Commit d02436db authored by Marco Mariani's avatar Marco Mariani

naming consistency (args/options/config..)

parent 5d6e6b96
......@@ -11,10 +11,10 @@ class BangCommand(ConfigCommand):
log = logging.getLogger(__name__)
def get_parser(self, prog_name):
parser = super(BangCommand, self).get_parser(prog_name)
parser.add_argument('-m', '--message',
help='Message for bang')
return parser
ap = super(BangCommand, self).get_parser(prog_name)
ap.add_argument('-m', '--message',
help='Message for bang')
return ap
def take_action(self, args):
config = self.fetch_config(args)
......
......@@ -11,11 +11,11 @@ class CacheLookupCommand(ConfigCommand):
log = logging.getLogger(__name__)
def get_parser(self, prog_name):
parser = super(CacheLookupCommand, self).get_parser(prog_name)
ap = super(CacheLookupCommand, self).get_parser(prog_name)
# XXX this argument could use a better name
parser.add_argument('software_url',
help='Your software url or MD5 hash')
return parser
ap.add_argument('software_url',
help='Your software url or MD5 hash')
return ap
def take_action(self, args):
config = self.fetch_config(args)
......
......@@ -21,9 +21,9 @@ class ConfigCommand(Command):
default_config_path = '/etc/opt/slapos/slapos.cfg'
def get_parser(self, prog_name):
parser = super(ConfigCommand, self).get_parser(prog_name)
parser.add_argument('--cfg', help='SlapOS configuration file')
return parser
ap = super(ConfigCommand, self).get_parser(prog_name)
ap.add_argument('--cfg', help='SlapOS configuration file')
return ap
def _get_config(self, cfg_path, required=False):
"""
......
......@@ -74,6 +74,7 @@ class RegisterCommand(Command):
return_code = do_register(config)
except SystemExit, err:
# Catch exception raised by optparse
# XXX returning exception with sys.exit?
return_code = err
sys.exit(return_code)
......@@ -15,11 +15,11 @@ class SupervisorctlCommand(ConfigCommand):
log = logging.getLogger(__name__)
def get_parser(self, prog_name):
parser = super(SupervisorctlCommand, self).get_parser(prog_name)
parser.add_argument('supervisor_args',
nargs=argparse.REMAINDER,
help='parameters passed to supervisorctl')
return parser
ap = super(SupervisorctlCommand, self).get_parser(prog_name)
ap.add_argument('supervisor_args',
nargs=argparse.REMAINDER,
help='parameters passed to supervisorctl')
return ap
def take_action(self, args):
config = self.fetch_config(args)
......
......@@ -34,17 +34,14 @@ from slapos.bang import do_bang
def main(*args):
parser = argparse.ArgumentParser()
parser.add_argument('-m', '--message', default='', help='Message for bang.')
parser.add_argument('configuration_file', nargs=1, type=argparse.FileType(),
help='SlapOS configuration file.')
if len(args) == 0:
argument = parser.parse_args()
ap = argparse.ArgumentParser()
ap.add_argument('-m', '--message', default='', help='Message for bang.')
ap.add_argument('configuration_file', type=argparse.FileType(),
help='SlapOS configuration file.')
if args:
args = ap.parse_args(list(args))
else:
argument = parser.parse_args(list(args))
configuration_file = argument.configuration_file[0]
message = argument.message
# Loads config (if config specified)
args = ap.parse_args()
config = ConfigParser.SafeConfigParser()
config.readfp(configuration_file)
do_bang(config, message)
config.readfp(args.configuration_file)
do_bang(config, args.message)
......@@ -7,10 +7,10 @@ from slapos.cache import do_lookup
def cache_lookup():
parser = argparse.ArgumentParser()
parser.add_argument("configuration_file", help="SlapOS configuration file")
parser.add_argument("software_url", help="Your software url or MD5 hash")
args = parser.parse_args()
ap = argparse.ArgumentParser()
ap.add_argument("configuration_file", help="SlapOS configuration file")
ap.add_argument("software_url", help="Your software url or MD5 hash")
args = ap.parse_args()
config = ConfigParser.SafeConfigParser()
config.read(args.configuration_file)
......
......@@ -40,12 +40,12 @@ examples :
ap.add_argument('configuration_file',
help='path to slapos.cfg')
options = ap.parse_args()
args = ap.parse_args()
if not os.path.isfile(options.configuration_file):
ap.error("%s: Not found or not a regular file." % options.configuration_file)
if not os.path.isfile(args.configuration_file):
ap.error("%s: Not found or not a regular file." % args.configuration_file)
config = ClientConfig(options, get_config_parser(options.configuration_file))
config = ClientConfig(args, get_config_parser(args.configuration_file))
local = init(config)
do_console(local)
......@@ -72,9 +72,9 @@ def checkSlaposCfg():
for element in sys.argv:
if '.cfg' in element:
if os.path.exists(element):
configuration = ConfigParser.SafeConfigParser()
configuration.read(element)
if configuration.has_section('slapos'):
config = ConfigParser.SafeConfigParser()
config.read(element)
if config.has_section('slapos'):
return True
return False
......@@ -207,23 +207,23 @@ Node subcommands usage:
# Parse arguments
# XXX remove the "positional arguments" from help message
parser = argparse.ArgumentParser(usage=usage)
parser.add_argument('command')
parser.add_argument('argument_list', nargs=argparse.REMAINDER)
ap = argparse.ArgumentParser(usage=usage)
ap.add_argument('command')
ap.add_argument('argument_list', nargs=argparse.REMAINDER)
namespace = parser.parse_args()
args = ap.parse_args()
# Set sys.argv for the sub-entry point that we will call
command_line = [namespace.command]
command_line.extend(namespace.argument_list)
command_line = [args.command]
command_line.extend(args.argument_list)
sys.argv = command_line
try:
if not dispatch(namespace.command, is_node):
parser.print_help()
if not dispatch(args.command, is_node):
ap.print_help()
sys.exit(1)
except EntryPointNotImplementedError, exception:
print ('The command %s does not exist or is not yet implemented. Please '
'have a look at http://community.slapos.org to read documentation or '
'forum. Please also make sure that SlapOS Node is up to '
'date.' % exception)
'have a look at http://community.slapos.org to read documentation or '
'forum. Please also make sure that SlapOS Node is up to '
'date.' % exception)
sys.exit(1)
......@@ -38,8 +38,6 @@ from slapos.format import FormatConfig, UsageError, tracing_monkeypatch, do_form
def main(*args):
"Run default configuration."
# Parse arguments
ap = argparse.ArgumentParser(usage='usage: %s [options] CONFIGURATION_FILE' % sys.argv[0])
ap.add_argument('-x', '--computer_xml',
......@@ -96,14 +94,14 @@ def main(*args):
help='path to slapos.cfg')
if args:
options = ap.parse_args(list(args))
args = ap.parse_args(list(args))
else:
options = ap.parse_args()
args = ap.parse_args()
logger = logging.getLogger("slapformat")
logger.addHandler(logging.StreamHandler())
if options.verbose:
if args.verbose:
logger.setLevel(logging.DEBUG)
logger.debug("Verbose mode enabled.")
else:
......@@ -112,13 +110,13 @@ def main(*args):
config = FormatConfig(logger=logger)
configuration_parser = ConfigParser.SafeConfigParser()
if configuration_parser.read(options.configuration_file) != [options.configuration_file]:
raise UsageError('Cannot find or parse configuration file: %s' % options.configuration_file)
if configuration_parser.read(args.configuration_file) != [args.configuration_file]:
raise UsageError('Cannot find or parse configuration file: %s' % args.configuration_file)
try:
config.setConfig(options, configuration_parser)
except UsageError as err:
sys.stderr.write(err.message + '\n')
config.setConfig(args, configuration_parser)
except UsageError as exc:
sys.stderr.write(exc.message + '\n')
sys.stderr.write("For help use --help\n")
sys.exit(1)
......
......@@ -35,8 +35,6 @@ from slapos.register.register import do_register, RegisterConfig
def main():
"Run default configuration."
ap = argparse.ArgumentParser(usage='usage: slapos node %s NODE_NAME [options]' % sys.argv[0])
ap.add_argument('node_name',
......@@ -86,9 +84,9 @@ def main():
default=False,
action='store_true')
options = ap.parse_args()
args = ap.parse_args()
if options.password and not options.login:
if args.password and not args.login:
ap.error('Please enter your login with your password')
logger = logging.getLogger('Register')
......@@ -100,10 +98,11 @@ def main():
try:
config = RegisterConfig(logger=logger)
config.setConfig(options)
config.setConfig(args)
return_code = do_register(config)
except SystemExit, err:
except SystemExit as exc:
# Catch exception raised by optparse
return_code = err
# XXX returning exception with sys.exit?
return_code = exc
sys.exit(return_code)
......@@ -7,17 +7,14 @@ from slapos.cli_legacy.util import get_config_parser
def remove():
"""
Run when invoking slapos remove. Mostly argument parsing.
"""
parser = argparse.ArgumentParser()
parser.add_argument('configuration_file',
help='SlapOS configuration file')
parser.add_argument('software_url',
help='Your software url')
parser.add_argument('node',
help='Target node')
args = parser.parse_args()
ap = argparse.ArgumentParser()
ap.add_argument('configuration_file',
help='SlapOS configuration file')
ap.add_argument('software_url',
help='Your software url')
ap.add_argument('node',
help='Target node')
args = ap.parse_args()
config = ClientConfig(args, get_config_parser(args.configuration_file))
local = init(config)
......
......@@ -10,14 +10,14 @@ def supply():
"""
Run when invoking slapos supply. Mostly argument parsing.
"""
parser = argparse.ArgumentParser()
parser.add_argument('configuration_file',
help='SlapOS configuration file')
parser.add_argument('software_url',
help='Your software url')
parser.add_argument('node',
help='Target node')
args = parser.parse_args()
ap = argparse.ArgumentParser()
ap.add_argument('configuration_file',
help='SlapOS configuration file')
ap.add_argument('software_url',
help='Your software url')
ap.add_argument('node',
help='Target node')
args = ap.parse_args()
config = ClientConfig(args, get_config_parser(args.configuration_file))
local = init(config)
......
......@@ -11,5 +11,3 @@ def get_config_parser(path):
raise OSError('Specified configuration file %s does not exist. Exiting.' % path)
configuration_parser.read(path)
return configuration_parser
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment