Mercurial > hg > gcmultimerge
changeset 89:d68acec7cb99
Require configuration file.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 26 Jul 2016 15:58:34 +0300 |
parents | 1d7d4dc5cf68 |
children | 286ccecf9257 |
files | multimerge.py |
diffstat | 1 files changed, 21 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/multimerge.py Tue Jul 26 15:56:29 2016 +0300 +++ b/multimerge.py Tue Jul 26 15:58:34 2016 +0300 @@ -376,27 +376,31 @@ cfg.mdef("credential_file", True, cfg.is_filename, None, "client_credentials.json") +## Check arguments +if len(sys.argv) <= 1: + gcm_fatal(u"No configuration file specified.\nUsage: {0} <configfile>".format(sys.argv[0])) + + ## Read, parse and validate configuration file -if len(sys.argv) > 1: - gcm_debug(3, u"Reading configuration from '{0}'.".format(sys.argv[1])) - try: - cfgparser = ConfigParser.RawConfigParser() - cfgparser.readfp(codecs.open(sys.argv[1], "r", "UTF-8")) - except Exception as e: - gcm_fatal(u"Failed to read configuration file '{0}': {1}".format(sys.argv[1], str(e))) +gcm_debug(3, u"Reading configuration from '{0}'.".format(sys.argv[1])) +try: + cfgparser = ConfigParser.RawConfigParser() + cfgparser.readfp(codecs.open(sys.argv[1], "r", "UTF-8")) +except Exception as e: + gcm_fatal(u"Failed to read configuration file '{0}': {1}".format(sys.argv[1], str(e))) - # Check that the required section exists - section = "gcm" - if not cfgparser.has_section(section): - gcm_fatal(u"Invalid configuration, missing '{0}' section.".format(section)) +# Check that the required section exists +section = "gcm" +if not cfgparser.has_section(section): + gcm_fatal(u"Invalid configuration, missing '{0}' section.".format(section)) - # Debug setting is a special case, we need to get it - # set before everything else, so do it here .. - if cfgparser.has_option(section, "debug"): - cfg.mset("debug", cfgparser.get(section, "debug")) +# Debug setting is a special case, we need to get it +# set before everything else, so do it here .. +if cfgparser.has_option(section, "debug"): + cfg.mset("debug", cfgparser.get(section, "debug")) - # Parse the settings and validate - cfg.mread(cfgparser, section) +# Parse the settings and validate +cfg.mread(cfgparser, section) ## Validate settings