From 6e64b84298ee0af829c2c656e9e3e0318dbb4d37 Mon Sep 17 00:00:00 2001 From: Kim Spasaro Date: Mon, 8 Aug 2016 15:57:40 -0500 Subject: [PATCH 1/2] adding module add command --- peru/main.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/peru/main.py b/peru/main.py index 05da9883..c5949395 100644 --- a/peru/main.py +++ b/peru/main.py @@ -221,6 +221,58 @@ def do_override(params): print('{}: {}'.format(module, params.runtime.get_override(module))) +@peru_command('module', '''\ +Usage: + peru module add [] [] [] [--rev=] [--reup=] + [--filename=] [--sha=] [--unpack=] [--yaml=] + peru module --help + +Add a module to your Peru yaml file. Reguires a module name, url, and module type. + +Options: + add add new module + --rev= set module rev value + --reup= set module reup value + --filename= set module filemame value + --sha= set module sha1 value + --unpack= set module unpack value + --yaml= file to use instead of peru.yaml + --help +''') +def do_add(params): + if params.args['add']: + if not params.args['']: + params.runtime.display.print('Please specify a module to add. See usage with peru module --help') + elif not params.args['']: + params.runtime.display.print('Please specify a module url. See usage with peru module --help') + elif not params.args['']: + params.runtime.display.print('Please specify a module type. See usage with peru module --help') + else: + peru_file = params.args['--yaml'] if params.args['--yaml'] else 'peru.yaml' + + if(peru_file[-5:] != '.yaml'): + print('Peru file should end in .yaml. See usage with peru add --help') + + with open(peru_file, "a") as yaml: + yaml.write('\n' + params.args[''] + ' module ' + params.args[''] + ':') + if(params.args['']): + yaml.write('\n url: ' + params.args['']) + if(params.args['--rev']): + yaml.write('\n rev: ' + params.args['--rev']) + if(params.args['--reup']): + yaml.write('\n reup: ' + params.args['--reup']) + if(params.args['--filename']): + yaml.write('\n filename: ' + params.args['--filename']) + if(params.args['--sha']): + yaml.write('\n sha: ' + params.args['--sha']) + if(params.args['--unpack']): + yaml.write('\n unpack: ' + params.args['--unpack']) + yaml.write('\n') + yaml.close() + + params.runtime.display.print('{} module added to {}'.format(params.args[''], peru_file)) + + def get_version(): version_file = os.path.join(compat.MODULE_ROOT, 'VERSION') with open(version_file) as f: From 9f3114158b655a1bc2fc4a74a7e74bc7fd8343df Mon Sep 17 00:00:00 2001 From: Kim Spasaro Date: Mon, 8 Aug 2016 16:28:19 -0500 Subject: [PATCH 2/2] fixing if/else block --- peru/main.py | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/peru/main.py b/peru/main.py index c5949395..21014a65 100644 --- a/peru/main.py +++ b/peru/main.py @@ -251,26 +251,27 @@ def do_add(params): peru_file = params.args['--yaml'] if params.args['--yaml'] else 'peru.yaml' if(peru_file[-5:] != '.yaml'): - print('Peru file should end in .yaml. See usage with peru add --help') - - with open(peru_file, "a") as yaml: - yaml.write('\n' + params.args[''] + ' module ' + params.args[''] + ':') - if(params.args['']): - yaml.write('\n url: ' + params.args['']) - if(params.args['--rev']): - yaml.write('\n rev: ' + params.args['--rev']) - if(params.args['--reup']): - yaml.write('\n reup: ' + params.args['--reup']) - if(params.args['--filename']): - yaml.write('\n filename: ' + params.args['--filename']) - if(params.args['--sha']): - yaml.write('\n sha: ' + params.args['--sha']) - if(params.args['--unpack']): - yaml.write('\n unpack: ' + params.args['--unpack']) - yaml.write('\n') - yaml.close() - - params.runtime.display.print('{} module added to {}'.format(params.args[''], peru_file)) + params.runtime.display.print('Peru file should end in .yaml. See usage with peru add --help') + + else: + with open(peru_file, "a") as yaml: + yaml.write('\n' + params.args[''] + ' module ' + params.args[''] + ':') + if(params.args['']): + yaml.write('\n url: ' + params.args['']) + if(params.args['--rev']): + yaml.write('\n rev: ' + params.args['--rev']) + if(params.args['--reup']): + yaml.write('\n reup: ' + params.args['--reup']) + if(params.args['--filename']): + yaml.write('\n filename: ' + params.args['--filename']) + if(params.args['--sha']): + yaml.write('\n sha: ' + params.args['--sha']) + if(params.args['--unpack']): + yaml.write('\n unpack: ' + params.args['--unpack']) + yaml.write('\n') + yaml.close() + + params.runtime.display.print('{} module added to {}'.format(params.args[''], peru_file)) def get_version():