Пример #1
0
 def initialize(self):
     """ Parse Configuration File """
     import ConfigParser
     # Assume filepath is good, since it is already checked
     info(self.v, 'Importing Configuration File: %s' % self.filepath)
     config = ConfigParser.SafeConfigParser(allow_no_value=True)
     try:
         config.readfp(open(self.filepath, 'r'))
     except Exception, e:
         exit(1, "Error reading config file (%s): %s" % (self.filepath, e))
Пример #2
0
            error("Could Not Save Config File (%s) - %s" % (self.filepath, e))

    def initialize(self):
        """ Parse Configuration File """
        import ConfigParser
        # Assume filepath is good, since it is already checked
        info(self.v, 'Importing Configuration File: %s' % self.filepath)
        config = ConfigParser.SafeConfigParser(allow_no_value=True)
        try:
            config.readfp(open(self.filepath, 'r'))
        except Exception, e:
            exit(1, "Error reading config file (%s): %s" % (self.filepath, e))

        # Error Check
        if not config.has_section('authentication'):
            exit(1, "Malformed Config File. Missing 'authentication' section")
        if not config.has_option('authentication', 'api_key'):
            exit(1, "Malformed Config File. Missing 'api_key' option")

        # Create a dictionary of config values
        config_dict = {}
        for section in config.sections():
            config_dict[section] = {}
            for name, value in config.items(section):
                config_dict[section][name] = value
                extra(self.v, "Section: %s\nName: %s\nValue: %s" % (section,
                                                                    name,
                                                                    value))

        # Transform dict into Config Object
        self.api_key = config_dict['authentication']['api_key']