Beispiel #1
0
    def __init__(self, filename, mixer):
        from ConfigParser import RawConfigParser
        config = RawConfigParser()
        config.read(filename)

        self.play_intro = config.getboolean('Main', 'play_intro')
        if mixer:
            self.mixer = config.getboolean('Main', 'mixer')
        else:
            self.mixer = False
        self.music = GetDataPath(config.get('Main', 'music'))
        self.music = os.path.expanduser(self.music)

        width = config.getint('Defaults', 'width')
        height = config.getint('Defaults', 'height')

        self.subsettings = {}
        sections = config.sections()
        for defaults in ('Main', 'Defaults'):
            sections.remove(defaults)
        for sec in sections:
            op_dict = {}
            for op in config.options(sec):
                op_dict[op] = config.get(sec, op)
                if op in ('width', 'height'):
                    op_dict[op] = eval(op_dict[op])
            for op in ('width', 'height'):
                if op not in op_dict or op_dict[op] == 0:
                    op_dict[op] = locals()[op]
            self.subsettings[sec] = op_dict
Beispiel #2
0
 def __init__(self, *args):
     LoginAction.__init__(self, *args)
     self.set_values(DEFAULT_VALS)
     self.LOG = self.db.get_logger().getChild('ldap_auth')
     ldap_conf_file = os.path.join(self.db.config.ext['HOME'],
                                   'ldap_config.ini')
     if os.path.exists(ldap_conf_file):
         self.LOG.debug("Reading configuration file 'ldap_config.ini'")
         cfg = RawConfigParser()
         cfg.read(ldap_conf_file)
         if cfg.has_section('ldap'):
             for (key, value) in cfg.items('ldap'):
                 self.LOG.debug("Setting option %s to %s" % (key, value))
                 if key in ['use_local_auth', 'autocreate', 'bind_once']:
                     setattr(self, key, cfg.getboolean('ldap', key))
                 elif key in ['referrals', 'start_tls', 'timeout']:
                     setattr(self, key, cfg.getint('ldap', key))
                 elif key == 'debug' and cfg.getboolean('ldap', key):
                     self.LOG.setLevel(logging.DEBUG)
                 else:
                     setattr(self, key, value)
         else:
             self.LOG.info(
                 "Skipping parsing of file ldap_config.ini as it has no 'ldap' section."
             )
Beispiel #3
0
    def _get_autoreload_programs(self, cfg_file):
        """Get the set of programs to auto-reload when code changes.

        Such programs will have autoreload=true in their config section.
        This can be affected by config file sections or command-line
        arguments, so we need to read it out of the merged config.
        """
        cfg = RawConfigParser()
        cfg.readfp(cfg_file)
        reload_progs = {}
        graceful_reload_progs = {}
        for section in cfg.sections():
            if section.startswith("program:"):
                try:
                    patterns = (
                        cfg.get(section, "autoreload_patterns").split(",")
                        if cfg.has_option(section, "autoreload_patterns")
                        else AUTORELOAD_PATTERNS
                    )
                    if cfg.getboolean(section, "autoreload"):
                        if cfg.getboolean(section, "autoreload_graceful"):
                            graceful_reload_progs[section.split(":", 1)[1]] = patterns
                        else:
                            reload_progs[section.split(":", 1)[1]] = patterns
                except NoOptionError:
                    pass
        return (reload_progs, graceful_reload_progs)
Beispiel #4
0
 def getboolean(self, section, option):
     try:
         return RawConfigParser.getboolean(self, section, option)
     except ValueError:
         rv = RawConfigParser.getboolean(self, 'DEFAULT', option)
         syslog(LOG_WARNING,
                "Invalid boolean value for %s in config file; assuming %s" % (option, rv))
         return rv
Beispiel #5
0
class Config:
    
    def __init__(self, logger):
        self.logger = logger
        try:
            self.conf = RawConfigParser()
            self.file = httpConstants().getConf()
            self.conf.read(self.file)
            self.logger.output('kHTTPd Mini config file loaded.')
        except:
            self.logger.output('Can\'t open kHTTPd Mini config file!')
        
    def getDocRoot(self):
        try:
            return self.conf.get('main', 'root')
        except:
            self.logger.output('Can\'t load document root setting of server from '+ self.file +', defaulting to www.')
            return 'www'
    
    def getPort(self):
        try:
            return self.conf.getint('main', 'port')
        except:
            self.logger.output('Can\'t load port to bind server to from '+ self.file +', defaulting to port 80.')
            return 80
    
    def getDebug(self):
        try:
            return self.conf.getboolean('main', 'debugmode')
        except:
            self.logger.output('Can\'t load debug mode setting from '+ self.file +', defaulting to off.')
            return False
    
    def getIndexFile(self):
        try:
            return self.conf.get('main', 'indexfile')
        except:
            self.logger.output('Can\'t load index file setting from '+ self.file +', defaulting to index.html.')
            return 'index.html'
        
    def getPhpEnabled(self):
        try:
            return self.conf.getboolean('php', 'phpenabled')
        except:
            self.logger.output('Can\'t load PHP mode setting from '+ self.file +', defaulting to off.')
            return False
        
    def getPhpExec(self):
        try:
            return self.conf.get('php', 'name')
        except:
            self.logger.output('Can\'t load PHP executable name from '+ self.file +', defaulting to php-cgi.')
            return 'php-cgi'
Beispiel #6
0
    def _read_configuration_file(self, path):
        """Try to read and parse `path` as a configuration file.

        If the configurations were illegal (checked with
        `self._validate_options`), raises `IllegalConfiguration`.

        Returns (options, should_inherit).

        """
        parser = RawConfigParser()
        options = None
        should_inherit = True

        if parser.read(path) and self._get_section_name(parser):
            option_list = dict([(o.dest, o.type or o.action)
                                for o in self._parser.option_list])

            # First, read the default values
            new_options, _ = self._parse_args([])

            # Second, parse the configuration
            section_name = self._get_section_name(parser)
            for opt in parser.options(section_name):
                if opt == 'inherit':
                    should_inherit = parser.getboolean(section_name, opt)
                    continue

                if opt.replace('_', '-') not in self.CONFIG_FILE_OPTIONS:
                    log.warning("Unknown option '{}' ignored".format(opt))
                    continue

                normalized_opt = opt.replace('-', '_')
                opt_type = option_list[normalized_opt]
                if opt_type in ('int', 'count'):
                    value = parser.getint(section_name, opt)
                elif opt_type == 'string':
                    value = parser.get(section_name, opt)
                else:
                    assert opt_type in ('store_true', 'store_false')
                    value = parser.getboolean(section_name, opt)
                setattr(new_options, normalized_opt, value)

            # Third, fix the set-options
            options = self._fix_set_options(new_options)

        if options is not None:
            if not self._validate_options(options):
                raise IllegalConfiguration('in file: {}'.format(path))

        return options, should_inherit
Beispiel #7
0
    def _read_configuration_file(self, path):
        """Try to read and parse `path` as a configuration file.

        If the configurations were illegal (checked with
        `self._validate_options`), raises `IllegalConfiguration`.

        Returns (options, should_inherit).

        """
        parser = RawConfigParser()
        options = None
        should_inherit = True

        if parser.read(path) and self._get_section_name(parser):
            option_list = dict([(o.dest, o.type or o.action)
                                for o in self._parser.option_list])

            # First, read the default values
            new_options, _ = self._parse_args([])

            # Second, parse the configuration
            section_name = self._get_section_name(parser)
            for opt in parser.options(section_name):
                if opt == 'inherit':
                    should_inherit = parser.getboolean(section_name, opt)
                    continue

                if opt.replace('_', '-') not in self.CONFIG_FILE_OPTIONS:
                    log.warning("Unknown option '{}' ignored".format(opt))
                    continue

                normalized_opt = opt.replace('-', '_')
                opt_type = option_list[normalized_opt]
                if opt_type in ('int', 'count'):
                    value = parser.getint(section_name, opt)
                elif opt_type == 'string':
                    value = parser.get(section_name, opt)
                else:
                    assert opt_type in ('store_true', 'store_false')
                    value = parser.getboolean(section_name, opt)
                setattr(new_options, normalized_opt, value)

            # Third, fix the set-options
            options = self._fix_set_options(new_options)

        if options is not None:
            if not self._validate_options(options):
                raise IllegalConfiguration('in file: {}'.format(path))

        return options, should_inherit
Beispiel #8
0
    def _readConfig(cls, filename):
        '''
        Read the configuration file and return a pythonic configuration dict.
        '''
        confParser = RawConfigParser(
            defaults={
                # these keys can be commented out in the config file,
                # warning: the values are converted to strings
                'user': None,
                'pathRegexFilter': '',
                'filenameRegexFilter': '',
                'subPath': '',
                'includes': '',
                'macros': '',
                'languages': '',
                'metrics': '',
                'settings': '',
                'aggregateIssueLinks': '',
                'shortBlockLines': 4
            })
        parsedFiles = confParser.read(filename)
        if not parsedFiles:
            msg = "Configuration file {} could not be read.".format(filename)
            raise Exception(msg)
        conf = {
            'sina': {},
            'neteasy': {},
            'hanjie': {},
            'matching': {},
        }
        # TODO: The 'configfie' entry is unused
        conf['consoleLog'] = confParser.getboolean('global', 'consoleLog')
        conf['debugMode'] = confParser.getboolean('global', 'debugMode')
        conf['encoding'] = confParser.get('global', 'encoding')
        conf['http_proxy'] = confParser.get('global', 'http_proxy')
        conf['configfile'] = os.path.abspath(filename)
        conf['basePath'] = os.path.abspath(
            convertOsPath(confParser.get('global', 'basePath')))
        if confParser.has_section('sina'):
            conf['sina']['url'] = confParser.get('sina', 'url')
            conf['sina']['user'] = confParser.get('sina', 'user')
            conf['sina']['password'] = confParser.get('sina', 'password')
        if confParser.has_section('netease'):
            conf['netease']['url'] = confParser.get('netease', 'url')
            conf['netease']['user'] = confParser.get('netease', 'user')
            conf['netease']['password'] = confParser.get('netease', 'password')

        _convertDictUnicode(conf)
        return conf
Beispiel #9
0
	def __init__(self):
		for file in ('', ):
			if os.path.exists(file):
				break
		else:
			file = None
		if file is None:
			reactor.callWhenRunning(
				log.msg, 'No config loaded, use default settings'
			)
		else:
			with open(file, 'rb') as fp:
				parser = ConfigParser(); parser.readfp(fp)
				for section in parser.sections():
					for key, value in parser.items(section):
						key, value = key.lower(), value.decode('utf8')
						if section == 'general':
							if key in (
									'timeout','connectionslimit',):
								value and setattr(self, key, parser.getint(section, key))
							elif key in (
									'socksauth',):
								setattr(self, key, parser.getboolean(section, key))
							elif key in (
									'usersfile','listeninterface',):
								value and setattr(self, key, parser.get(section, key))
							else:
								raise ParsingError, 'unknown key "%s" in section "%s"' % (key, section)
						else:
							raise TypeError, 'unknown section "%s"' % (section)
Beispiel #10
0
    def __init__(self, configuration_file, rewrite=False):
        parser = RawConfigParser()
        parser.read(configuration_file)
        dist_filename = parser.get('files', 'distances-filename')
        entropy_filename = parser.get('files', 'entropy-filename')
        self.mRMR_filename = parser.get('files', 'mRMR-filename')
        self.num_bins = parser.getint('parameters', 'num-bins')
        self.bin_width = parser.getfloat('parameters', 'bin-width')
        self.aa = parser.getboolean('parameters', 'aa')
        self.chains = parser.getint('parameters', 'chains')
        self.dist_range = [float(i) for i in parser.get('parameters', 'distance-range').split()]
        self.weights = [float(i) for i in parser.get('parameters', 'weights').split()]
        self.resi_select = parser.get('parameters', 'excluded-residues').split()
        if not self.resi_select:
            self.resi_select = None

        print "Loading distance file %s" % dist_filename
        init = time.time()
        self.dists = cPickle.load(open(dist_filename))
        print "Loaded %s in %f seconds" % (dist_filename, time.time() - init)
        # If no entropy has been provided, entropy must be calculated for permitted residues.
        print colors.HEADER + "\tENTROPY CALCULATION" + colors.ENDC
        if os.path.exists(entropy_filename) and not rewrite:
            warn_file_exists(entropy_filename)
            self.entropy = cPickle.load(open(entropy_filename))
        else:
            print "No entropy file was found or you have chosen to rewrite. Calculating entropies..."
            self.entropy = h_fast(self.dists)
            print "Dumping entopies to", entropy_filename
            cPickle.dump(self.entropy, open(entropy_filename, 'w'))
Beispiel #11
0
 def __read_config(self):
     """
     Obtiene la configuración de la persona de su archivo .person y devuelve True si es válida
     """
     pparser = RawConfigParser()
     with codecs.open("config/" + self.person + '.person', 'r', encoding='utf-8') as cf:
         pparser.readfp(cf)
     if pparser.has_section("general"):
         if pparser.has_option('general', 'name'):
             self.name = pparser.get('general', 'name')
             if self.name == '':
                 return False
         else:
             return False
         if pparser.has_option('general', 'notify'):
             self.notify = pparser.getboolean('general', 'notify')
         if pparser.has_option('general', 'alarm_threshold'):
             self.alarm_threshold = pparser.getint('general', 'alarm_threshold')
         if pparser.has_option('general', 'email'):
             self.email = pparser.get('general', 'email')
         if self.email == '' and self.notify:
                 return False
     else:
         return False
     return True
Beispiel #12
0
class Configuration(object):
    """
    Singleton class to access application's configuration.
    """
    def __init__(self):
        self.parser = RawConfigParser()
        config_file = os.path.join(get_install_dir(), 'config.ini')
        self.parser.read(config_file)

    def get(self, section, option):
        return self.parser.get(section, option)

    def getboolean(self, section, option):
        return self.parser.getboolean(section, option)

    def getfloat(self, section, option):
        return self.parser.getfload(section, option)

    def getint(self, section, option):
        return self.parser.getint(section, option)

    def has_option(self, section, option):
        return self.parser.has_option(section, option)

    def has_section(self, section):
        return self.parser.has_section(section)
Beispiel #13
0
def _read_config(conf_file, running):
    parser = RawConfigParser()
    parser.read([conf_file])
    for section in sorted(parser.sections()):
        if parser.has_option(section, 'pattern'):
            pattern = parser.get(section, 'pattern')
        else:
            pattern = None
        yield dict(command=parser.get(section, 'command'),
                   period=parser.getint(section, 'period'),
                   selected=parser.getboolean(section, 'selected'),
                   active=parser.getboolean(section, 'active'),
                   show_diffs=parser.getboolean(section, 'show_diffs'),
                   pattern=pattern,
                   layout=parser.get(section, 'layout'),
                   graph=parser.getboolean(section, 'graph'))
Beispiel #14
0
 def __read_config(self):
     """
     Obtiene la configuración de la persona de su archivo .person y devuelve True si es válida
     """
     pparser = RawConfigParser()
     with codecs.open("config/" + self.person + '.person',
                      'r',
                      encoding='utf-8') as cf:
         pparser.readfp(cf)
     if pparser.has_section("general"):
         if pparser.has_option('general', 'name'):
             self.name = pparser.get('general', 'name')
             if self.name == '':
                 return False
         else:
             return False
         if pparser.has_option('general', 'notify'):
             self.notify = pparser.getboolean('general', 'notify')
         if pparser.has_option('general', 'alarm_threshold'):
             self.alarm_threshold = pparser.getint(
                 'general', 'alarm_threshold')
         if pparser.has_option('general', 'email'):
             self.email = pparser.get('general', 'email')
         if self.email == '' and self.notify:
             return False
     else:
         return False
     return True
Beispiel #15
0
def read_options():
    """Read options"""
    config = RawConfigParser()
    config.read(expanduser('~/.lumberrc'))
    parser = OptionParser()
    for short, option, section, default, metavar, helptext in OPTIONS:
        sectiontext = ' Configure in ~/.lumberrc as %s in %s section.' % (
            option, section)
        try:
            if type(default) == type(True):
                action = 'store_true'
                cdefault = config.getboolean(section, option)
            else:
                action = 'store'
                cdefault = config.get(section, option)
        except (NoOptionError, NoSectionError):
            cdefault = default
        argl = []
        if short:
            argl.append ('-'+short)
        argl.append('--'+option.replace('_', '-'))
        argk = {'action':action, 'default':cdefault, 'metavar':metavar, 
                'help':helptext+sectiontext}
        parser.add_option(*argl, **argk)
    options, args = parser.parse_args()
    return options, args, config
Beispiel #16
0
class Config:

    BLINDS = 0
    BLINDX = 1
    WEB = 2
    SECTIONS = ["blinds", "blind_%d", "webServer"]

    STRING_KEYS = [
        "msgFormat", "logFileName", "endPoint", "webRoot", "default", "name",
        "tag", "address", "cmdDriveIn", "cmdDriveOut", "cmdStop", "headline"
    ]
    INT_KEYS = ["maxFilesize", "logLevel", "count"]
    BOOLEAN_KEYS = ["enableLogging"]

    DEFAULTS = {
        "enableLogging": "yes",
        "logFileName": "/tmp/pbc.log",
        "maxFilesize": 1000000,
        "msgFormat":
        "%(asctime)s, %(levelname)s, %(module)s {%(process)d}, %(lineno)d, %(message)s",
        "logLevel": 10
    }

    def __init__(self, cfgFile, section):
        self.section = section
        self.cfg = RawConfigParser(Config.DEFAULTS)
        _ = self.cfg.read(cfgFile)

    def hasKey(self, dct, key):
        k = key.upper()
        for d in dct:
            if d.upper() == k:
                return d
        return None

    def hasSection(self, section):
        return self.cfg.has_section(section)

    def hasOption(self, option):
        return self.cfg.has_option(self.section, option)

    def __getattr__(self, name):
        key = self.hasKey(Config.STRING_KEYS, name)
        if not key is None:
            return self.cfg.get(self.section, key)
        key = self.hasKey(Config.INT_KEYS, name)
        if not key is None:
            return self.cfg.getint(self.section, key)
        key = self.hasKey(Config.BOOLEAN_KEYS, name)
        if not key is None:
            return self.cfg.getboolean(self.section, key)
        return None

    def setSection(self, newSection):
        tmp = self.section
        self.section = newSection
        return tmp

    def readValue(self, key):
        return self.cfg.get(self.section, key)
Beispiel #17
0
def parse_conf(conf_fd):
    """Parse configuration file"""
    config = RawConfigParser()
    config.readfp(conf_fd)

    try:
        settings = {
            'host_ip': config.get('main', 'host_ip'),
            'runtime': config.getint('main', 'runtime'),
            'timeout': config.getint('main', 'timeout'),
            'use_sudo': config.getboolean('main', 'use_sudo'),
            'rekall': config.get('main', 'rekall'),
            'xml_conf': config.get('main', 'xml_conf'),
            'vol_bin': config.get('main', 'vol_bin'),
            'vol_prof': config.get('main', 'vol_prof'),
        }
    except (NoOptionError, ValueError) as e:
        log.error('Configuration is missing parameters. See example.conf.')
        sys.exit(1)

    errors = False
    for filepath in ['rekall', 'xml_conf']:
        if not os.path.isfile(settings[filepath]):
            log.error('Not a file: ' + str(settings[filepath]))
            errors = True
    if errors:
        log.error('Config file contains errors')
        sys.exit(1)

    return settings
Beispiel #18
0
 def _readConfig(cls, filename):
     '''
     Read the configuration file and return a pythonic configuration dict.
     '''
     confParser = RawConfigParser(defaults={
         # these keys can be commented out in the config file,
         # warning: the values are converted to strings
         'user': None,
         'pathRegexFilter': '',
         'filenameRegexFilter': '',
         'subPath': '',
         'includes': '',
         'macros': '',
         'languages': '',
         'metrics': '',
         'settings': '',
         'aggregateIssueLinks': '',
         'shortBlockLines': 4}
     )
     parsedFiles = confParser.read(filename)
     if not parsedFiles:
         msg = "Configuration file {} could not be read.".format(filename)
         raise Exception(msg)
     conf = {
         'sina': {},
         'neteasy': {},
         'hanjie': {},
         'matching': {},
     }
     # TODO: The 'configfie' entry is unused
     conf['consoleLog'] = confParser.getboolean('global', 'consoleLog')
     conf['debugMode'] = confParser.getboolean('global', 'debugMode')
     conf['encoding'] = confParser.get('global', 'encoding')
     conf['http_proxy'] = confParser.get('global', 'http_proxy')
     conf['configfile'] = os.path.abspath(filename)
     conf['basePath'] = os.path.abspath(convertOsPath(confParser.get('global', 'basePath')))
     if confParser.has_section('sina'):
        conf['sina']['url'] = confParser.get('sina', 'url')
        conf['sina']['user'] = confParser.get('sina','user')
        conf['sina']['password'] = confParser.get('sina','password')
     if confParser.has_section('netease'):
        conf['netease']['url'] = confParser.get('netease', 'url')
        conf['netease']['user'] = confParser.get('netease','user')
        conf['netease']['password'] = confParser.get('netease','password')
     
     _convertDictUnicode(conf)
     return conf
Beispiel #19
0
class SncConfig(object):
    def __init__(self):
        self.config = RawConfigParser(allow_no_value=False)
        try:
            if ENVB_PATH in os.environ:
                self.config_file_path = os.environ[
                    ENVB_PATH] + os.sep + ENVBUILDER_CONF
                if len(str(
                        self.config_file_path).strip()) > len(ENVBUILDER_CONF):
                    self.config.read(self.config_file_path)
                else:
                    self.config.read(ENVBUILDER_CONF)
            else:
                self.config.read(ENVBUILDER_CONF)
                os.environ[ENVB_PATH] = os.getcwd()
        except:
            ColorPrint.err("Config file {0} not found".format(ENVBUILDER_CONF))
            exit(1)

    def getstring(self, section, param_name):
        try:
            return self.config.get(section, param_name)
        except:
            ColorPrint.err(
                "Config file {0} or section not found".format(ENVBUILDER_CONF))
            exit(1)

    def getboolean(self, section, param_name):
        try:
            return self.config.getboolean(section, param_name)
        except:
            ColorPrint.err(
                "Config file {0} or section not found".format(ENVBUILDER_CONF))
            exit(1)

    def getint(self, section, param_name):
        try:
            return self.config.getint(section, param_name)
        except:
            ColorPrint.err(
                "Config file {0} or section not found".format(ENVBUILDER_CONF))
            exit(1)

    def getlist(self, section, param_name):
        try:
            cfg_list = self.config.get(section, param_name)
            return cfg_list.split(",")
        except:
            ColorPrint.err(
                "Config file {0} or section not found".format(ENVBUILDER_CONF))
            exit(1)

    def getsection(self, section_name):
        try:
            return self.config.items(section_name)
        except:
            ColorPrint.err(
                "Config file {0} or section not found".format(ENVBUILDER_CONF))
            exit(1)
Beispiel #20
0
 def getboolean(self, section, option, *args):
     if len(args) > 0:
         try:
             return RawConfigParser.getboolean(self, section, option)
         except (NoSectionError, NoOptionError):
             return args[0]
     else:
         return RawConfigParser.get(self, section, option)
Beispiel #21
0
    def __init__(self, config_file, *args, **kwargs):
        """
        Класс настроек ЕСИА на основе конфигурационного файла

        :param str config_file: путь к конфигурационному ini-файлу
        :raises ConfigFileError: если указан неверный путь или файл недоступен
            для чтения
        :raises ConfigParser.*: при ошибках в формате файла или параметра
        """
        if os.path.isfile(config_file) and os.access(config_file, os.R_OK):
            conf = RawConfigParser()
            conf.read(config_file)
            base_dir = os.path.dirname(config_file)

            kwargs = {
                'esia_client_id': conf.get('esia', 'CLIENT_ID'),
                'redirect_uri': conf.get('esia', 'REDIRECT_URI'),
                'esia_service_url': conf.get('esia', 'SERVICE_URL'),
                'esia_scope': conf.get('esia', 'SCOPE'),
                'crypto_backend': conf.get('esia', 'CRYPTO_BACKEND'),
                'certificate_file': None,
                'private_key_file': None,
                'csp_cert_thumbprint': None,
                'csp_container_pwd': None,
                'ssl_verify': True
            }

            # Openssl, M2Crypto params
            if conf.has_option('esia', 'CERT_FILE') and \
                    conf.has_option('esia', 'PRIV_KEY_FILE'):
                cert_f = conf.get('esia', 'CERT_FILE')
                pkey_f = conf.get('esia', 'PRIV_KEY_FILE')
                kwargs['certificate_file'] = base_dir + '/' + cert_f
                kwargs['private_key_file'] = base_dir + '/' + pkey_f

            # CryptoPro CSP params
            if conf.has_option('esia', 'CSP_CERT_THUMBPRINT'):
                kwargs['csp_cert_thumbprint'] = conf.get(
                    'esia', 'CSP_CERT_THUMBPRINT')
                kwargs['csp_container_pwd'] = conf.get('esia',
                                                       'CSP_CONTAINER_PWD')

            if conf.has_option('esia', 'JWT_CHECK_KEY'):
                token_check_key = conf.get('esia', 'JWT_CHECK_KEY')
                kwargs['esia_token_check_key'] = \
                    base_dir + '/' + token_check_key

            if conf.has_option('esia', 'LOGOUT_REDIRECT_URI'):
                redir = conf.get('esia', 'LOGOUT_REDIRECT_URI')
                kwargs['logout_redirect_uri'] = redir

            if conf.has_option('esia', 'SSL_VERIFY'):
                ssl_verify = conf.getboolean('esia', 'SSL_VERIFY')
                kwargs['ssl_verify'] = ssl_verify

            super(EsiaConfig, self).__init__(*args, **kwargs)
        else:
            raise ConfigFileError("Config file not exists or not readable!")
Beispiel #22
0
def read_config(filename, section='kleenex'):
    """
    This looks for [kleenex] in ``filename`` such as the following:

    [kleenex]
    db = sqlite:///coverage.db
    parent = origin/master
    discover = true
    report = true
    report_output = -
    record = true
    skip_missing = true
    max_distance = 4
    test_missing = true
    max_revisions = 100
    """
    config = RawConfigParser({
        'db': 'sqlite:///coverage.db',
        'parent': 'origin/master',
        'discover': 'false',
        'report': 'true',
        'report_output': '-',
        'record': 'false',
        'skip_missing': 'true',
        'max_distance': '4',
        'test_missing': 'true',
        'max_revisions': '100',
    }, dict_type=Config)
    config.read(filename)

    if not config.has_section(section):
        return config.defaults()

    return Config({
        'db': config.get(section, 'db'),
        'parent': config.get(section, 'parent'),
        'discover': config.getboolean(section, 'discover'),
        'report': config.getboolean(section, 'report'),
        'report_output': config.get(section, 'report_output'),
        'record': config.getboolean(section, 'record'),
        'skip_missing': config.getboolean(section, 'skip_missing'),
        'max_distance': config.getint(section, 'max_distance'),
        'test_missing': config.getboolean(section, 'test_missing'),
        'max_revisions': config.getint(section, 'max_revisions'),
    })
Beispiel #23
0
 def getboolean(self, section, option, default):
     value = default
     try:
         if RawConfigParser.has_section(self, section):
             if RawConfigParser.has_option(self, section, option):
                 value = RawConfigParser.getboolean(self, section, option)
     except:
         value = default
     return value
Beispiel #24
0
class Config(object):

    """
    Manage configuration - a simple wrapper around RawConfigParser.
    Upon initialization, the loaded file is updated with the default values.
    config.save() will save the current state.
    """

    def __init__(self):
        self.filename = get_config_fn()
        try:
            self.parser = RawConfigParser(dict_type=OrderedDict)
        except TypeError:
            # Python versions < 2.6 don't support dict_type
            self.parser = RawConfigParser()
        f = StringIO(default_config)
        self.parser.readfp(f)
        self.parser.read(self.filename)
        self.save()
    
    def get(self, key, section='DreamPie'):
        return self.parser.get(section, key)
    
    def get_bool(self, key, section='DreamPie'):
        return self.parser.getboolean(section, key)
    
    def get_int(self, key, section='DreamPie'):
        return self.parser.getint(section, key)
    
    def set(self, key, value, section='DreamPie'):
        self.parser.set(section, key, value)
    
    def set_bool(self, key, value, section='DreamPie'):
        value_str = 'True' if value else 'False'
        self.set(key, value_str, section)
    
    def set_int(self, key, value, section='DreamPie'):
        if value != int(value):
            raise ValueError("Expected an int, got %r" % value)
        self.set(key, '%d' % value, section)
    
    def sections(self):
        return self.parser.sections()

    def has_section(self, section):
        return self.parser.has_section(section)

    def add_section(self, section):
        return self.parser.add_section(section)

    def remove_section(self, section):
        return self.parser.remove_section(section)

    def save(self):
        f = open(self.filename, 'w')
        self.parser.write(f)
        f.close()
Beispiel #25
0
def settingsvar():
    testconfig()
    parser = RawConfigParser()
    results = parser.read("config.ini")
    sections = parser.sections()
    settings = []
    if parser.has_option(sections[2], "autoupdate"):
        settings.append(parser.getboolean(sections[2], "autoupdate"))
    return settings
Beispiel #26
0
    def load_config(self, environ):
        """Load configuration options

        Options are read from a config file.

        Backwards compatibility:
            - if ConfigFile is not set, opts are loaded from http config
            - if ConfigFile is set, then the http config must not provide Koji options
            - In a future version we will load the default hub config regardless
            - all PythonOptions (except koji.web.ConfigFile) are now deprecated and
              support for them will disappear in a future version of Koji
        """
        modpy_opts = environ.get('modpy.opts', {})
        if 'modpy.opts' in environ:
            cf = modpy_opts.get('koji.web.ConfigFile', None)
            # to aid in the transition from PythonOptions to web.conf, we do
            # not check the config file by default, it must be configured
        else:
            cf = environ.get('koji.web.ConfigFile', '/etc/kojiweb/web.conf')
        if cf:
            if not os.path.isfile(cf):
                raise koji.GenericError, "Configuration missing: %s" % cf
            config = RawConfigParser()
            config.read(cf)
        else:
            #can only happen under mod_python
            self.logger.warn('Warning: configuring Koji via PythonOptions is deprecated. Use web.conf')
        opts = {}
        for name, dtype, default in self.cfgmap:
            if cf:
                key = ('web', name)
                if config.has_option(*key):
                    if dtype == 'integer':
                        opts[name] = config.getint(*key)
                    elif dtype == 'boolean':
                        opts[name] = config.getboolean(*key)
                    else:
                        opts[name] = config.get(*key)
                else:
                    opts[name] = default
            else:
                if modpy_opts.get(name, None) is not None:
                    if dtype == 'integer':
                        opts[name] = int(modpy_opts.get(name))
                    elif dtype == 'boolean':
                        opts[name] = modpy_opts.get(name).lower() in ('yes', 'on', 'true', '1')
                    else:
                        opts[name] = modpy_opts.get(name)
                else:
                    opts[name] = default
        if 'modpy.conf' in environ:
            debug = environ['modpy.conf'].get('PythonDebug', '0').lower()
            opts['PythonDebug'] = (debug in ['yes', 'on', 'true', '1'])
        opts['Secret'] = koji.util.HiddenValue(opts['Secret'])
        self.options = opts
        return opts
Beispiel #27
0
 def getboolean(self, section, option):
     try:
         return RawConfigParser.getboolean(self, section, option)
     except AttributeError:
         # XXX:
         # For some reason, getboolean likes to die sometimes.
         # Until I figure it out, this will act as a band-aid
         # to prevent the error from causing Lookit to not work
         value = self.get(section, option)
         return value == "True"
Beispiel #28
0
 def getboolean(self, section, option):
     try:
         return RawConfigParser.getboolean(self, section, option)
     except AttributeError:
         # XXX:
         # For some reason, getboolean likes to die sometimes.
         # Until I figure it out, this will act as a band-aid
         # to prevent the error from causing Lookit to not work
         value = self.get(section, option)
         return value == "True"
Beispiel #29
0
class Config(object):
    """
    Manage configuration - a simple wrapper around RawConfigParser.
    Upon initialization, the loaded file is updated with the default values.
    config.save() will save the current state.
    """
    def __init__(self):
        self.filename = get_config_fn()
        try:
            self.parser = RawConfigParser(dict_type=OrderedDict)
        except TypeError:
            # Python versions < 2.6 don't support dict_type
            self.parser = RawConfigParser()
        f = StringIO(default_config)
        self.parser.readfp(f)
        self.parser.read(self.filename)
        self.save()

    def get(self, key, section='DreamPie'):
        return self.parser.get(section, key)

    def get_bool(self, key, section='DreamPie'):
        return self.parser.getboolean(section, key)

    def get_int(self, key, section='DreamPie'):
        return self.parser.getint(section, key)

    def set(self, key, value, section='DreamPie'):
        self.parser.set(section, key, value)

    def set_bool(self, key, value, section='DreamPie'):
        value_str = 'True' if value else 'False'
        self.set(key, value_str, section)

    def set_int(self, key, value, section='DreamPie'):
        if value != int(value):
            raise ValueError("Expected an int, got %r" % value)
        self.set(key, '%d' % value, section)

    def sections(self):
        return self.parser.sections()

    def has_section(self, section):
        return self.parser.has_section(section)

    def add_section(self, section):
        return self.parser.add_section(section)

    def remove_section(self, section):
        return self.parser.remove_section(section)

    def save(self):
        f = open(self.filename, 'w')
        self.parser.write(f)
        f.close()
Beispiel #30
0
def load_config(path):
    c = RawConfigParser()
    c.read(path)

    d = {}
    d.update(c.items('servo'))

    d['pulse_port'] = c.getint('servo', 'pulse_port')
    d['pulse_ssl'] = c.getboolean('servo', 'pulse_ssl')

    return d
Beispiel #31
0
 def getboolean(self, section, option, default=None):
     # default should be a string.
     #    _boolean_states = {
     #        '1': True, 'yes': True, 'true': True, 'on': True,
     #        '0': False, 'no': False, 'false': False, 'off': False}
     val = default
     try:
         val = RawConfigParser.getboolean(self, section, option)
     except NoOptionError, e:
         # NOTE: None cannot be the default.
         if default is None:
             raise
Beispiel #32
0
class preferences:
	config = []
	parse = None
	lcdconnection = None
	
	def __init__(self):
		if (DEBUG == True): 
			self.writetolog("Init Prefs")
		self.loadprefs(None, None, None)
		if (DEBUG == True): 
			self.writetolog("Done")
			
	def loadprefs(self, word, word_eol, userdata):
		if (self.lcdconnection != None):
			self.lcdconnection.offlights(None, None, None)
		prefs = open(module_dir + "config.txt")
		self.parse = RawConfigParser()
		self.parse.readfp(prefs)
		prefs.close()
		print "Prefrences Loaded"
				
	def value(self,option):
		if (DEBUG == True): 
			self.writetolog("Prefs -> Value") 
		return self.parse.get("config",option)
		if (DEBUG == True): 
			self.writetolog("Done")
			
	def floatvalue(self,option):
		if (DEBUG == True): 
			self.writetolog("Prefs -> FloatValue") 
		return self.parse.getfloat("config",option)
		if (DEBUG == True): 
			self.writetolog("Done")
	
	def intvalue(self,option):
		if (DEBUG == True): 
			self.writetolog("Prefs -> IntValue") 
		return self.parse.getint("config",option)
		if (DEBUG == True): 
			self.writetolog("Done")
			
	def boolvalue(self,option):
		if (DEBUG == True): 
			self.writetolog("Prefs -> IntValue") 
		return self.parse.getboolean("config",option)
		if (DEBUG == True): 
			self.writetolog("Done")
			
	def writetolog(self, message):
		debuglog = open(module_dir + "log.txt","a")
		debuglog.write(message + "\n")
		debuglog.close
Beispiel #33
0
 def getboolean(self, section, option, default=None):
    # default should be a string.
    #    _boolean_states = {
    #        '1': True, 'yes': True, 'true': True, 'on': True,
    #        '0': False, 'no': False, 'false': False, 'off': False}
    val = default
    try:
       val = RawConfigParser.getboolean(self, section, option)
    except NoOptionError, e:
       # NOTE: None cannot be the default.
       if default is None:
          raise
Beispiel #34
0
class Settings():
	_changed  = True
	def __init__(self):
		self._settings = RawConfigParser()
		self._funcs = (self._getGeneric, self._getInt, self._getFloat, self._getStruct, self._getBool)
		
	def getValue(self, section, option, select):
                """Returns value from settings file - 0: string/raw value, 1: integer, 2: float, 3: data structure, 4: boolean"""
                if Settings._changed:
			self._fileOpen()
			Settings._changed = False
		return self._funcs[select](section,option)
		
	def changeValue(self, section, option):
		self._settings.set(section, str(option))
		with open('cellular.ini', 'wb') as fp: self._settings.write(fp)
		Settings._changed = True
		
	def _throwError(self, message, title = 'Fatal Error'):
		Tkinter.Tk().withdraw()
		tkMessageBox.showerror(str(title),str(message))
		exit
	
	def _fileOpen(self):
		try: fp = open(configFile)
		except IOError: self._throwError('config file not found.\nThe program will now terminate.')
		self._settings.readfp(fp)

	def _getGeneric(self, section, option):
		value = self._settings.get(section, option)
		return value
		
	def _getInt(self, section, option):
		try: value = self._settings.getint(section,option)
		except ValueError: self._throwError('Expected integer, recieved something else at ['+section+'],'+option+'.\nThe program will now terminate.')
		return value

	def _getFloat(self, section, option):
		try: value = self._settings.getfloat(section,option)  
		except ValueError: self._throwError('Expected float, recieved something else at ['+section+'],'+option+'.\nThe program will now terminate.')
		return value

	def _getStruct(self, section, option):
		try: value = decode(self._settings.get(section,option))
		except ValueError or SyntaxError: self._throwError('Expected data structure, recieved something else at ['+section+'], '+option+'.\nTheProgram will now terminate.')
		return value

	def _getBool(self, section, option):
		try: value = self._settings.getboolean(section,option)
		except ValueError: self._throwError('Expected boolean, recieved something else at ['+section+'], '+option+'.\nThe program will now terminate.')
		return value
Beispiel #35
0
def get_option_autostart(options, section):
    """Retrieve auto_start option from a section
    """
    #print self.data['conf_file']
    if 'conf_file' in options and options['conf_file'] is not None:
        config = RawConfigParser()
        config.read([options['conf_file']])
        try:
            return config.getboolean(section, 'auto_start')
        except ConfigParser.NoOptionError:
            return False
        except ConfigParser.NoSectionError:
            return False
    return False
