diff options
author | 2015-05-16 22:40:12 -0400 | |
---|---|---|
committer | 2015-06-19 15:51:37 -0400 | |
commit | 8ac9e0dbf2a8d871887a3b577515662f57874c17 (patch) | |
tree | 4efdc76e4e218212b4ee8b9156d0f4b51446fb0d | |
parent | config.py: Adds optionality to --dir flag (diff) | |
download | webapp-config-8ac9e0dbf2a8d871887a3b577515662f57874c17.tar.gz webapp-config-8ac9e0dbf2a8d871887a3b577515662f57874c17.tar.bz2 webapp-config-8ac9e0dbf2a8d871887a3b577515662f57874c17.zip |
config.py: Allows for -lui to not have any arguments passed
Other command line flags such as -I, -C, or -U will always expect
2 command line args. If they are not properly supplied then that
is handled by argparse. This commit allows for the -lui flag that
can have 0 up to 2 optional flags passed to have that 0 flags passed.
-rw-r--r-- | WebappConfig/config.py | 84 |
1 files changed, 43 insertions, 41 deletions
diff --git a/WebappConfig/config.py b/WebappConfig/config.py index c9c0baf..37c2982 100644 --- a/WebappConfig/config.py +++ b/WebappConfig/config.py @@ -976,47 +976,49 @@ class Config: 'show_postinst', 'show_postupgrade', 'upgrade']: # get cat / pn args = options[self.work] - m = args[0].split('/') - - if self.work == 'list_installs' and len(args) > 2: - msg = os.path.basename(sys.argv[0]) + ': error: argument -li/'\ - '--list-installs: expected up to 2 arguments' - - self.parser.print_usage() - print(msg) - sys.exit() - - if len(m) == 1: - if '*' not in m: - self.config.set('USER', 'pn', m[0]) - elif len(m) == 2: - self.config.set('USER', 'cat', m[0]) - if '*' not in m: - self.config.set('USER', 'pn', m[1]) - else: - OUT.die('Invalid package name') - - if len(args) > 1: - argsvr = args[1].split('.') - if len(argsvr) == 1: - OUT.die('Invalid package version: %(pvr)s' % {'pvr': args[1]}) - - pvr = '' - for i in range(0, len(argsvr)): - if not i == len(argsvr) - 1: - pvr += argsvr[i] + '.' - else: - pvr += argsvr[i] - self.config.set('USER', 'pvr', pvr) - - if not options['dir'] and self.work != 'list_installs': - pn = self.config.get('USER', 'pn') - msg = 'Install dir flag not supplied, defaulting to '\ - '"%(pn)s".' % {'pn': pn} - - OUT.warn(msg) - self.config.set('USER', 'g_installdir', pn) - self.flag_dir = True + + if len(args): + m = args[0].split('/') + + if self.work == 'list_installs' and len(args) > 2: + msg = os.path.basename(sys.argv[0]) + ': error: argument '\ + '-li/--list-installs: expected up to 2 arguments' + + self.parser.print_usage() + print(msg) + sys.exit() + + if len(m) == 1: + if '*' not in m: + self.config.set('USER', 'pn', m[0]) + elif len(m) == 2: + self.config.set('USER', 'cat', m[0]) + if '*' not in m: + self.config.set('USER', 'pn', m[1]) + else: + OUT.die('Invalid package name') + + if len(args) > 1: + argsvr = args[1].split('.') + if len(argsvr) == 1: + OUT.die('Invalid package version: %(pvr)s' % {'pvr': args[1]}) + + pvr = '' + for i in range(0, len(argsvr)): + if not i == len(argsvr) - 1: + pvr += argsvr[i] + '.' + else: + pvr += argsvr[i] + self.config.set('USER', 'pvr', pvr) + + if not options['dir'] and self.work != 'list_installs': + pn = self.config.get('USER', 'pn') + msg = 'Install dir flag not supplied, defaulting to '\ + '"%(pn)s".' % {'pn': pn} + + OUT.warn(msg) + self.config.set('USER', 'g_installdir', pn) + self.flag_dir = True # -------------------------------------------------------------------- |