# HG changeset patch # User Matti Hamalainen # Date 1469537914 -10800 # Node ID d68acec7cb99fd24e960fac6aa131edb078c9f96 # Parent 1d7d4dc5cf68bfcf224a51366d36ea4aefced0db Require configuration file. diff -r 1d7d4dc5cf68 -r d68acec7cb99 multimerge.py --- 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} ".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