Beispiel #36
0
class Config:

    SECTION = "mail2Shell"
    STRING_KEYS=["mailServer", "smtpServer", "username", "password", "magicKey", "trustedSender", "msgFormat", "logFileName", \
                 "workDir", "path2Shell", "keys", "gpgBinary", "hashStore"]
    INT_KEYS = ["maxFilesize", "keepRunning", "hashBufferSize"]
    BOOLEAN_KEYS = [
        "enableLogging", "enableGPG", "allowOnlyGPG", "verifySignature"
    ]

    DEFAULTS = {
        "enableLogging": "yes",
        "logFileName": "/tmp/mail2shell.log",
        "maxFilesize": 1000000,
        "msgFormat":
        "%(asctime)s, %(levelname)s, %(module)s, %(lineno)d, %(message)s",
        "path2Shell": "/bin/sh",
        "keepRunning": 0,
        "enableGPG": "False",
        "keys": "./keys",
        "allowOnlyGPG": "False",
        "verifySignature": "False",
        "gpgBinary": "/usr/local/bin/gpg",
        "hashBufferSize": 1024,
        "hashStore": "./hashStore.json"
    }

    def __init__(self, cfgFile):
        self.cfg = RawConfigParser(Config.DEFAULTS)

        _ = self.cfg.read(cfgFile)

    def hasKey(self, dct, key):
        k = key.upper()
        for d in dct:
            if d.upper() == k:
                return d
        return None

    def __getattr__(self, name):
        key = self.hasKey(Config.STRING_KEYS, name)
        if not key is None:
            return self.cfg.get(Config.SECTION, key)
        key = self.hasKey(Config.INT_KEYS, name)
        if not key is None:
            return self.cfg.getint(Config.SECTION, key)
        key = self.hasKey(Config.BOOLEAN_KEYS, name)
        if not key is None:
            return self.cfg.getboolean(Config.SECTION, key)
        return None
Beispiel #37
0
    def override_from_config(self, filename):
        config = RawConfigParser()
        if IS_PY3:
            config.read_file(open(filename))
        else:
            config.readfp(open(filename))

        # Common options
        if config.has_section('bumpr'):
            for option in config.options('bumpr'):
                if option in ('tag', 'commit'):
                    self[option] = config.getboolean('bumpr', option)
                elif option == 'files':
                    # pylint: disable=W0201
                    self.files = [name.strip() for name in config.get('bumpr', 'files').split('\n') if name.strip()]
                    # pylint: enable=W0201
                else:
                    self[option] = config.get('bumpr', option)

        # Bump and next section
        for section in 'bump', 'prepare':
            for option in 'message', 'suffix':
                if config.has_option(section, option):
                    self[section][option] = config.get(section, option)
            if config.has_option(section, 'unsuffix'):
                self[section]['unsuffix'] = config.getboolean(section, 'unsuffix')

            if config.has_option(section, 'part'):
                self[section]['part'] = PARTS[config.get(section, 'part').lower()]

        for hook in HOOKS:
            if config.has_section(hook.key):
                if not self.get(hook.key, False):
                    self[hook.key] = hook.defaults
                self[hook.key].update(config.items(hook.key))
            else:
                self[hook.key] = False
Beispiel #38
0
    def override_from_config(self, filename):
        config = RawConfigParser()
        if IS_PY3:
            config.read_file(open(filename))
        else:
            config.readfp(open(filename))

        # Common options
        if config.has_section('bumpr'):
            for option in config.options('bumpr'):
                if option in ('tag', 'commit'):
                    self[option] = config.getboolean('bumpr', option)
                elif option == 'files':
                    # pylint: disable=W0201
                    self.files = [name.strip() for name in config.get('bumpr', 'files').split('\n') if name.strip()]
                    # pylint: enable=W0201
                else:
                    self[option] = config.get('bumpr', option)

        # Bump and next section
        for section in 'bump', 'prepare':
            for option in 'message', 'suffix':
                if config.has_option(section, option):
                    self[section][option] = config.get(section, option)
            if config.has_option(section, 'unsuffix'):
                self[section]['unsuffix'] = config.getboolean(section, 'unsuffix')

            if config.has_option(section, 'part'):
                self[section]['part'] = PARTS[config.get(section, 'part').lower()]

        for hook in HOOKS:
            if config.has_section(hook.key):
                if not self.get(hook.key, False):
                    self[hook.key] = hook.defaults
                self[hook.key].update(config.items(hook.key))
            else:
                self[hook.key] = False
def get_categories():
    categories = {}
    cat_parser = RawConfigParser()
    if os.path.isfile(os.path.join("data", "categories.ini")):
        cat = open(os.path.join("data", "categories.ini"))
    else:
        cat = open(
            os.path.join(control.controller.data_system_path,
                         "categories.ini"))
    cat_parser.readfp(cat)
    for section in cat_parser.sections():
        name = cat_parser.get(section, "name")
        icon = cat_parser.get(section, "icon")
        #tags = cat_parser.get(section, "contains")
        showboth = cat_parser.getboolean(section, "showboth")
        categories[section] = [icon, _(name), showboth]
    return categories
Beispiel #40
0
    def __init__(self, cfg_file, pwd_file):
        
        self._cfg_file = cfg_file
        self._pwd_file = pwd_file
        
        cfg = {}
        config = RawConfigParser()
        config.read(cfg_file)

        for section in config.sections():
            cfg[section] = dict(config.items(section))
            
        # Split username and domain since it's used on incoming mail
        # regex (EMAIL_REGEX)
        cfg['email']['username'], cfg['email']['domain'] = cfg['email']['address'].split('@')

        # IMAP/SMTP usernames are optional
        for section in 'imap', 'smtp':
            if (not 'username' in cfg[section]) or (cfg[section]['username'] == ''):
                cfg[section]['username'] = cfg['email']['address']

        # Coerce boolean values
        bln = [('main', 'save_passwords'),
               ('main', 'debug'),
               ('imap', 'ssl'),
               ('smtp', 'ssl'),
               ('smtp', 'tls')]
        for section, setting in bln:
            cfg[section][setting] = config.getboolean(section, setting)
            
        # Read passwords
        config = RawConfigParser()
        config.read(pwd_file)
        if config.has_section('passwords'):
            for section, password in config.items('passwords'):
                cfg[section]['password'] = password

        if cfg['main']['debug']:
            cfg['DEBUG'] = True
        else:
            cfg['DEBUG'] = False
            
        del(cfg['main']['debug'])
            
        self._config = cfg
Beispiel #41
0
    def load_config(self, environ):
        """Load configuration options

        Options are read from a config file.

        Backwards compatibility:
            - if ConfigFile is not set, opts are loaded from http config
            - if ConfigFile is set, then the http config must not provide Koji options
            - In a future version we will load the default hub config regardless
            - all PythonOptions (except koji.web.ConfigFile) are now deprecated and
              support for them will disappear in a future version of Koji
        """
        cf = environ.get('koji.web.ConfigFile', '/etc/kojiweb/web.conf')
        cfdir = environ.get('koji.web.ConfigDir', '/etc/kojiweb/web.conf.d')
        if cfdir:
            configs = koji.config_directory_contents(cfdir)
        else:
            configs = []
        if cf and os.path.isfile(cf):
            configs.append(cf)
        if configs:
            config = RawConfigParser()
            config.read(configs)
        else:
            raise koji.GenericError("Configuration missing")

        opts = {}
        for name, dtype, default in self.cfgmap:
            key = ('web', name)
            if config and config.has_option(*key):
                if dtype == 'integer':
                    opts[name] = config.getint(*key)
                elif dtype == 'boolean':
                    opts[name] = config.getboolean(*key)
                elif dtype == 'list':
                    opts[name] = [
                        x.strip() for x in config.get(*key).split(',')
                    ]
                else:
                    opts[name] = config.get(*key)
            else:
                opts[name] = default
        opts['Secret'] = koji.util.HiddenValue(opts['Secret'])
        self.options = opts
        return opts
Beispiel #42
0
    def read_ini(self, filename):
        if not filename or not os.path.isfile(filename):
            return

        parser = RawConfigParser()
        parser.read(filename)
        for section in parser.sections():
            for option in parser.options(section):
                value = None
                if section in self.defaults and option in self.defaults[section]:
                    t = type(self.defaults[section][option])
                    if   t is str:   value = parser.get(section, option)
                    elif t is int:   value = parser.getint(section, option)
                    elif t is float: value = parser.getfloat(section, option)
                    elif t is bool:  value = parser.getboolean(section, option)
                else:
                    value = parser.get(section, option)
                self.set(section, option, value)
