Skip to content
This repository has been archived by the owner on Feb 13, 2020. It is now read-only.

Commit

Permalink
Merge pull request #183 from gamechanger/ae-scripts
Browse files Browse the repository at this point in the history
Changing scripts to no longer have data in keys. Also change command form script to scripts
  • Loading branch information
Philip Alexander Etling committed Jun 9, 2015
2 parents d570aff + 8942c59 commit f9f4e6e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
4 changes: 2 additions & 2 deletions dusty/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
logs Tail logs for a Dusty-managed service
repos Manage Git repos used for running Dusty applications
restart Restart Dusty-managed containers
script Execute predefined scripts inside running containers
scripts Execute predefined scripts inside running containers
setup Configure Dusty after installation
shell Open a shell inside a running container
stop Stop Dusty-managed containers
Expand Down Expand Up @@ -45,7 +45,7 @@
'logs': logs,
'repos': repos,
'restart': restart,
'script': script,
'scripts': script,
'setup': setup,
'shell': shell,
'stop': stop,
Expand Down
2 changes: 1 addition & 1 deletion dusty/cli/script.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Execute scripts defined in an app's spec inside a running app container.
Usage:
script <app_name> [<script_name>] [<args>...]
scripts <app_name> [<script_name>] [<args>...]
Options:
<args> Arguments to pass to the script
Expand Down
12 changes: 8 additions & 4 deletions dusty/commands/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@ def script_info_for_app(app_name):
return

table = PrettyTable(['Script', 'Description'])
for script_name, script_spec in app_specs['scripts'].iteritems():
table.add_row([script_name,
for script_spec in app_specs['scripts']:
table.add_row([script_spec['name'],
'\n'.join(textwrap.wrap(script_spec.get('description', ''), 80))])
log_to_client(table.get_string(sortby='Script'))

def execute_script(app_name, script_name, script_arguments=[]):
app_specs = get_specs()['apps'].get(app_name)
if not app_specs:
raise KeyError('No app found named {} in specs'.format(app_name))
if 'scripts' not in app_specs or script_name not in app_specs['scripts']:
script_spec = None
for script_dict in app_specs.get('scripts', []):
if script_dict['name'] == script_name:
script_spec = script_dict
if script_spec is None:
raise KeyError('No script found named {} in specs for app {}'.format(script_name, app_name))
script_spec = app_specs['scripts'][script_name]

if script_arguments == []:
script_string = script_spec['command']
else:
Expand Down
7 changes: 2 additions & 5 deletions dusty/schemas/app_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@
})

script_schema = Schema({
'name': {'type': basestring, 'required': True},
'description': {'type': basestring},
'command': {'type': basestring, 'required': True}
})

def get_scripts_schema(document):
scripts_keys = document.keys()
schema_dict = {key: {'type': script_schema} for key in scripts_keys}
return Schema(schema_dict)

app_schema = Schema({
'repo': {'type': basestring, 'required': True},
Expand All @@ -42,6 +39,6 @@ def get_scripts_schema(document):
'build': {'type': basestring},
'mount': {'type': basestring},
'commands': {'type': commands_schema},
'scripts': {'type': get_scripts_schema},
'scripts': {'type': Array(script_schema)},
'compose': {'type': dict},
})
11 changes: 6 additions & 5 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ def basic_specs_fixture():
_write('bundle', 'bundle-b', {'description': 'Bundle B', 'apps': ['app-b']})
_write('app', 'app-a', {'repo': 'github.com/app/a',
'image': 'app/a',
'scripts': {'example': {'description': 'A script description',
'command': 'ls /',
'accepts_arguments': True}}})
'scripts': [{'description': 'A script description',
'command': 'ls /',
'name': 'example'}]})
_write('app', 'app-b', {'repo': 'github.com/app/b',
'image': 'app/b',
'scripts': {'example': {'description': 'A script description',
'command': 'ls /'}}})
'scripts': [{'description': 'A script description',
'command': 'ls /',
'name': 'example'}]})
_write('app', 'app-c', {'repo': '/gc/repos/c',
'image': 'app/c'})
_write('lib', 'lib-a', {'repo': 'github.com/lib/a', 'image': 'lib/a'})
Expand Down

0 comments on commit f9f4e6e

Please sign in to comment.