Commit 5d47a675 authored by Marco Mariani's avatar Marco Mariani

extracted merged_options()

parent d02436db
...@@ -125,7 +125,7 @@ def check_missing_files(options): ...@@ -125,7 +125,7 @@ def check_missing_files(options):
raise RuntimeError('Directory %r does not exist' % d) raise RuntimeError('Directory %r does not exist' % d)
def parse_arguments_merge_config(*argument_tuple): def parse_arguments(*argument_tuple):
"""Parse arguments and return options dictionary merged with the config file.""" """Parse arguments and return options dictionary merged with the config file."""
ap = argparse.ArgumentParser() ap = argparse.ArgumentParser()
...@@ -197,9 +197,11 @@ def parse_arguments_merge_config(*argument_tuple): ...@@ -197,9 +197,11 @@ def parse_arguments_merge_config(*argument_tuple):
else: else:
args = ap.parse_args(list(argument_tuple)) args = ap.parse_args(list(argument_tuple))
return args
def merged_options(args, config):
options = {} options = {}
config = ConfigParser.SafeConfigParser()
config.readfp(args.configuration_file)
options = dict(config.items('slapos')) options = dict(config.items('slapos'))
if config.has_section('networkcache'): if config.has_section('networkcache'):
...@@ -208,6 +210,34 @@ def parse_arguments_merge_config(*argument_tuple): ...@@ -208,6 +210,34 @@ def parse_arguments_merge_config(*argument_tuple):
if value is not None: if value is not None:
options[key] = value options[key] = value
if options.get('all'):
options['develop'] = True
if options.get('maximum_periodicity') is not None:
options['force_periodicity'] = True
# Supervisord configuration location
if not options.get('supervisord_configuration_path'):
options['supervisord_configuration_path'] = \
os.path.join(options['instance_root'], 'etc', 'supervisord.conf')
# Supervisord socket
if not options.get('supervisord_socket'):
options['supervisord_socket'] = \
os.path.join(options['instance_root'], 'supervisord.socket')
# Parse cache / binary cache options
# Backward compatibility about "binary-cache-url-blacklist" deprecated option
if options.get("binary-cache-url-blacklist") and not \
options.get("download-from-binary-cache-url-blacklist"):
options["download-from-binary-cache-url-blacklist"] = \
options["binary-cache-url-blacklist"]
options["download-from-binary-cache-url-blacklist"] = [
url.strip() for url in options.get(
"download-from-binary-cache-url-blacklist", "").split('\n') if url]
options["upload-to-binary-cache-url-blacklist"] = [
url.strip() for url in options.get(
"upload-to-binary-cache-url-blacklist", "").split('\n') if url]
return options return options
...@@ -247,46 +277,22 @@ def random_delay(options, logger): ...@@ -247,46 +277,22 @@ def random_delay(options, logger):
time.sleep(duration) time.sleep(duration)
def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple): def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
"""Returns a new instance of slapgrid.Slapgrid created with argument+config parameters. """Returns a new instance of slapgrid.Slapgrid created with argument+config parameters.
Also returns the pidfile path, and configures logger. Also returns the pidfile path, and configures logger.
""" """
options = parse_arguments_merge_config(*argument_tuple) args = parse_arguments(*argument_tuple)
config = ConfigParser.SafeConfigParser()
config.readfp(args.configuration_file)
options = merged_options(args, config)
logger = setup_logger(options) logger = setup_logger(options)
check_missing_parameters(options) check_missing_parameters(options)
check_missing_files(options) check_missing_files(options)
if options.get('all'):
options['develop'] = True
if options.get('maximum_periodicity') is not None:
options['force_periodicity'] = True
# Supervisord configuration location
if not options.get('supervisord_configuration_path'):
options['supervisord_configuration_path'] = \
os.path.join(options['instance_root'], 'etc', 'supervisord.conf')
# Supervisord socket
if not options.get('supervisord_socket'):
options['supervisord_socket'] = \
os.path.join(options['instance_root'], 'supervisord.socket')
# Parse cache / binary cache options
# Backward compatibility about "binary-cache-url-blacklist" deprecated option
if options.get("binary-cache-url-blacklist") and not \
options.get("download-from-binary-cache-url-blacklist"):
options["download-from-binary-cache-url-blacklist"] = \
options["binary-cache-url-blacklist"]
options["download-from-binary-cache-url-blacklist"] = [
url.strip() for url in options.get(
"download-from-binary-cache-url-blacklist", "").split('\n') if url]
options["upload-to-binary-cache-url-blacklist"] = [
url.strip() for url in options.get(
"upload-to-binary-cache-url-blacklist", "").split('\n') if url]
random_delay(options, logger=logger) random_delay(options, logger=logger)
slapgrid_object = create_slapgrid_object(options, logger=logger) slapgrid_object = create_slapgrid_object(options, logger=logger)
...@@ -294,7 +300,6 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple): ...@@ -294,7 +300,6 @@ def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
return slapgrid_object, options.get('pidfile') return slapgrid_object, options.get('pidfile')
def create_slapgrid_object(options, logger): def create_slapgrid_object(options, logger):
signature_certificate_list = None signature_certificate_list = None
if 'signature-certificate-list' in options: if 'signature-certificate-list' in options:
......
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