Beispiel #43
0
	def __init__(self, config_path):
		config = RawConfigParser()
		config.read(config_path)
		protocol = mqtt.MQTTv31
		if (config.has_option('mqtt', 'use311') and
		    config.getboolean('mqtt', 'use311')):
			kLog.debug('311')
			protocol = mqtt.MQTTv311
		self.name = config.get('mqtt', 'client_name')
		client = mqtt.Client(client_id=self.name,
				     clean_session=True,
				     protocol=protocol)
		client.username_pw_set(config.get('mqtt', 'username'), config.get('mqtt', 'password'))
		client.tls_set(config.get('mqtt', 'ca_cert'))
		if config.get('mqtt','hostname') in ('localhost', '127.0.0.1', '::1'):
			client.tls_insecure_set(True)
		self.config = config
		self.client = client
    def _get_autoreload_programs(self, cfg_file):
        """Get the set of programs to auto-reload when code changes.

        Such programs will have autoreload=true in their config section.
        This can be affected by config file sections or command-line
        arguments, so we need to read it out of the merged config.
        """
        cfg = RawConfigParser()
        cfg.readfp(cfg_file)
        reload_progs = []
        for section in cfg.sections():
            if section.startswith("program:"):
                try:
                    if cfg.getboolean(section, "autoreload"):
                        reload_progs.append(section.split(":", 1)[1])
                except NoOptionError:
                    pass
        return reload_progs
    def _get_autoreload_programs(self,cfg_file):
        """Get the set of programs to auto-reload when code changes.

        Such programs will have autoreload=true in their config section.
        This can be affected by config file sections or command-line
        arguments, so we need to read it out of the merged config.
        """
        cfg = RawConfigParser()
        cfg.readfp(cfg_file)
        reload_progs = []
        for section in cfg.sections():
            if section.startswith("program:"):
                try:
                    if cfg.getboolean(section,"autoreload"):
                        reload_progs.append(section.split(":",1)[1])
                except NoOptionError:
                    pass
        return reload_progs
    def __init__(self, filepath):
        config = RawConfigParser()
        config.read(filepath)
        self.fp = filepath
        self.name = config.get('Task', 'name')
        self.description = config.get('Task', 'description')
        self.basic_url = config.get('Task', 'Basic_url')
        self.area = map(float, config.get('Task', 'Area').split(','))
        self.max_z = config.getint('Task', 'maxZoom')
        self.min_z = config.getint('Task', 'minZoom')
        
                
        self.debug = config.getboolean('Debug', 'debugmode')
        self.debugTryTimes = config.getint('Debug', 'TryTimes')
        
        self.MAX_Threads = config.getint('Run', 'MAX_Threads')
        self.MAX_QUEUE = config.getint('Run', 'MAX_QUEUE')
        self.image_floder = config.get('File', 'ImageFloder')
        
        self.min_x = int(lonToTileX(self.area[0], self.min_z))
        self.min_y = int(latToTileY(self.area[3], self.min_z))
        self.max_x = int(lonToTileX(self.area[1], self.min_z))
        self.max_y = int(latToTileY(self.area[2], self.min_z))
        self.x = config.getint('Task-State', 'currentX')
        self.y = config.getint('Task-State', 'currentY')
        # Initialize
        if self.x == 0 and self.y == 0:
            self.x = self.min_x
            self.y = self.min_y
        # Breakpoint Resume
        elif self.x-self.min_x+(self.y-self.min_y)*(self.max_x-self.min_x)>3*self.MAX_QUEUE:
            if self.x - self.min_x > 3*self.MAX_QUEUE:
                self.x = self.x - 3*self.MAX_QUEUE
            else:
                self.x = self.max_x - (3*self.MAX_QUEUE - (self.x - self.min_x))
                self.y = self.y - 1
        else:
            self.x = self.min_x
            self.y = self.min_y
        

        print self.x, self.max_x
        print self.y, self.max_y
        print (self.max_x-self.x)*(self.max_y-self.y)
Beispiel #47
0
def get_options(args, opt_parser):
    config = RawConfigParser()
    parent = tail = os.path.abspath(os.path.commonprefix(args))
    config_found = False
    while tail and not config_found:
        log.info(tail)
        for fn in PROJECT_CONFIG:
            full_path = os.path.join(parent, fn)
            if config.read(full_path):
                log.info('local configuration: in %s.', full_path)
                config_found = True
                break
        parent, tail = os.path.split(parent)

    new_options = None
    if config.has_section('pep257'):
        option_list = dict([(o.dest, o.type or o.action)
                            for o in opt_parser.option_list])

        # First, read the default values
        new_options, _ = opt_parser.parse_args([])

        # Second, parse the configuration
        pep257_section = 'pep257'
        for opt in config.options(pep257_section):
            if opt.replace('_', '-') not in opt_parser.config_options:
                log.warning("Unknown option '{}' ignored".format(opt))
                continue
            normalized_opt = opt.replace('-', '_')
            opt_type = option_list[normalized_opt]
            if opt_type in ('int', 'count'):
                value = config.getint(pep257_section, opt)
            elif opt_type == 'string':
                value = config.get(pep257_section, opt)
            else:
                assert opt_type in ('store_true', 'store_false')
                value = config.getboolean(pep257_section, opt)
            setattr(new_options, normalized_opt, value)

    # Third, overwrite with the command-line options
    options, _ = opt_parser.parse_args(values=new_options)
    log.debug("options: %s", options)
    return options
Beispiel #48
0
def parse_materials():
    """Parses the materials.ini file."""
    global MATERIALS

    raws = RawConfigParser()
    raws.read('materials.ini')
    for section in raws.sections():
        MATERIALS[section] = {}
        MATERIALS[section]['name'] = section
        MATERIALS[section]['transparent'] = raws.getboolean(section, 'transparent')
        MATERIALS[section]['priority'] = raws.getint(section, 'priority')

        #seperates the color values and converts them into the libtcod standard
        color_tuple = re.split( r'\D+', raws.get(section, 'color floor') )
        color_tuple = map(int, color_tuple)
        MATERIALS[section]['floor_color'] = libtcod.Color( *color_tuple )
        color_tuple = re.split( r'\D+', raws.get(section, 'color wall') )
        color_tuple = map(int, color_tuple)
        MATERIALS[section]['wall_color'] = libtcod.Color( *color_tuple )
Beispiel #49
0
def get_options(args, opt_parser):
    config = RawConfigParser()
    parent = tail = os.path.abspath(os.path.commonprefix(args))
    config_found = False
    while tail and not config_found:
        log.info(tail)
        for fn in PROJECT_CONFIG:
            full_path = os.path.join(parent, fn)
            if config.read(full_path):
                log.info('local configuration: in %s.', full_path)
                config_found = True
                break
        parent, tail = os.path.split(parent)

    new_options = None
    if config.has_section('pep257'):
        option_list = dict([(o.dest, o.type or o.action)
                            for o in opt_parser.option_list])

        # First, read the default values
        new_options, _ = opt_parser.parse_args([])

        # Second, parse the configuration
        pep257_section = 'pep257'
        for opt in config.options(pep257_section):
            if opt.replace('_', '-') not in opt_parser.config_options:
                log.warning("Unknown option '{}' ignored".format(opt))
                continue
            normalized_opt = opt.replace('-', '_')
            opt_type = option_list[normalized_opt]
            if opt_type in ('int', 'count'):
                value = config.getint(pep257_section, opt)
            elif opt_type == 'string':
                value = config.get(pep257_section, opt)
            else:
                assert opt_type in ('store_true', 'store_false')
                value = config.getboolean(pep257_section, opt)
            setattr(new_options, normalized_opt, value)

    # Third, overwrite with the command-line options
    options, _ = opt_parser.parse_args(values=new_options)
    log.debug("options: %s", options)
    return options
Beispiel #50
0
def ReadSingleConfigValue(file, section, type, entry, default, bounds=None):

    try:
        config = RawConfigParser()
        # config parser reads from current directory, when running form a cron tab this is
        # not defined so we specify the full path
        config.read(file)

        if not config.has_option(section, entry):
            return default

        if type.lower() == "string" or type == "password":
            return config.get(section, entry)
        elif type.lower() == "boolean":
            return config.getboolean(section, entry)
        elif type.lower() == "int":
            return config.getint(section, entry)
        elif type.lower() == 'list':
            Value = config.get(section, entry)
            if bounds != None:
                DefaultList = bounds.split(",")
                if Value.lower() in (name.lower() for name in DefaultList):
                    return Value
                else:
                    LogError(
                        "Error Reading Config File (value not in list): %s : %s"
                        % (entry, Value))
                return default
            else:
                LogError(
                    "Error Reading Config File (bounds not provided): %s : %s"
                    % (entry, Value))
                return default
        else:
            LogError("Error Reading Config File (unknown type): %s : %s" %
                     (entry, type))
            return default

    except Exception as e1:
        LogError("Error Reading Config File (ReadSingleConfigValue): " +
                 str(e1))
        return default
Beispiel #51
0
 def __init__(self, conffile_path, conf_sec):
     super(APIFramework, self).__init__()
     conf = RawConfigParser(CONF_DEFAULTS)
     conf.read(conffile_path)
     self.listen_port = conf.getint(conf_sec, 'listen_port')
     #mysql
     self.db_host = conf.get(conf_sec, 'db_host')
     self.db_port = conf.getint(conf_sec, 'db_port')
     self.db_name = conf.get(conf_sec, 'db_name')
     self.db_user = conf.get(conf_sec, 'db_user')
     self.db_password = conf.get(conf_sec, 'db_password')
     db_max_connection = conf.getint(conf_sec, 'db_max_connections')
     db_stale_timeout = conf.getint(conf_sec, 'db_stale_timeout')
     #redis
     self.redis_server = conf.get(conf_sec, 'redis_server').split(',')
     self.redis_port = conf.getint(conf_sec, 'redis_port')
     self.redis_password = conf.get(conf_sec, 'redis_password')
     #debug
     self.debug = conf.getboolean(conf_sec, 'debug')
     #db/redis init
     self.db = db.get_MysqlConnection(self.db_host, self.db_port,
                                      self.db_user, self.db_password,
                                      self.db_name, db_max_connection,
                                      db_stale_timeout)
     self.redis_conn = db.get_RedisConnection(self.redis_server,
                                              self.redis_port,
                                              self.redis_password)
     #errors
     self.error_handler[404] = self.NotFoundError
     self.add_hook('before_request', self.before_request)
     self.add_hook('after_request', self.after_request)
     #install plugins
     self.install(ParseArgs())
     #register handler
     self.loadHandlers(True)
     #install self handler
     if self.debug:
         Bottle.route(self, '/reloadhandlers', ['GET', 'POST'],
                      self.loadHandlers)
     else:
         Bottle.route(self, '/reloadhandlers', 'POST', self.loadHandlers)
Beispiel #52
0
def read_config():
	# config file should be placed in same directory as the script
	config_file_path = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "locopod.config")
	parser = RawConfigParser()

	try:
		parser.readfp(open(config_file_path))
	except IOError:		
		return

	for name, value in parser.items("config"):
		name = name.upper()
		if name in GLOBAL_VARS:
			default = globals()[name]
			if type(default) == type(1):
				value = parser.getint("config", name)
			elif type(default) == type(1.0):
				value = parser.getfloat("config", name)
			elif type(default) == type(True):
				value = parser.getboolean("config", name)
			globals()[name] = value
Beispiel #53
0
def ReadSingleConfigValue(file, section, type, entry, default):

    try:
        config = RawConfigParser()
        # config parser reads from current directory, when running form a cron tab this is
        # not defined so we specify the full path
        config.read(file)

        if not config.has_option(section, entry):
            return default

        if type == "string":
            return config.get(section, entry)
        elif type == "boolean":
            return config.getboolean(section, entry)
        elif type == "int":
            return config.getint(section, entry)
        else:
            return default

    except Exception as e1:
        log.error("Error Reading Config File (ReadSingleConfigValue): " + str(e1))
        return default
def init_local_facility(conf):
    config = RawConfigParser()
    config.readfp(open(conf['__file__'], 'r'))

    global ENCRYPTION_UTILITY

    enabled = False
    if config.has_option('encryptingstorage:encryption', 'enabled'):
        enabled = config.getboolean('encryptingstorage:encryption', 'enabled')

    if enabled:
        kek_path = config.get('encryptingstorage:encryption', 'kek-path')

        if config.has_option('encryptingstorage:encryption', 'kmi-server'):
            kmf = facility.LocalKeyManagementFacility(
                config.get('encryptingstorage:encryption', 'kmi-server'))
        else:
            kmf = facility.KeyManagementFacility(
                config.get('encryptingstorage:encryption', 'dek-storage-path'))

        if kek_path.startswith('/'):
            path = kek_path
        else:
            path = os.path.join(conf['here'], kek_path)

        ENCRYPTION_UTILITY = EncryptionUtility(path, kmf)

        # encryptingstorage specific:
        # just don't provide utilities, who knows what will be defined
        # by the main app

        # provideUtility(ENCRYPTION_UTILITY, IKeyHolder)
        # provideUtility(kmf)

    else:
        ENCRYPTION_UTILITY = TrivialEncryptionUtility()
def init_local_facility(conf):
    config = RawConfigParser()
    config.readfp(open(conf['__file__'], 'r'))

    global ENCRYPTION_UTILITY

    enabled = False
    if config.has_option('encryptingstorage:encryption', 'enabled'):
        enabled = config.getboolean('encryptingstorage:encryption', 'enabled')

    if enabled:
        kek_path = config.get('encryptingstorage:encryption', 'kek-path')

        if config.has_option('encryptingstorage:encryption', 'kmi-server'):
            kmf = facility.LocalKeyManagementFacility(
                config.get('encryptingstorage:encryption', 'kmi-server'))
        else:
            kmf = facility.KeyManagementFacility(
                config.get('encryptingstorage:encryption', 'dek-storage-path'))

        if kek_path.startswith('/'):
            path = kek_path
        else:
            path = os.path.join(conf['here'], kek_path)

        ENCRYPTION_UTILITY = EncryptionUtility(path, kmf)

        # encryptingstorage specific:
        # just don't provide utilities, who knows what will be defined
        # by the main app

        # provideUtility(ENCRYPTION_UTILITY, IKeyHolder)
        # provideUtility(kmf)

    else:
        ENCRYPTION_UTILITY = TrivialEncryptionUtility()
Beispiel #56
0
class MyConfig(MyLog):
    #---------------------MyConfig::__init__------------------------------------
    def __init__(self, filename=None, section=None, log=None):

        super(MyLog, self).__init__()
        self.log = log
        self.FileName = filename
        self.Section = section
        self.CriticalLock = threading.Lock(
        )  # Critical Lock (writing conf file)
        self.InitComplete = False

        self.LogLocation = "/var/log/"
        self.Latitude = 51.4769
        self.Longitude = 0
        self.SendRepeat = 1
        self.UseHttps = False
        self.HTTPPort = 80
        self.HTTPSPort = 443
        self.RTS_Address = "0x279620"
        self.Shutters = {}
        self.ShuttersByName = {}
        self.Schedule = {}
        self.Password = ""

        try:
            self.config = RawConfigParser()
            self.config.read(self.FileName)

            if self.Section == None:
                SectionList = self.GetSections()
                if len(SectionList):
                    self.Section = SectionList[0]

        except Exception as e1:
            self.LogErrorLine("Error in MyConfig:init: " + str(e1))
            return
        self.InitComplete = True

    # -------------------- MyConfig::LoadConfig-----------------------------------
    def LoadConfig(self):

        parameters = {
            'LogLocation': str,
            'Latitude': float,
            'Longitude': float,
            'SendRepeat': int,
            'UseHttps': bool,
            'HTTPPort': int,
            'HTTPSPort': int,
            'TXGPIO': int,
            'RTS_Address': str,
            "Password": str
        }

        self.SetSection("General")
        for key, type in parameters.items():
            try:
                if self.HasOption(key):
                    setattr(self, key, self.ReadValue(key, return_type=type))
            except Exception as e1:
                self.LogErrorLine(
                    "Missing config file or config file entries in Section General for key "
                    + key + ": " + str(e1))
                return False

        parameters = {
            'MQTT_Server': str,
            'MQTT_Port': int,
            'MQTT_User': str,
            'MQTT_Password': str,
            'EnableDiscovery': bool
        }

        self.SetSection("MQTT")
        for key, type in parameters.items():
            try:
                if self.HasOption(key):
                    setattr(self, key, self.ReadValue(key, return_type=type))
            except Exception as e1:
                self.LogErrorLine(
                    "Missing config file or config file entries in Section General for key "
                    + key + ": " + str(e1))
                return False

        self.SetSection("Shutters")
        shutters = self.GetList()
        for key, value in shutters:
            try:
                param1 = value.split(",")
                if param1[1].strip().lower() == 'true':
                    if (len(param1) < 3):
                        param1.append("10")
                    elif (param1[2].strip() == "") or (int(
                            param1[2]) <= 0) or (int(param1[2]) >= 100):
                        param1[2] = "10"
                    param2 = int(
                        self.ReadValue(key,
                                       section="ShutterRollingCodes",
                                       return_type=int))
                    self.Shutters[key] = {
                        'name': param1[0],
                        'code': param2,
                        'duration': int(param1[2])
                    }
                    self.ShuttersByName[param1[0]] = key
            except Exception as e1:
                self.LogErrorLine(
                    "Missing config file or config file entries in Section Shutters for key "
                    + key + ": " + str(e1))
                return False

        self.SetSection("Scheduler")
        schedules = self.GetList()
        for key, value in schedules:
            try:
                param = value.split(",")
                if param[0].strip().lower() in ('active', 'paused'):
                    self.Schedule[key] = {
                        'active': param[0],
                        'repeatType': param[1],
                        'repeatValue': param[2],
                        'timeType': param[3],
                        'timeValue': param[4],
                        'shutterAction': param[5],
                        'shutterIds': param[6]
                    }
            except Exception as e1:
                self.LogErrorLine(
                    "Missing config file or config file entries in Section Scheduler for key "
                    + key + ": " + str(e1))
                return False

        return True

    #---------------------MyConfig::setLocation---------------------------------
    def setLocation(self, lat, lng):
        self.WriteValue("Latitude", lat, section="General")
        self.WriteValue("Longitude", lng, section="General")
        self.Latitude = lat
        self.Longitude = lng

    #---------------------MyConfig::setCode---------------------------------
    def setCode(self, shutterId, code):
        self.WriteValue(shutterId, str(code), section="ShutterRollingCodes")
        self.Shutters[shutterId]['code'] = code

    #---------------------MyConfig::HasOption-----------------------------------
    def HasOption(self, Entry):

        return self.config.has_option(self.Section, Entry)

    #---------------------MyConfig::GetList-------------------------------------
    def GetList(self):

        return self.config.items(self.Section)

    #---------------------MyConfig::GetSections---------------------------------
    def GetSections(self):

        return self.config.sections()

    #---------------------MyConfig::SetSection----------------------------------
    def SetSection(self, section):

        # if not (isinstance(section, str) or isinstance(section, unicode)) or not len(section):
        if not len(section):
            self.LogError("Error in MyConfig:ReadValue: invalid section: " +
                          str(section))
            return False
        self.Section = section
        return True

    #---------------------MyConfig::ReadValue-----------------------------------
    def ReadValue(self,
                  Entry,
                  return_type=str,
                  default=None,
                  section=None,
                  NoLog=False):

        try:

            if section != None:
                self.SetSection(section)

            if self.config.has_option(self.Section, Entry):
                if return_type == str:
                    return self.config.get(self.Section, Entry)
                elif return_type == bool:
                    return self.config.getboolean(self.Section, Entry)
                elif return_type == float:
                    return self.config.getfloat(self.Section, Entry)
                elif return_type == int:
                    return self.config.getint(self.Section, Entry)
                else:
                    self.LogErrorLine(
                        "Error in MyConfig:ReadValue: invalid type:" +
                        str(return_type))
                    return default
            else:
                return default
        except Exception as e1:
            if not NoLog:
                self.LogErrorLine("Error in MyConfig:ReadValue: " + Entry +
                                  ": " + str(e1))
            return default

    #---------------------MyConfig::WriteSection--------------------------------
    def WriteSection(self, SectionName):

        SectionList = self.GetSections()

        if SectionName in SectionList:
            self.LogError("Error in WriteSection: Section already exist.")
            return True
        try:
            with self.CriticalLock:
                with open(self.FileName, "a") as ConfigFile:
                    ConfigFile.write("[" + SectionName + "]")
                    ConfigFile.flush()
                    ConfigFile.close()
                    # update the read data that is cached
                    self.config.read(self.FileName)
            return True
        except Exception as e1:
            self.LogErrorLine("Error in WriteSection: " + str(e1))
            return False

    #---------------------MyConfig::WriteValue----------------------------------
    def WriteValue(self, Entry, Value, remove=False, section=None):

        if section != None:
            self.SetSection(section)

        SectionFound = False
        try:
            with self.CriticalLock:
                Found = False
                ConfigFile = open(self.FileName, 'r')
                FileList = ConfigFile.read().splitlines()
                ConfigFile.close()

                mySectionStart = -1
                mySectionEnd = -1
                myLine = -1
                currentLastDataLine = -1
                for i, line in enumerate(FileList):
                    if self.LineIsSection(line) and self.Section.lower(
                    ) == self.GetSectionName(line).lower():
                        mySectionStart = i
                    elif mySectionStart >= 0 and mySectionEnd == -1 and len(
                            line.strip().split('=')) >= 2 and (
                                line.strip().split('='))[0].strip() == Entry:
                        myLine = i
                    elif mySectionStart >= 0 and mySectionEnd == -1 and self.LineIsSection(
                            line):
                        mySectionEnd = currentLastDataLine

                    if not line.isspace() and not len(
                            line.strip()) == 0 and not line.strip()[0] == "#":
                        currentLastDataLine = i
                if mySectionStart >= 0 and mySectionEnd == -1:
                    mySectionEnd = currentLastDataLine

                self.LogDebug("CONFIG FILE WRITE ->> mySectionStart = " +
                              str(mySectionStart) + ", mySectionEnd = " +
                              str(mySectionEnd) + ", myLine = " + str(myLine))
                if mySectionStart == -1:
                    raise Exception("NOT ABLE TO FIND SECTION:" + self.Section)

                ConfigFile = open(self.FileName, 'w')
                for i, line in enumerate(FileList):
                    if myLine >= 0 and myLine == i and not remove:  # I found my line, now write new value
                        ConfigFile.write(Entry + " = " + Value + "\n")
                    elif myLine == -1 and mySectionEnd == i:  # Here we have to insert the new record...
                        ConfigFile.write(line + "\n")
                        ConfigFile.write(Entry + " = " + Value + "\n")
                    else:  # Nothing special, just copy the previous line....
                        ConfigFile.write(line + "\n")

                ConfigFile.flush()
                ConfigFile.close()
                # update the read data that is cached
                self.config.read(self.FileName)
            return True

        except Exception as e1:
            self.LogError("Error in WriteValue: " + str(e1))
            return False

    #---------------------MyConfig::GetSectionName------------------------------
    def GetSectionName(self, Line):

        Line = Line.strip()
        if Line.startswith("[") and Line.endswith("]") and len(Line) >= 3:
            Line = Line.replace("[", "")
            Line = Line.replace("]", "")
            return Line
        return ""

    #---------------------MyConfig::LineIsSection-------------------------------
    def LineIsSection(self, Line):

        Line = Line.strip()
        if Line.startswith("[") and Line.endswith("]") and len(Line) >= 3:
            return True
        return False
Beispiel #57
0
    def __init__(self,
                 log,
                 newinstall=False,
                 simulation=False,
                 simulationfile=None,
                 message=None,
                 feedback=None,
                 ConfigFilePath=None):
        super(GeneratorController, self).__init__()
        self.log = log
        self.NewInstall = newinstall
        self.Simulation = simulation
        self.SimulationFile = simulationfile
        self.FeedbackPipe = feedback
        self.MessagePipe = message
        if ConfigFilePath == None:
            self.ConfigFilePath = "/etc/"
        else:
            self.ConfigFilePath = ConfigFilePath
        self.Address = None
        self.SerialPort = "/dev/serial0"
        self.BaudRate = 9600
        self.InitComplete = False
        self.Registers = {}  # dict for registers and values
        self.NotChanged = 0  # stats for registers
        self.Changed = 0  # stats for registers
        self.TotalChanged = 0.0  # ratio of changed ragisters
        self.EnableDebug = False  # Used for enabeling debugging
        self.OutageLog = os.path.dirname(
            os.path.dirname(os.path.realpath(__file__))) + "/outage.txt"
        self.PowerLogMaxSize = 15  # 15 MB max size
        self.PowerLog = os.path.dirname(
            os.path.dirname(os.path.realpath(__file__))) + "/kwlog.txt"
        self.TileList = []  # Tile list for GUI

        if self.Simulation:
            self.LogLocation = "./"
        else:
            self.LogLocation = "/var/log/"
        self.DisableOutageCheck = False
        self.bDisplayUnknownSensors = False
        self.UtilityVoltsMin = 0  # Minimum reported utility voltage above threshold
        self.UtilityVoltsMax = 0  # Maximum reported utility voltage above pickup
        self.SystemInOutage = False  # Flag to signal utility power is out
        self.TransferActive = False  # Flag to signal transfer switch is allowing gen supply power
        self.SiteName = "Home"
        # The values "Unknown" are checked to validate conf file items are found
        self.FuelType = "Unknown"
        self.NominalFreq = "Unknown"
        self.NominalRPM = "Unknown"
        self.NominalKW = "Unknown"
        self.Model = "Unknown"

        self.CommAccessLock = threading.RLock(
        )  # lock to synchronize access to the protocol comms
        self.ProgramStartTime = datetime.datetime.now()  # used for com metrics
        self.OutageStartTime = self.ProgramStartTime  # if these two are the same, no outage has occured
        self.LastOutageDuration = self.OutageStartTime - self.OutageStartTime

        # Read conf entries common to all controllers
        ConfigSection = "GenMon"
        try:
            # read config file
            config = RawConfigParser()
            # config parser reads from current directory, when running form a cron tab this is
            # not defined so we specify the full path
            config.read(self.ConfigFilePath + 'genmon.conf')

            # getfloat() raises an exception if the value is not a float
            # getint() and getboolean() also do this for their respective types
            if config.has_option(ConfigSection, 'sitename'):
                self.SiteName = config.get(ConfigSection, 'sitename')

            if config.has_option(ConfigSection, 'port'):
                self.SerialPort = config.get(ConfigSection, 'port')

            if config.has_option(ConfigSection, 'loglocation'):
                self.LogLocation = config.get(ConfigSection, 'loglocation')

            # optional config parameters, by default the software will attempt to auto-detect the controller
            # this setting will override the auto detect
            if config.has_option(ConfigSection, 'disableoutagecheck'):
                self.DisableOutageCheck = config.getboolean(
                    ConfigSection, 'disableoutagecheck')

            if config.has_option(ConfigSection, 'enabledebug'):
                self.EnableDebug = config.getboolean(ConfigSection,
                                                     'enabledebug')

            if config.has_option(ConfigSection, 'displayunknown'):
                self.bDisplayUnknownSensors = config.getboolean(
                    ConfigSection, 'displayunknown')
            if config.has_option(ConfigSection, 'outagelog'):
                self.OutageLog = config.get(ConfigSection, 'outagelog')

            if config.has_option(ConfigSection, 'kwlog'):
                self.PowerLog = config.get(ConfigSection, 'kwlog')
            if config.has_option(ConfigSection, 'kwlogmax'):
                self.PowerLogMaxSize = config.getint(ConfigSection, 'kwlogmax')

            if config.has_option(ConfigSection, 'nominalfrequency'):
                self.NominalFreq = config.get(ConfigSection,
                                              'nominalfrequency')
            if config.has_option(ConfigSection, 'nominalRPM'):
                self.NominalRPM = config.get(ConfigSection, 'nominalRPM')
            if config.has_option(ConfigSection, 'nominalKW'):
                self.NominalKW = config.get(ConfigSection, 'nominalKW')
            if config.has_option(ConfigSection, 'model'):
                self.Model = config.get(ConfigSection, 'model')

            if config.has_option(ConfigSection, 'fueltype'):
                self.FuelType = config.get(ConfigSection, 'fueltype')

        except Exception as e1:
            if not reload:
                self.FatalError(
                    "Missing config file or config file entries: " + str(e1))
            else:
                self.LogErrorLine("Error reloading config file" + str(e1))
Beispiel #58
0
        "--emevoucher_chain",
        dest="emevoucher_chain",
        help="Certificate chain to include in EME voucher signatures")
    parser.add_option("-v",
                      action="store_const",
                      dest="loglevel",
                      const=logging.DEBUG)

    options, args = parser.parse_args()

    if options.configfile:
        config = RawConfigParser()
        config.read(options.configfile)
        for option, value in config.items('signscript'):
            if option == "signcode_timestamp":
                value = config.getboolean('signscript', option)
            options.ensure_value(option, value)

    # Reset to default if this wasn't set in the config file
    if options.signcode_timestamp is None:
        options.signcode_timestamp = True

    logging.basicConfig(level=options.loglevel,
                        format="%(asctime)s - %(message)s")

    if len(args) != 4:
        parser.error("Incorrect number of arguments")

    format_, inputfile, destfile, filename = args

    tmpfile = destfile + ".tmp"
Beispiel #59
0
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

config = RawConfigParser()
config.read(os.path.join(BASE_DIR, 'settings.ini'))

########## Версия сайта #####
CONF = 'dev' if os.environ.get('DEVELOP_MODE') else 'prod'
# Доступные варианты:
#   prod
#   dev
#############################

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '3*ht_i78=^ydrz-3hv75ub30i3ip^*v+iu4vjo%bd=cicw)egs'

DEBUG = config.getboolean(CONF, 'DEBUG')
TEMPLATE_DEBUG = DEBUG

ALLOWED_HOSTS = ['*']

INTERNAL_IPS = ('127.0.0.1', )

# email setting

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '******'
EMAIL_HOST_PASSWORD = '******'
DEFAULT_FROM_EMAIL = '*****@*****.**'