Esempio n. 1
0
def reset():
    global bin_paths
    global config
    global configs_found

    bin_paths = {}

    config = ConfigParser.ConfigParser()
    configs_found = config.read(config_files)
    if not configs_found:
        print ('WARNING: pyTivo.conf does not exist.\n' +
               'Assuming default values.')
        configs_found = config_files[-1:]

    for section in config.sections():
        if section.startswith('_tivo_'):
            tsn = section[6:]
            if tsn.upper() not in ['SD', 'HD']:
                if config.has_option(section, 'name'):
                    tivo_names[tsn] = config.get(section, 'name')
                else:
                    tivo_names[tsn] = tsn
                if config.has_option(section, 'address'):
                    tivos[tsn] = config.get(section, 'address')

    for section in ['Server', '_tivo_SD', '_tivo_HD']:
        if not config.has_section(section):
            config.add_section(section)
Esempio n. 2
0
 def parse_config(self, arguments=None):
     finalconfig = {}
     args = self.parser.parse_args(arguments)
     config = configparser.SafeConfigParser()
     try:
         with open(args.config) as fdconfig:
             config.readfp(fdconfig) 
     except Exception as e:
         msg = "Ignoring configuration file '%s'"
         self.logger.warn(msg % (args.config))
         for section in self.PARAMETERS.keys():
             config.add_section(section)
     else:
         self.logger.info("Read configuration file '%s'" % args.config)
     for section in self.PARAMETERS.keys():
         cfgsection = dict(config.items(section))
         for var, required in self.PARAMETERS[section].iteritems():
             try:
                 # build env variables like IRONIC_URL
                 envparameter = section.upper() + '_' + var.upper()
                 cfgsection[var] = os.environ[envparameter]
                 msg = "Reading env variable '%s'" % envparameter
                 self.logger.debug(msg)
             except:
                 pass
             if required and not var in cfgsection:
                 msg = "Variable '%s.%s' not defined and it is required!" 
                 msg = msg % (section, var)
                 self.logger.error(msg)
                 raise ValueError(msg)
         finalconfig[section] = cfgsection
     self.args = args
     return finalconfig
Esempio n. 3
0
def dict2config(jdict, section):
    config = ConfigParser()
    if not config.has_section(section):
        config.add_section(section)
    for (k, v) in viewitems(jdict):
        config.set(section, k, str(v))
    return config
Esempio n. 4
0
def reset():
    global bin_paths
    global config
    global configs_found
    global tivos_found

    bin_paths = {}

    config = ConfigParser.ConfigParser()
    configs_found = config.read(config_files)
    if not configs_found:
        print ('WARNING: pyTivo.conf does not exist.\n' +
               'Assuming default values.')
        configs_found = config_files[-1:]

    for section in config.sections():
        if section.startswith('_tivo_'):
            tsn = section[6:]
            if tsn.upper() not in ['SD', 'HD', '4K']:
                tivos_found = True
                tivos[tsn] = Bdict(config.items(section))

    for section in ['Server', '_tivo_SD', '_tivo_HD', '_tivo_4K']:
        if not config.has_section(section):
            config.add_section(section)
Esempio n. 5
0
def reset():
    global bin_paths
    global config
    global configs_found

    bin_paths = {}

    config = ConfigParser.ConfigParser()
    configs_found = config.read(config_files)
    if not configs_found:
        print ('WARNING: pyTivo.conf does not exist.\n' +
               'Assuming default values.')
        configs_found = config_files[-1:]

    for section in config.sections():
        if section.startswith('_tivo_'):
            tsn = section[6:]
            if tsn.upper() not in ['SD', 'HD']:
                if config.has_option(section, 'name'):
                    tivo_names[tsn] = config.get(section, 'name')
                else:
                    tivo_names[tsn] = tsn
                if config.has_option(section, 'address'):
                    tivos[tsn] = config.get(section, 'address')

    for section in ['Server', '_tivo_SD', '_tivo_HD']:
        if not config.has_section(section):
            config.add_section(section)
def main():
    # process configuration file (if exists) and setup logging
    config = SafeConfigParser(cfg_defaults)
    config.add_section('common')
    for key, value in cfg_defaults.items(): config.set('common', key, str(value))
    if config.read(cfg_filename):
        logging.config.fileConfig(cfg_filename)
    else:
        logging.basicConfig(stream=sys.stdout, level=cfg_defaults['logLevel'], format=cfg_defaults['logFormat'])

    # process command line arguments
    parser = OptionParser(version='{0} {1}'.format(__description__, __version__), description=__description__)
    parser.add_option('-b', '--brokerUrl', dest='brokerUrl', metavar='URL', type='string',
                      default=config.get('common', 'brokerUrl'), help='context broker URL [default=%default]'),
    parser.add_option('-l', '--logLevel', dest='logLevel', metavar='LEVEL',
                      choices=[level for level in logging._levelNames.keys() if isinstance(level, str)],
                      default=config.get('common', 'logLevel'), help='logging level [default=%default]')
    (opts, args) = parser.parse_args()  # @UnusedVariable
    config.set('common', 'brokerUrl', opts.brokerUrl)
    config.set('common', 'logLevel', opts.logLevel)
    logging.root.setLevel(opts.logLevel)

    # rpc connection
    connection = rpc.create_connection()
    try:
        logging.info('Context Broker URL: %s', config.get('common', 'brokerUrl'))
        listen(connection, config)
    finally:
        connection.close()
    return 0
Esempio n. 7
0
def dict2config(jdict, section):
    config = ConfigParser.ConfigParser()
    if not config.has_section(section):
        config.add_section(section)
    for k,v in jdict.iteritems():
        config.set(section, k, str(v))
    return config
Esempio n. 8
0
def reset():
    global bin_paths
    global config
    global configs_found

    bin_paths = {}

    config = ConfigParser.ConfigParser()
    configs_found = config.read(config_files)
    if not configs_found:
        print ("WARNING: pyTivo.conf does not exist.\n" + "Assuming default values.")
        configs_found = config_files[-1:]

    for section in config.sections():
        if section.startswith("_tivo_"):
            tsn = section[6:]
            if tsn.upper() not in ["SD", "HD"]:
                if config.has_option(section, "name"):
                    tivo_names[tsn] = config.get(section, "name")
                else:
                    tivo_names[tsn] = tsn
                if config.has_option(section, "address"):
                    tivos[tsn] = config.get(section, "address")

    for section in ["Server", "_tivo_SD", "_tivo_HD"]:
        if not config.has_section(section):
            config.add_section(section)
Esempio n. 9
0
def dict2config(jdict, section):
    config = ConfigParser()
    if not config.has_section(section):
        config.add_section(section)
    for (k, v) in viewitems(jdict):
        config.set(section, k, str(v))
    return config
Esempio n. 10
0
def reset():
    global bin_paths
    global config
    global configs_found
    global tivos_found

    bin_paths = {}

    config = ConfigParser.ConfigParser()
    configs_found = config.read(config_files)
    if not configs_found:
        print('WARNING: pyTivo.conf does not exist.\n' +
              'Assuming default values.')
        configs_found = config_files[-1:]

    for section in config.sections():
        if section.startswith('_tivo_'):
            tsn = section[6:]
            if tsn.upper() not in ['SD', 'HD', '4K']:
                tivos_found = True
                tivos[tsn] = Bdict(config.items(section))

    for section in ['Server', '_tivo_SD', '_tivo_HD', '_tivo_4K']:
        if not config.has_section(section):
            config.add_section(section)
Esempio n. 11
0
def dict2config(jdict, section):
    config = ConfigParser.ConfigParser()
    if not config.has_section(section):
        config.add_section(section)
    for k, v in jdict.iteritems():
        config.set(section, k, str(v))
    return config
Esempio n. 12
0
File: config.py Progetto: ktbs/ktbs
def get_service_configuration(configfile_handler=None):
    """I set rdfrest Service default configuration options and possibly
    override them with the values extracted from a configuration file.

    :param configfile_handler: optional handler of a configuration file

    :return: Configuration object.
    """
    # When allow_no_value=True is passed, options without values return None
    # The value must be used as flags i.e
    # [rdf_database]
    # repository
    # and not :
    # repository =
    # which will return an empty string whatever 'allow_no_value' value is set
    config = SafeConfigParser(allow_no_value=True)

    # Setting default values
    config.add_section("server")
    config.set("server", "host-name", "localhost")
    config.set("server", "port", "8001")
    config.set("server", "base-path", "")
    config.set("server", "force-ipv4", "false")
    config.set("server", "max-bytes", "-1")
    config.set("server", "no-cache", "false")
    config.set("server", "flash-allow", "false")
    config.set("server", "max-triples", "-1")
    config.set("server", "cors-allow-origin", "")
    config.set("server", "resource-cache", "false")

    config.add_section("ns_prefix")

    # A future specification section "httpd" or "wsgi"
    # may be needed for HttpFrontend
    # config.add_section('httpd')

    config.add_section("plugins")
    config.set("plugins", "post_via_get", "false")

    # TODO : optional plugin specific configuration
    # config.add_section('post_via_get')

    config.add_section("rdf_database")
    config.set("rdf_database", "repository", "")
    config.set("rdf_database", "force-init", "false")

    config.add_section("logging")
    config.set("logging", "loggers", "")
    config.set("logging", "console-level", "INFO")
    # No filename implies no logging to file
    config.set("logging", "filename", "")
    config.set("logging", "file-level", "INFO")
    config.set("logging", "json-configuration-filename", "logging.json")

    # Loading from config file
    if configfile_handler is not None:
        config.readfp(configfile_handler)

    return config
Esempio n. 13
0
def get_service_configuration(configfile_handler=None):
    """I set rdfrest Service default configuration options and possibly
    override them with the values extracted from a configuration file.

    :param configfile_handler: optional handler of a configuration file

    :return: Configuration object.
    """
    # When allow_no_value=True is passed, options without values return None
    # The value must be used as flags i.e
    # [rdf_database]
    # repository
    # and not :
    # repository =
    # which will return an empty string whatever 'allow_no_value' value is set
    config = SafeConfigParser(allow_no_value=True)

    # Setting default values
    config.add_section('server')
    config.set('server', 'host-name', 'localhost')
    config.set('server', 'port', '8001')
    config.set('server', 'base-path', '')
    config.set('server', 'force-ipv4', 'false')
    config.set('server', 'max-bytes', '-1')
    config.set('server', 'no-cache', 'false')
    config.set('server', 'flash-allow', 'false')
    config.set('server', 'max-triples', '-1')
    config.set('server', 'cors-allow-origin', '')
    config.set('server', 'resource-cache', 'false')

    config.add_section('ns_prefix')

    # A future specification section "httpd" or "wsgi"
    # may be needed for HttpFrontend
    #config.add_section('httpd')

    config.add_section('plugins')
    config.set('plugins', 'post_via_get', 'false')

    # TODO : optional plugin specific configuration
    #config.add_section('post_via_get')

    config.add_section('rdf_database')
    config.set('rdf_database', 'repository', '')
    config.set('rdf_database', 'force-init', 'false')

    config.add_section('logging')
    config.set('logging', 'loggers', '')
    config.set('logging', 'console-level', 'INFO')
    # No filename implies no logging to file
    config.set('logging', 'filename', '')
    config.set('logging', 'file-level', 'INFO')
    config.set('logging', 'json-configuration-filename', 'logging.json')

    # Loading from config file
    if configfile_handler is not None:
        config.readfp(configfile_handler)

    return config
Esempio n. 14
0
def get_url(config, target):
    try:
        return config.get('gist-sync', 'url')
    except six.moves.configparser.NoSectionError:
        logger.debug('no section: create gist: %s', target)
        config.add_section('gist-sync')
    except six.moves.configparser.NoOptionError:
        logger.debug('no option: create gist: %s', target)
Esempio n. 15
0
 def set(config, section, option, value):
     if value is not None:
         if section not in config:
             config.add_section(section)
         config[section][option] = value
     elif section in config and option in config[section]:
         del config[section][option]
         if not config[section]:
             del config[section]
Esempio n. 16
0
def get_commit_hash(config, target):
    try:
        return config.get('gist-sync', 'commit').strip()
    except six.moves.configparser.NoSectionError:
        logger.debug('no section: commit: %s', target)
        config.add_section('gist-sync')
    except six.moves.configparser.NoOptionError:
        logger.debug('no option: commit: %s', target)
    return None
Esempio n. 17
0
def getConfiguration(cfgfile=None, config_required={'Main': {'key1': 'value1', 'key2': 'value2'}}):
    '''
    read an ini configuration file and return a dictionary of key/value pairs
    update configuration file if missing any sections
    accepts: 
        cfgfile - path to configuration file
        config_required - nested dictionary in the following format:
        {'Section1':
            {'key1': 'value1', 'key2': 'value2'},
            
         'Section 2':
            {'key1': 'value1'}
        }
    '''
    if not cfgfile:
        raise ValueError('no configuration file specified')
    # required configuraiton options
    # Section: {'option': 'default value'}
    logger = logging.getLogger(__name__)
    logger.debug('getting configuration from file: {}'.format(cfgfile))
    cfgpath = os.path.dirname(cfgfile)
#     config_required = {
#         'Main': {'credentials': os.path.join(cfgpath, 'credentials/'), 
#                  },
#         }

    config = configuration.get_config(cfgfile)

    update_config = False

    logger.debug('checking sections')
    for section, values in list(config_required.items()):
        if not config.has_section(section):
            logger.warning('section: {} not found in {}'.format(section, cfgfile))
            logger.debug('adding section {}'.format(section))
            config.add_section(section)
            update_config = True
        for option, value in list(values.items()):
            if not config.has_option(section, option):
                logger.warning('option: {} not found in {}'.format(option, cfgfile))
                logger.debug('adding option {}: {}'.format(option, value))

                config.set(section, option, value)
                update_config = True


    # for section, options in config_required.items():

    if update_config:
        try:
            logger.debug('updating configuration file at: {}'.format(cfgfile))
            configuration.create_config(cfgfile, config)
        except Exception as e:
            logger.error(e)
            
    return(config)
Esempio n. 18
0
def get_title(config, target, files):
    title = None
    try:
        title = config.get('gist-sync', 'title').strip()
    except six.moves.configparser.NoSectionError:
        logger.debug('no section: title: %s', target)
        config.add_section('gist-sync')
    except six.moves.configparser.NoOptionError:
        logger.debug('no option: title: %s', target)
    return title or get_title_from_files(files)
Esempio n. 19
0
 def create_default_configuration(cls, default_profile_url):
     """ensure a default profile is configured."""
     config_directory = cls._ensure_configuration_directory()
     config = ConfigParser()
     config.add_section('default')
     config.set('default', 'repository', default_profile_url)
     with open(os.path.join(config_directory, 'profiles'),
               'w') as profiles_file:
         config.write(profiles_file)
     return cls()
Esempio n. 20
0
    def test_invalid_config_file(self):
        config = ConfigParser()
        config.add_section("telegram-bot")
        config.add_section("allowed-users")

        app = self.application_module.Application(self.config, self.opts)

        app.config = config

        self.assertRaises(self.application_module.InvalidConfigurationException, app.load_configuration, self.opts.to)
Esempio n. 21
0
File: config.py Progetto: ktbs/ktbs
def get_service_configuration(configfile_handler=None):
    """I set rdfrest Service default configuration options and possibly
    override them with the values extracted from a configuration file.

    :param configfile_handler: optional handler of a configuration file

    :return: Configuration object.
    """
    # When allow_no_value=True is passed, options without values return None
    # The value must be used as flags i.e
    # [rdf_database]
    # repository
    # and not :
    # repository =
    # which will return an empty string whatever 'allow_no_value' value is set
    config = SafeConfigParser(allow_no_value=True)

    # Setting default values
    config.add_section('server')
    config.set('server', 'host-name', 'localhost')
    config.set('server', 'port', '8001')
    config.set('server', 'threads', '2')
    config.set('server', 'base-path', '')
    config.set('server', 'force-ipv4', 'false')
    config.set('server', 'max-bytes', '-1')
    config.set('server', 'flash-allow', 'false')
    config.set('server', 'max-triples', '-1')
    config.set('server', 'cors-allow-origin', '')
    config.set('server', 'reset-connection', 'false')
    config.set('server', 'send-traceback', 'false')

    config.add_section('ns_prefix')

    # A future specification section "httpd" or "wsgi"
    # may be needed for HttpFrontend
    #config.add_section('httpd')

    config.add_section('plugins')
    config.set('plugins', 'post_via_get', 'false')

    # TODO : optional plugin specific configuration
    #config.add_section('post_via_get')

    config.add_section('rdf_database')
    config.set('rdf_database', 'repository', '')
    config.set('rdf_database', 'force-init', 'false')

    config.add_section('logging')
    config.set('logging', 'loggers', '')

    # Loading from config file
    if configfile_handler is not None:
        config.readfp(configfile_handler)

    return config
Esempio n. 22
0
    def test_invalid_config_file(self):
        config = ConfigParser()
        config.add_section("telegram-bot")
        config.add_section("allowed-users")

        app = self.application_module.Application(self.config, self.opts)

        app.config = config

        self.assertRaises(
            self.application_module.InvalidConfigurationException,
            app.load_configuration, self.opts.to)
Esempio n. 23
0
    def _setup_system(self):
        config_dir = utils.Utils().get_app_dir()
        config_path = os.path.join(config_dir, '.guardiancl.ini')
        if not os.path.exists(config_path):
            config = configparser2.ConfigParser()
            config.add_section('ROUTES')
            config.set('ROUTES', 'auth', 'http://guardiaocloud.com.br/service/v1/authenticate')
            config.set('ROUTES', 'devices', 'http://guardiaocloud.com.br/service/v1/devices')
            config.set('ROUTES', 'collect', 'http://guardiaocloud.com.br/collect')

            with open(config_path, 'w') as configfile:
                config.write(configfile)
Esempio n. 24
0
def write_config(albumNum, trackNum):
    # Add content to the file
    config = ConfigParser.ConfigParser()
    config.add_section('cdc')
    config.set('cdc', 'album', albumNum)
    config.set('cdc', 'track', trackNum)

    # Create the configuration file as it doesn't exist yet
    with open(CONFIG, 'w') as file:
        config.write(file)

    logger.info('write config album: {}, track: {}'.format(albumNum, trackNum))
    return
Esempio n. 25
0
def write_config_to_filename(config_dictionary, config_filename):
    config = SafeConfigParser()
    for section in config_dictionary:
        config.add_section(section)
        variables = config_dictionary[section]
        for v in variables:
            config.set(section, v, variables[v])
    mode = stat.S_IRUSR | stat.S_IWUSR
    flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL
    fd = os.open(config_filename, flags, mode)
    f = os.fdopen(fd, 'wb')
    config.write(f)
    f.close()
Esempio n. 26
0
def get_cache_dir(config, target):
    cache_dir = None
    try:
        cache_dir = config.get('gist-sync', 'cache_dir').strip()
    except six.moves.configparser.NoSectionError:
        logger.debug('no section: title: %s', target)
        config.add_section('gist-sync')
    except six.moves.configparser.NoOptionError:
        logger.debug('no option: title: %s', target)
    if not cache_dir:
        cache_dir = '.gist-sync'
        config.set('gist-sync', 'cache_dir', cache_dir)
    return cache_dir
Esempio n. 27
0
def create_default_config():
    config = ConfigParser.ConfigParser()
    # set some defaults, which may be overwritten
    config.add_section('network')
    config.set('network', 'listen_host', '0.0.0.0')
    config.set('network', 'listen_port', '30303')
    config.set('network', 'num_peers', '5')
    config.set('network', 'remote_port', '30303')
    config.set('network', 'remote_host', '')
    config.set('network', 'client_id', Packeter.CLIENT_ID)
    config.set('network', 'node_id', sha3(str(uuid.uuid1())).encode('hex'))

    config.add_section('api')
    config.set('api', 'listen_host', '127.0.0.1')
    config.set('api', 'listen_port', '30203')

    config.add_section('misc')
    config.set('misc', 'verbosity', '1')
    config.set('misc', 'config_file', None)
    config.set('misc', 'logging', None)
    config.set('misc', 'data_dir', data_dir.path)
    config.set('misc', 'mining', '10')

    config.add_section('wallet')
    config.set('wallet', 'coinbase', '0' * 40)

    return config
Esempio n. 28
0
File: cdc.py Progetto: oritomov/cdc
def write_config(albumNum, trackNum):

	# Add content to the file
	config = ConfigParser.ConfigParser()
	config.add_section('cdc')
	config.set('cdc', 'album', albumNum)
	config.set('cdc', 'track', trackNum)

	# Create the configuration file as it doesn't exist yet
	with open(CONFIG, 'w') as file:
		config.write(file)

	logger.info('write config album: {}, track: {}'.format(albumNum, trackNum))
	return
Esempio n. 29
0
 def writeDefaultConfig(config):
     config.add_section('STORAGE')
     storageConfig                   = config['STORAGE']
     storageConfig['data_path']      = 'data/storage/'
     config.add_section('TASK_MANAGER')
     config.add_section('SERVER')
     config.add_section('SCHEDULER')
     config.add_section('LOGGING')
     loggingConfig                   = config['LOGGING']
     loggingConfig['file']           = CONFIG_PATH + '/logging.conf'
     if not os.path.exists(CONFIG_PATH):
         os.makedirs(CONFIG_PATH)
     with open(CONFIG_FILE,'w') as configFile:        
         config.write(configFile)
Esempio n. 30
0
    def setup(self):
        """ Call super(TESTNAME, self).setup() """
        self.kernel = MockKernel()

        self.kernel.services = {}
        try:
            config.add_section('Database')
        except:
            pass

        config.set('Database','connectionstring','sqlite://')

        if self.kernel.session == None:
            raise Exception("The test framework is broken")
Esempio n. 31
0
def create_default_config():
    config = ConfigParser.ConfigParser()
    # set some defaults, which may be overwritten
    config.add_section('network')
    config.set('network', 'listen_host', '0.0.0.0')
    config.set('network', 'listen_port', '30303')
    config.set('network', 'num_peers', '5')
    config.set('network', 'remote_port', '30303')
    config.set('network', 'remote_host', '')
    config.set('network', 'client_id', Packeter.CLIENT_ID)
    config.set('network', 'node_id', sha3(str(uuid.uuid1())).encode('hex'))

    config.add_section('api')
    config.set('api', 'listen_host', '127.0.0.1')
    config.set('api', 'listen_port', '30203')

    config.add_section('misc')
    config.set('misc', 'verbosity', '1')
    config.set('misc', 'config_file', None)
    config.set('misc', 'logging', None)
    config.set('misc', 'data_dir', data_dir.path)
    config.set('misc', 'mining', '10')

    config.add_section('wallet')
    config.set('wallet', 'coinbase', '0' * 40)

    return config
Esempio n. 32
0
def updateLogConfig(fileName, loggerName):
    try:
      config = openLogConfig(fileName)
      config.set('loggers', 'keys', config.get('loggers', 'keys')+','+loggerName)
      print 'new logger names:',config.get('loggers', 'keys')
      config.add_section('logger_'+loggerName)
      config.set('logger_'+loggerName, 'handlers', 'consoleHandler')
      config.set('logger_'+loggerName, 'propagate', '0')
      config.set('logger_'+loggerName, 'level', 'ERROR')
      config.set('logger_'+loggerName, 'qualname', loggerName)
      configfile = open(fileName, 'wb')
      config.write(configfile)
    except:
      pass
Esempio n. 33
0
    def _setup_system(self):
        config_dir = utils.Utils().get_app_dir()
        config_path = os.path.join(config_dir, '.guardiancl.ini')
        if not os.path.exists(config_path):
            config = configparser2.ConfigParser()
            config.add_section('ROUTES')
            config.set('ROUTES', 'auth',
                       'http://guardiaocloud.com.br/service/v1/authenticate')
            config.set('ROUTES', 'devices',
                       'http://guardiaocloud.com.br/service/v1/devices')
            config.set('ROUTES', 'collect',
                       'http://guardiaocloud.com.br/collect')

            with open(config_path, 'w') as configfile:
                config.write(configfile)
def user_update(username):
    if not config: raise ValueError('Configuration not loaded')
    if not config.has_section('users'):
        config.add_section('users')
    if config.has_option('users', username):
        print 'Changing password for %s' % username
    else:
        print 'Adding new user %s' % username
    password = getpass.getpass('Password: '******' * Updating OFTG-Ninja config ...'
        return True
    else:
        print ' * Failed to update user'
        return False
Esempio n. 35
0
    def write_config(self, filename):
        # Ecrit les config de toutes les sections dans un autre fichier
        """

        :param filename:
        """
        LOG.info("Writing .ini file (%s)" % filename)
        config = SafeConfigParser(allow_no_value=True)
        iniout = open(filename, mode="w")
        for section in self._sections:
            config.add_section(section)
            if hasattr(self, section):
                for opt in getattr(self, section).config:
                    config.set(section, str(opt),
                               str(getattr(self, section).config.get(opt)))
        config.write(iniout)
Esempio n. 36
0
def load_config(config, path):
    """Loads the config from file or creates a new one if that file is
    missing."""
    if not path.is_file():
        config.add_section("window")
        config.set("window", "xsize", "1200")
        config.set("window", "ysize", "700")
        config.set("window", "xpos", "200")
        config.set("window", "ypos", "200")
        config.add_section("io")
        config.set("io", "xydir", str(CONFDIR / "xy_temp/"))
        config.set("io", "project_file", "None")
        config.set("io", "project_dir", os.environ["HOME"])
        config.set("io", "data_dir", os.environ["HOME"])
        config.set("io", "export_dir", os.environ["HOME"])
        with open(str(path), "w") as cfg_file:
            config.write(cfg_file)
    else:
        config.read(str(path))
Esempio n. 37
0
def getConfiguration(cfgfile):
    # required configuraiton options
    # Section: {'option': 'default value'}
    logger = logging.getLogger(__name__)
    logger.debug('getting configuration from file: {}'.format(cfgfile))
    cfgpath = os.path.dirname(cfgfile)
    config_required = {
        'Main': {
            'credentials': os.path.join(cfgpath, 'credentials/'),
        },
    }

    config = configuration.get_config(cfgfile)

    update_config = False

    logger.debug('checking sections')
    for section, values in list(config_required.items()):
        if not config.has_section(section):
            logger.warning('section: {} not found in {}'.format(
                section, cfgfile))
            logger.debug('adding section {}'.format(section))
            config.add_section(section)
            update_config = True
        for option, value in list(values.items()):
            if not config.has_option(section, option):
                logger.warning('option: {} not found in {}'.format(
                    option, cfgfile))
                logger.debug('adding option {}: {}'.format(option, value))

                config.set(section, option, value)
                update_config = True

    # for section, options in config_required.items():

    if update_config:
        try:
            logger.debug('updating configuration file at: {}'.format(cfgfile))
            configuration.create_config(cfgfile, config)
        except Exception as e:
            logger.error(e)

    return (config)
Esempio n. 38
0
def updateLogConfig(fileName, loggerName):
    config = openLogConfig(fileName)
    try:
        config.set('loggers', 'keys',
                   config.get('loggers', 'keys') + ',' + loggerName)
        #print 'new logger names:',config.get('loggers', 'keys')
        config.add_section('logger_' + loggerName)
        config.set('logger_' + loggerName, 'handlers', 'consoleHandler')
        config.set('logger_' + loggerName, 'propagate', '0')
        config.set('logger_' + loggerName, 'level', 'ERROR')
        config.set('logger_' + loggerName, 'qualname', loggerName)
        configfile = open(fileName, 'wb')
        config.write(configfile)
    except:
        configfile = open(fileName, 'wb')
        try:
            config.add_section('loggers')
        except:
            pass
        config.set('loggers', 'keys', '')
        config.write(configfile)
Esempio n. 39
0
    def write_report_details(self):

        phy_topology = self._get_phy_topology_detail()

        details_h = open(self.report_details_file, 'w')
        config = ConfigParser.ConfigParser()
        config.add_section('Test')
        config.set('Test', 'Build', self.build_id)
        config.set('Test', 'timestamp', self.ts)
        config.set('Test', 'Report', self.html_log_link)
        config.set('Test', 'LogsLocation', self.log_link)
        config.set('Test', 'Topology', phy_topology)
        config.write(details_h)

        log_location = ''
        if self.jenkins_trigger:
            log_location = "nodeb10.englab.juniper.net:/cs-shared/test_runs" \
                "/%s/%s" % (self.host_data[self.cfgm_ips[0]]['name'], self.ts) 
            config.set('Test', 'CoreLocation', log_location)

        details_h.close()
Esempio n. 40
0
    def __parse_config_file(file = None):
        """
        Parse the configuration file

        :param file: Configuration file to parse
        :type file: String
        """


        config = ConfigParser.ConfigParser()
        if file is not None:
            # If config file, load Logger config
            Config._log = logging
            logging.config.fileConfig(file)
            config.readfp(open(file))
        else:
            # Set defaults
            config.add_section("app:main")
            config.set("app:main","db_uri","mongodb://localhost")
            config.set("app:main","db_name","mobyle")

        Config._config = config
Esempio n. 41
0
    def setting(self):
        """Setting up config file

        :return: config object
        """
        home_path = os.path.dirname(
            os.path.dirname(os.path.realpath('__file__')))
        s3_path = 's3://' + self.project_name
        user = '******'
        password = '******'
        redshift_path = 'postgresql://' + user + ':' + password + \
                        '@automl-instance.cbfploinlvqm.us-east-1.redshift.amazonaws.com:5439/' + self.database_name

        config = configparser.ConfigParser()
        config.add_section('PATH')
        config.set('PATH', 'home_path', home_path)
        config.set('PATH', 'model_path', os.path.join(home_path, 'model'))
        config.set('PATH', 'preprocess_path',
                   os.path.join(home_path, 'preprocess'))
        config.set('PATH', 'log_path', os.path.join(home_path, 'log-database'))
        config.set('PATH', 's3_path', s3_path)
        config.set('PATH', 'redshift_path', redshift_path)
        return config
Esempio n. 42
0
def main():
    locale.setlocale(locale.LC_ALL, '')
    args = command_args()
    config = ConfigParser(interpolation=ExtendedInterpolation(),
                          default_section="defaults")
    config.add_section("paths")
    config["paths"] = { "pkgdir": PKG_DIR }
    config.read("badumtss.conf")

    probe_input_drivers(config)

    loop = asyncio.get_event_loop()
    try:
        loop.add_signal_handler(signal.SIGINT, loop.stop)
        loop.add_signal_handler(signal.SIGTERM, loop.stop)

        player = player_factory(config, loop, section=args.player)
        if not player:
            logger.error("No MIDI player available.")
            if not args.keymap_wizard:
                return

        input_devices = list(input_devices_generator(config,
                                                     loop,
                                                     section=args.input_device))
        player.start()
        try:
            if args.keymap_wizard:
                keymap_wizard(args, loop, input_devices, player)
            else:
                play_input(args, loop, input_devices, player)
        finally:
            for input_device in input_devices:
                input_device.stop()
            player.stop()
    finally:
        loop.close()
Esempio n. 43
0
def reset():
    global bin_paths
    global config
    global configs_found
    global tivos_found

    bin_paths = {}

    config = ConfigParser.ConfigParser()
    configs_found = config.read(config_files)
    if not configs_found:
        print ("WARNING: pyTivo.conf does not exist.\n" + "Assuming default values.")
        configs_found = config_files[-1:]

    for section in config.sections():
        if section.startswith("_tivo_"):
            tsn = section[6:]
            if tsn.upper() not in ["SD", "HD", "4K"]:
                tivos_found = True
                tivos[tsn] = Bdict(config.items(section))

    for section in ["Server", "_tivo_SD", "_tivo_HD", "_tivo_4K"]:
        if not config.has_section(section):
            config.add_section(section)
Esempio n. 44
0
def create_config(path):
    """
    Create a config file
    :param path: path to file
    :return: None
    """
    config = configparser.ConfigParser()
    config.add_section("CSV_file")
    config.set("CSV_file", "Working", "True")
    config.set("CSV_file", "file name", "output.log")
    config.add_section("sieve_interval")
    config.set("sieve_interval", "sieve_interval", "100000")
    config.add_section("over_smooth")
    config.set("over_smooth", "over_smooth", "20")
    config.add_section("numbers")
    config.set("numbers", "numbers", "")

    with open(path, "w") as config_file:
        config.write(config_file)
Esempio n. 45
0
 def writeConfig(self):
     '''
     This function creates / saves log settings to a file.
     '''
     config = ConfigParser.ConfigParser()
     config.add_section('loggers')
     config.set('loggers', 'keys', 'root')
     
     config.add_section('formatters')
     config.set('formatters', 'keys', 'basic,nix')
     
     config.add_section('handlers')
     config.set('handlers', 'keys', 'consoleHandler,syslogHandler')
     
     config.add_section('logger_root')
     config.set('logger_root', 'level', 'DEBUG')
     config.set('logger_root', 'handlers', 'consoleHandler,syslogHandler')
     
     config.add_section('handler_consoleHandler')
     config.set('handler_consoleHandler', 'class', 'StreamHandler')
     config.set('handler_consoleHandler', 'level', 'NOTSET')
     config.set('handler_consoleHandler', 'formatter', 'basic')
     config.set('handler_consoleHandler', 'args', '(sys.stdout,)')
     
     config.add_section('handler_syslogHandler')
     config.set('handler_syslogHandler', 'class', 'handlers.SysLogHandler')
     config.set('handler_syslogHandler', 'level', 'NOTSET')
     config.set('handler_syslogHandler', 'formatter', 'nix')
     config.set('handler_syslogHandler', 'args', "(('/dev/log'), handlers.SysLogHandler.LOG_USER)")
     
     config.add_section('formatter_basic')
     config.set('formatter_basic', 'format', '%(asctime)s freeseer: <%(levelname)s> %(message)s')
     config.set('formatter_basic', 'datefmt', '%Y-%m-%d %H:%M:%S')
     
     config.add_section('formatter_nix')
     config.set('formatter_nix', 'format', 'freeseer: <%(levelname)s> %(message)s')
     
     # Save default settings to new config file
     with open(self.logconf, 'w') as configfile:
         config.write(configfile)
Esempio n. 46
0
def create_config():

    config = ConfigParser.ConfigParser()
    # set some defaults, which may be overwritten
    config.add_section('network')
    config.set('network', 'listen_host', 'localhost')
    config.set('network', 'listen_port', '30303')
    config.set('network', 'num_peers', '5')
    config.set('network', 'remote_port', '30303')
    config.set('network', 'remote_host', '')
    config.set('network', 'client_id', 'Ethereum(py)/0.0.1')

    config.add_section('misc')
    config.set('misc', 'verbosity', '1')
    config.set('misc', 'config_file', None)
    config.set('misc', 'logging', None)

    config.add_section('wallet')

    # NODE_ID == pubkey, needed in order to work with Ethereum(++)
    config.set(
        'wallet', 'pub_key',
        'J\x02U\xfaFs\xfa\xa3\x0f\xc5\xab\xfd<U\x0b\xfd\xbc\r<\x97=5'
        '\xf7&F:\xf8\x1cT\xa02\x81\xcf\xff"\xc5\xf5\x96[8\xacc\x01R'
        '\x98wW\xa3\x17\x82G\x85I\xc3o|\x84\xcbD6\xbay\xd6\xd9')

    usage = "usage: %prog [options]"
    parser = OptionParser(usage=usage, version="%prog 0.1a")
    parser.add_option("-l",
                      "--listen",
                      dest="listen_port",
                      default=config.get('network', 'listen_port'),
                      help="<port>  Listen on the given port for incoming"
                      " connected (default: 30303).")
    parser.add_option("-r",
                      "--remote",
                      dest="remote_host",
                      help="<host> Connect to remote host"
                      " (try: 54.201.28.117 or 54.204.10.41)")
    parser.add_option("-p",
                      "--port",
                      dest="remote_port",
                      default=config.get('network', 'remote_port'),
                      help="<port> Connect to remote port (default: 30303)")
    parser.add_option(
        "-v",
        "--verbose",
        dest="verbosity",
        default=config.get('misc', 'verbosity'),
        help="<0 - 3>  Set the log verbosity from 0 to 3 (default: 1)")
    parser.add_option(
        "-L",
        "--logging",
        dest="logging",
        default=config.get('misc', 'logging'),
        help="<logger1:LEVEL,logger2:LEVEL> set the console log level for"
        " logger1, logger2, etc. Empty loggername means root-logger,"
        " e.g. 'pyethereum.wire:DEBUG,:INFO'. Overrides '-v'")
    parser.add_option(
        "-x",
        "--peers",
        dest="num_peers",
        default=config.get('network', 'num_peers'),
        help="<number> Attempt to connect to given number of peers"
        "(default: 5)")
    parser.add_option("-C",
                      "--config",
                      dest="config_file",
                      help="read coniguration")

    (options, args) = parser.parse_args()

    # set network options
    for attr in ('listen_port', 'remote_host', 'remote_port', 'num_peers'):
        config.set('network', attr,
                   getattr(options, attr) or config.get('network', attr))
    # set misc options
    for attr in ('verbosity', 'config_file'):
        config.set('misc', attr,
                   getattr(options, attr) or config.get('misc', attr))

    if len(args) != 0:
        parser.error("wrong number of arguments")
        sys.exit(1)

    if config.get('misc', 'config_file'):
        config.read(config.get('misc', 'config_file'))

    # configure logging
    loggerlevels = getattr(options, 'logging') or ''
    configure_logging(loggerlevels,
                      verbosity=config.getint('misc', 'verbosity'))

    return config
Esempio n. 47
0
 def writeDefaultConfig(config):
     config.add_section('STORAGE')
     storageConfig                   = config['STORAGE']
     storageConfig['data_path']      = 'data/storage/'
     config.add_section('SCHEDULER')
     config.add_section('TASK_MANAGER')
     config.add_section('INTERFACE')
     config.add_section('CONTRACTOR')
     config.add_section('ENTITY_MANAGER')
     interfaceConfig                 = config['INTERFACE']
     interfaceConfig['xmlrpc_server_addr'] = 'localhost'
     interfaceConfig['xmlrpc_server_port'] = '8000' 
     config.add_section('LOGGING')
     loggingConfig                   = config['LOGGING']
     loggingConfig['file']           = CONFIG_PATH + '/logging.conf'
     
     if not os.path.exists(CONFIG_PATH):
         os.makedirs(CONFIG_PATH)        
     
     with open(CONFIG_FILE,'w') as configFile:        
         config.write(configFile)
def main():
    formatterStr = '%(asctime)s %(module)s:%(lineno)d [%(levelname)s]:%(message)s'
    logging.basicConfig(level=logging.DEBUG,
                        format=formatterStr)
    logger = logging.getLogger()

    config = configparser.RawConfigParser()

    config.add_section('Section1')
    config.set('Section1', 'an_int', '15')
    config.set('Section1', 'a_bool', 'true')
    config.set('Section1', 'a_float', '3.1415')
    config.set('Section1', 'baz', 'fun')
    config.set('Section1', 'bar', 'Python')
    config.set('Section1', 'foo', '%(bar)s is %(baz)s!')

    with io.open('example.cfg', 'w') as configfile:
        config.write(configfile)

    config1 = configparser.RawConfigParser()
    config1.read('example.cfg')

    logger.info("config1{")
    a_float = config1.getfloat('Section1', 'a_float')
    an_int = config1.getint('Section1', 'an_int')
    logger.info(a_float + an_int)

    if config1.getboolean('Section1', 'a_bool'):
        logger.info(config1.get('Section1', 'foo'))

    logger.info("}")

    logger.info("config2{")
    config2 = configparser.ConfigParser()
    config2.read('example.cfg')

    logger.info(config2.get('Section1', 'foo', 0))
    logger.info(config2.get('Section1', 'foo', 1))

    logger.info(config2.get('Section1', 'foo', 0, {'bar': 'Documentation',
                                                   'baz': 'evil'}))
    logger.info("}")
    logger.info("config3{")
    config3 = configparser.SafeConfigParser({'bar': 'Life', 'baz': 'hard'})
    config3.read('example.cfg')

    logger.info(config3.get('Section1', 'foo'))
    config3.remove_option('Section1', 'bar')
    config3.remove_option('Section1', 'baz')
    logger.info(config3.get('Section1', 'foo'))
    logger.info("}")

    logger.info("config4{")
    sample_config = """
    [mysqld]
    user = mysql
    pid-file = /var/run/mysqld/mysqld.pid
    skip-external-locking
    old_passwords = 1
    skip-bdb
    skip-innodb
    """
    config4 = configparser.RawConfigParser(allow_no_value=True)
    config4.readfp(io.BytesIO(sample_config))

    # Settings with values are treated as before:
    config4.get("mysqld", "user")

    # Settings without values provide None:
    config4.get("mysqld", "skip-bdb")

    # Settings which aren't specified still raise an error:
    config4.get("mysqld", "does-not-exist")
    logger.info("}")
Esempio n. 49
0
def main():
    """Entry point."""

    # 1. Configure

    logconfig = None
    options, overrides, srcpkg_path = parse_cmdline()

    config = ConfigParser()
    if os.path.exists(options.config):
        config.read(options.config)
        if not config.has_section(DERBUILD_SECTION):
            config.add_section(DERBUILD_SECTION)
        try:
            logconfig = config.get(DERBUILD_SECTION, LOGCONFIG_OPT,
                                   vars=overrides)
        except NoOptionError:
            if config.has_section("loggers"):
                logconfig = options.config
    else:
        config.add_section(DERBUILD_SECTION)

    # Initialize logging:
    # 1. try to find settings for logging
    #   * in the command line option '--log-config' first,
    #   * then in option 'logconfig' in the section [derbuild] of
    #     derbuild's config file,
    #   * then in derbuild's config file itself
    # 2. if logging settings have been found then load them
    # 3. otherwise initialize logging with standard basic settings.
    if logconfig:
        logging.config.fileConfig(logconfig, disable_existing_loggers=False)
        if options.debug:
            rootlogger = logging.getLogger()
            rootlogger.setLevel(logging.DEBUG)
    else:
        if options.debug:
            logging.basicConfig(level=logging.DEBUG)
        else:
            logging.basicConfig(level=logging.WARNING)
    LOG.debug("logging initialized")

    options = get_effective_options(options, overrides, config)

    # 2. Set up

    # prepare working directory
    if os.path.exists(options.workdir):
        LOG.error("working directory '%s' exists already. Exiting..." %
                  options.workdir)
        sys.exit(1)
    os.makedirs(options.workdir)

    # prepare output directory
    if not os.path.isdir(options.outdir):
        os.makedirs(options.outdir)

    env = BuildEnvironment(options.arch, options.rootdir, options.envvars,
                           options.binds)
    env.setup(options.rootstrap, options.overdir)

    pkg = get_package(options.type, srcpkg_path, options.workdir, env)

    # 3. Build

    pkg.unpack()
    pkg.build()
    pkg.get_artifacts(options.outdir)

    # 4. Clean up

    env.destroy()
    LOG.debug("removing the working directory '%s'" % options.workdir)
    shutil.rmtree(options.workdir)
def main(argv=None):  # IGNORE:C0111
    '''Command line options.'''

    if argv is None:
        argv = sys.argv
    else:
        sys.argv.extend(argv)

    program_name = os.path.basename(sys.argv[0])
    program_version = "v%s" % __version__
    program_build_date = str(__updated__)
    program_version_message = '%%(prog)s %s (%s)' % (program_version,
                                                     program_build_date)
    program_shortdesc = __import__('__main__').__doc__.split("\n")[1]
    program_license = '''%s

  Copyright 2017 Neul Ltd. All rights reserved.

  Distributed on an "AS IS" basis without warranties
  or conditions of any kind, either express or implied.

USAGE
''' % program_shortdesc

    print("%s %s (%s)" %
          (__programname__, program_version, program_build_date))

    default_config_files = [
        os.path.join(os.path.dirname(os.path.realpath(__file__)),
                     __programname__ + ".cfg"),
        os.path.join(os.path.expanduser("~"), "." + __programname__ + ".cfg")
    ]
    CONFIG_SECTION = __programname__

    try:
        # Setup argument parser
        argparser = ArgumentParser(description=program_license,
                                   formatter_class=RawDescriptionHelpFormatter)

        # generic commands
        argparser.add_argument("-V",
                               "--version",
                               action='version',
                               version=program_version_message)

        # generic options
        argparser.add_argument("-c",
                               "--config",
                               dest="config",
                               metavar="FILE",
                               default=None,
                               help="Configuration file.")
        argparser.add_argument(
            "-v",
            "--verbose",
            dest="verbose",
            action="count",
            help="set verbosity level [default: %(default)s]")

        # specific options
        argparser.add_argument("-ksid",
                               "--keystoreid",
                               dest="keystoreid",
                               default=None,
                               action="append",
                               help="keystore 0 (SiVendor) or 1 (Customer)")
        argparser.add_argument("-cert1",
                               "--certificate1",
                               dest="certificate1",
                               default=None,
                               action="append",
                               help="X509 Public Key Certificate (DER)")
        argparser.add_argument("-cert2",
                               "--certificate2",
                               dest="certificate2",
                               default=None,
                               action="append",
                               help="X509 Public Key Certificate (DER)")
        argparser.add_argument("-cert3",
                               "--certificate3",
                               dest="certificate3",
                               default=None,
                               action="append",
                               help="X509 Public Key Certificate (DER)")
        argparser.add_argument("-cert4",
                               "--certificate4",
                               dest="certificate4",
                               default=None,
                               action="append",
                               help="X509 Public Key Certificate (DER)")
        argparser.add_argument("-use1",
                               "--use1",
                               dest="use1",
                               default=None,
                               help="Keystore Key use")
        argparser.add_argument("-use2",
                               "--use2",
                               dest="use2",
                               default=None,
                               help="Keystore Key use")
        argparser.add_argument("-use3",
                               "--use3",
                               dest="use3",
                               default=None,
                               help="Keystore Key use")
        argparser.add_argument("-use4",
                               "--use4",
                               dest="use4",
                               default=None,
                               help="Keystore Key use")
        argparser.add_argument("-iks",
                               "--inputkeystore",
                               dest="input_keystore",
                               default=None,
                               help="Keystore File")

        # Actions
        argparser.add_argument("-createkeystore",
                               "--createkeystore",
                               dest="createkeystore",
                               action="store_true",
                               default=False,
                               help="Create a Keystore")
        argparser.add_argument("-printkeystore",
                               "--printkeystore",
                               dest="printkeystore",
                               action="store_true",
                               default=False,
                               help="Print Keystore (takes no arguements)")

        # Process arguments
        commandline_options = vars(argparser.parse_args())

        logging_configured = False

        cfg_defaults = {
            # Command line options defaults
            'verbose': 0,
            'certificate1': None,
            'certificate2': None,
            'certificate3': None,
            'certificate4': None,
            'use1': None,
            'use2': None,
            'use3': None,
            'use4': None,
        }

        # Make sure all our options are strings.
        config_defaults = {}
        for k, v in cfg_defaults.items():
            if v != None:
                config_defaults[k] = str(v)
            else:
                config_defaults[k] = None

        config = ConfigParser.SafeConfigParser(config_defaults)

        if commandline_options['config']:
            configfile = os.path.abspath(commandline_options['config'])
            if configfile in config.read(configfile):
                try:
                    logging.config.fileConfig(configfile)
                    logging_configured = True
                except NoSectionError:
                    pass

            if not config.has_section(CONFIG_SECTION):
                config.add_section(CONFIG_SECTION)
        else:
            # Try loading defaults if no command line options given.
            for configfile in default_config_files:
                if configfile in config.read(configfile):
                    try:
                        logging.config.fileConfig(configfile)
                        logging_configured = True
                    except NoSectionError:
                        pass
                    break
        # Add section if we don't have one
        if not config.has_section(CONFIG_SECTION):
            config.add_section(CONFIG_SECTION)

        # Override settings with settings from command line.
        for k, v in commandline_options.items():
            if v != None:
                if isinstance(v, list):
                    config.set(CONFIG_SECTION, k, "|".join(v))
                else:
                    config.set(CONFIG_SECTION, k, str(v))

        # We should now have a config option parser with everything set...
        # If we are verbose when add logging to std
        verbose = config.get(CONFIG_SECTION, 'verbose')
        if verbose and verbose != "0":
            console_handler = logging.StreamHandler(sys.stdout)
            console_handler.setLevel(
                logging.CRITICAL
            )  # set later by set_log_level_from_verbose() in interactive sessions
            console_handler.setFormatter(
                logging.Formatter('%(asctime)s: %(levelname)s: %(message)s'))

            loglevel = logging.DEBUG
            if verbose == '1':
                loglevel = logging.ERROR
            if verbose == '2':
                loglevel = logging.WARNING
            elif verbose == '3':
                loglevel = logging.INFO

            console_handler.setLevel(loglevel)
            logging.root.addHandler(console_handler)

            if not logging_configured:
                logging.root.setLevel(loglevel)
            logging_configured = True

        if not logging_configured:
            logging.basicConfig(
                level=logging.CRITICAL,
                format="%(asctime)s: %(levelname)s: %(message)s",
                stream=sys.stderr)

        logging.debug("Logging configured")

        logging.info("%s %s (%s)" %
                     (__programname__, program_version, program_build_date))

        foundAction = False
        # -----------------------------------------------------------------------
        # Sign an image
        if commandline_options.get('createkeystore', None):
            foundAction = True
            logging.info("Create Keystore")

            # keystore id
            keystoreID = int(config.get(CONFIG_SECTION, 'keystoreid'))

            # load assets
            signerCertificateFilename = [
                config.get(CONFIG_SECTION, 'certificate1'),
                config.get(CONFIG_SECTION, 'certificate2'),
                config.get(CONFIG_SECTION, 'certificate3'),
                config.get(CONFIG_SECTION, 'certificate4')
            ]

            for cert in signerCertificateFilename:
                if cert is not None:
                    if os.path.isfile(cert) is not True:
                        logging.error("Certificate file does not exist.", cert)
                        print("Certificate file does not exist.", cert)
                        return -1

            signerCertificateUse = [
                config.get(CONFIG_SECTION, 'use1'),
                config.get(CONFIG_SECTION, 'use2'),
                config.get(CONFIG_SECTION, 'use3'),
                config.get(CONFIG_SECTION, 'use4')
            ]

            paramAdded = False
            for cert, use in zip(signerCertificateFilename,
                                 signerCertificateUse):
                if cert is not None and use is not None:
                    paramAdded = True

            if not paramAdded:
                logging.error("No certificate/use specified.")
                print("No certificate/use specified.")
                return -1

            # generate keystore
            keystore = []
            for certFile, certUse in zip(signerCertificateFilename,
                                         signerCertificateUse):
                if certFile is not None:
                    keystore.extend(
                        [createKeystoreKey(certFile, int(certUse))])

            # write to a fixed name for now
            cwd = os.getcwd()
            dir_path = os.path.dirname(os.path.realpath(__file__))
            keystore_name = 'keystore_' + str(keystoreID)
            outfile = os.path.join(cwd, keystore_name) + '.keystore'
            hashfile = os.path.join(cwd, keystore_name) + '.sha256'

            # logging.info("Writing file '%s'" % outfile)
            print("Writing file '%s'" % outfile)
            writeKeystore(outfile, keystoreID, keystore)
            # logging.info("Writing keystore hash file '%s'" % hashfile)
            print("Writing keystore hash file '%s'" % hashfile)
            generateKeystoreHashFile(outfile, hashfile)

        # -----------------------------------------------------------------------
        # Print Keystore
        if commandline_options.get('printkeystore', None):
            foundAction = True
            logging.info("Print Keystore")

            keystoreFilename = config.get(CONFIG_SECTION, 'input_keystore')
            if keystoreFilename is None:
                logging.error("Could not load keystore %s" % keystoreFilename)
                print("Could not load keystore %s" % keystoreFilename)
                return -1

            logging.info("Keystore: %s" % keystoreFilename)
            print("Keystore: %s" % keystoreFilename)

            keystore_id, loadedKeystore = readKeystore(keystoreFilename)
            printKeystore(keystore_id, loadedKeystore)

        # -----------------------------------------------------------------------

        if not foundAction:
            logging.error("No action specified.")
            print("No action specified.")
            return -1

        return 0

    except KeyboardInterrupt:
        ### handle keyboard interrupt ###
        return 0
    except Exception, e:
        indent = len(program_name) * " "
        sys.stderr.write(program_name + ": " + repr(e) + "\n")
        sys.stderr.write(indent + "  for help use --help")
        return 2
Esempio n. 51
0
def create_config():

    config = ConfigParser.ConfigParser()
    # set some defaults, which may be overwritten
    config.add_section('network')
    config.set('network', 'listen_host', 'localhost')
    config.set('network', 'listen_port', '30303')
    config.set('network', 'num_peers', '5')
    config.set('network', 'remote_port', '30303')
    config.set('network', 'remote_host', '')
    config.set('network', 'client_id', 'Ethereum(py)/0.0.1')

    config.add_section('misc')
    config.set('misc', 'verbosity', '1')
    config.set('misc', 'config_file', None)
    config.set('misc', 'logging', None)

    config.add_section('wallet')

    # NODE_ID == pubkey, needed in order to work with Ethereum(++)
    config.set('wallet', 'pub_key', 'J\x02U\xfaFs\xfa\xa3\x0f\xc5\xab\xfd<U\x0b\xfd\xbc\r<\x97=5\xf7&F:\xf8\x1cT\xa02\x81\xcf\xff"\xc5\xf5\x96[8\xacc\x01R\x98wW\xa3\x17\x82G\x85I\xc3o|\x84\xcbD6\xbay\xd6\xd9')

    usage = "usage: %prog [options]"
    parser = OptionParser(usage=usage,  version="%prog 0.1a")
    parser.add_option("-l", "--listen",
                      dest="listen_port",
                      default=config.get('network', 'listen_port'),
                      help="<port>  Listen on the given port for incoming connected (default: 30303)."
                      )
    parser.add_option("-r", "--remote",
                      dest="remote_host",
                      help="<host> Connect to remote host (try: 54.201.28.117 or 54.204.10.41)"
                      )
    parser.add_option("-p", "--port",
                      dest="remote_port",
                      default=config.get('network', 'remote_port'),
                      help="<port> Connect to remote port (default: 30303)"
                      )
    parser.add_option("-v", "--verbose",
                      dest="verbosity",
                      default=config.get('misc', 'verbosity'),
                      help="<0 - 3>  Set the log verbosity from 0 to 3 (default: 1)")
    parser.add_option("-L", "--logging",
                      dest="logging",
                      default=config.get('misc', 'logging'),
                      help="<logger1:LEVEL,logger2:LEVEL> set the console log level for logger1, logger2, etc.\
                            Empty loggername means root-logger, e.g. 'pyethereum.wire:DEBUG,:INFO'. Overrides '-v'")
    parser.add_option("-x", "--peers",
                      dest="num_peers",
                      default=config.get('network', 'num_peers'),
                      help="<number>  Attempt to connect to given number of peers (default: 5)")
    parser.add_option("-C", "--config",
                      dest="config_file",
                      help="read coniguration")

    (options, args) = parser.parse_args()

    # set network options
    for attr in ('listen_port', 'remote_host', 'remote_port', 'num_peers'):
        config.set('network', attr, getattr(
            options, attr) or config.get('network', attr))
    # set misc options
    for attr in ('verbosity', 'config_file'):
        config.set(
            'misc', attr, getattr(options, attr) or config.get('misc', attr))

    if len(args) != 0:
        parser.error("wrong number of arguments")
        sys.exit(1)

    if config.get('misc', 'config_file'):
        config.read(config.get('misc', 'config_file'))

    #configure logging
    loggerlevels = getattr(options, 'logging') or ''
    configure_logging(loggerlevels, verbosity=config.getint('misc', 'verbosity'))

    return config
Esempio n. 52
0
    def writeConfig(self):
        '''
        This function creates / saves log settings to a file.
        '''
        config = ConfigParser.ConfigParser()
        config.add_section('loggers')
        config.set('loggers', 'keys', 'root')

        config.add_section('formatters')
        config.set('formatters', 'keys', 'basic,nix')

        config.add_section('handlers')
        config.set('handlers', 'keys', 'consoleHandler,syslogHandler')

        config.add_section('logger_root')
        config.set('logger_root', 'level', 'DEBUG')
        config.set('logger_root', 'handlers', 'consoleHandler,syslogHandler')

        config.add_section('handler_consoleHandler')
        config.set('handler_consoleHandler', 'class', 'StreamHandler')
        config.set('handler_consoleHandler', 'level', 'NOTSET')
        config.set('handler_consoleHandler', 'formatter', 'basic')
        config.set('handler_consoleHandler', 'args', '(sys.stdout,)')

        config.add_section('handler_syslogHandler')
        config.set('handler_syslogHandler', 'class', 'handlers.SysLogHandler')
        config.set('handler_syslogHandler', 'level', 'NOTSET')
        config.set('handler_syslogHandler', 'formatter', 'nix')
        config.set('handler_syslogHandler', 'args',
                   "(('/dev/log'), handlers.SysLogHandler.LOG_USER)")

        config.add_section('formatter_basic')
        config.set('formatter_basic', 'format',
                   '%(asctime)s freeseer: <%(levelname)s> %(message)s')
        config.set('formatter_basic', 'datefmt', '%Y-%m-%d %H:%M:%S')

        config.add_section('formatter_nix')
        config.set('formatter_nix', 'format',
                   'freeseer: <%(levelname)s> %(message)s')

        # Save default settings to new config file
        with open(self.logconf, 'w') as configfile:
            config.write(configfile)
Esempio n. 53
0
def updateStatusIniFile():
    config = ConfigParser.RawConfigParser()
    config.add_section(STATUS_DATES_SECTION)
    config.set(STATUS_DATES_SECTION, START_DATE, eventDatetime)
    with open(STATUS_INI, 'wb') as configfile:
        config.write(configfile)
Esempio n. 54
0
def configureProxy(args, proxyConfigPath):
    '''
    Configure proxy configuration file from command line

    :param args: argparse arguments
    :param proxyConfigPath: Path to proxy.ini file
    :return: None
    '''

    config = ConfigParser.RawConfigParser()
    config.read(os.path.join(path, "proxy.ini"))

    # Configure UNITx sections
    unit = 'UNIT' + str(args.unit)
    if args.unit is not 0:
        try:
            config.add_section(unit)

        except ConfigParser.DuplicateSectionError:
            pass

    if args.callsign is not None:
        config.set(unit, 'CALLSIGN', args.callsign)
    if args.nodeid is not None:
        config.set(unit, 'NODEID', args.nodeid)
    if args.port is not None:
        config.set(unit, 'COM', args.port)
    if args.baudrate:
        config.set(unit, 'BAUDRATE', args.baudrate)
    if args.timeout:
        config.set(unit, 'TIMEOUT', args.timeout)

    # Configure Proxy section items
    if args.number is not 0:
        config.set('PROXY', 'units', args.number)
    if args.log:
        config.set('PROXY', 'log', 1)
    else:
        config.set('PROXY', 'log', 0)
    if args.testmode:
        config.set('PROXY', 'testmode', 1)
    else:
        config.set('PROXY', 'testmode', 0)
    if args.testcallsign is not None:
        config.set('PROXY', 'testcallsign', args.testcallsign)
    if args.testnodeid is not None:
        config.set('PROXY', 'testnodeid', args.testnodeid)
    if args.testrate:
        config.set('PROXY', 'testrate', args.testrate)

    #Configure Proxy databases
    if args.database is not None:
        config.set('DATABASE', 'filename', args.database)
    if args.schema is not None:
        config.set('DATABASE', 'schemaname', args.schema)
    if args.testdatabase is not None:
        config.set('TESTDATABASE', 'filename', args.testdatabase)

    # Configure Proxy flask server
    if args.flaskhost is not None:
        config.set('FLASK', 'host', args.flaskhost)
    if args.flaskport is not None:
        config.set('FLASK', 'port', args.flaskport)

    with open(proxyConfigPath, 'wb') as configfile:
        config.write(configfile)
Esempio n. 55
0
STATIC_DIR = os.path.join(PROJECT_DIR, 'static')

CONFIG_FILE = os.path.join(PROJECT_DIR, 'config', 'config.ini')
config = Config()
config.read(CONFIG_FILE)

DEBUG = config.get_boolean(APPLICATION_NAME, 'debug', False)
LOGIN_URL = config.get_option(APPLICATION_NAME, 'login_url', '/login/')
PORT = config.get_int(APPLICATION_NAME, 'port', 8000)

if config.has_option(APPLICATION_NAME, 'cookie_secret'):
    COOKIE_SECRET = config.get(APPLICATION_NAME, 'cookie_secret')
else:
    COOKIE_SECRET = base64.b64encode(uuid.uuid4().bytes + uuid.uuid4().bytes)
    if not config.has_section(APPLICATION_NAME):
        config.add_section(APPLICATION_NAME)
    config.set(APPLICATION_NAME, 'cookie_secret', COOKIE_SECRET)
    with open(CONFIG_FILE, 'wt') as cf:
        config.write(cf)

LOGGING_CONFIG = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'verbose': {
            'format': '%(asctime)s - %(name)s - %(levelname)s - %(module)s - %(process)d - %(thread)d - %(message)s',
            'datefmt': '%d/%m/%Y %Hh%Mm%Ss'
        },
        'simple': {
            'format': '%(asctime)s - %(name)-12s - %(levelname)-8s - %(message)s',
            'datefmt': '%d/%m/%Y %Hh%Mm%Ss'
Esempio n. 56
0
def main():
    InitConfig()
    config = GetConfig()
    config.add_section('DB')
    logging.config.fileConfig('logging.conf')
    for dbStem in DBs:
        config.set('DB','dbStem',dbStem)
        InitDB()
        db = GetDB()
        dbFile = db.GetDBFile()
        print '*** START : DB = %s ***' % (dbFile)
        print 'Records = %d' % (db.rowCount)
        tests = [
                     {
                      'desc' : 'Get count of all listings with a particular first name',
                      'N' : 1,
                      'spec' : {
                                'bus' : None,
                                'origin' : 0,
                                'destination' : 0,
                                'time' : 0,
                                },
                      },
                     {
                      'desc' : 'Get count of all listings with a particular first name and last name',
                      'N' : 1,
                      'spec' : {
                                'bus' : None,
                                'origin' : None,
                                'destination' : 0,
                                'time' : 0,
                                },
                      },
                     {
                      'desc' : 'Get count of all listings with a particular first name, last name, city, and state',
                      'N' : 1,
                      'spec' : {
                                'bus' : None,
                                'origin' : None,
                                'destination' : None,
                                'time' : None,
                                },
                      },
                     {
                      'desc' : 'Get count of all listings with a particular first name and excluding 50 last names',
                      'N' : 1,
                      'spec' : {
                                'bus' : None,
                                'origin' : 1,
                                'destination' : 0,
                                'time' : 0,
                                },
                      },
                     {
                      'desc' : 'Get count of all listings with a particular first name and excluding 50 last names, 50 cities, and 40 states',
                      'N' : 1,
                      'spec' : {
                                'bus' : None,
                                'origin' : 1,
                                'destination' : 1,
                                'time' : 1,
                                },
                      },
                     {
                      'desc' : 'Get count of all listings with a particular first name and excluding 1 last name, 1 city, and 1 state',
                      'N' : 1,
                      'spec' : {
                                'bus' : None,
                                'origin' : 1,
                                'destination' : 1,
                                'time' : 1,
                                },
                      },
                      ]
        for (i,test) in enumerate(tests):
            print '*** TEST %d : DB = %s ***' % (i,dbFile)
            print 'Description: %s' % (test['desc'])
            print 'Spec: %s' % (test['spec'])
            print 'N: %d' % (test['N'])
            (avRandTime,avQueryTime,longestQueryTime,avReturnedCallees) = db.RunTest(test['spec'],test['N'])
            print 'average randomTime = %f' % (avRandTime)
            print 'average queryTime = %f' % (avQueryTime)
            print 'longest queryTime = %f' % (longestQueryTime)
            print 'average returned callees = %f' % (avReturnedCallees)
            print ''
        KillDB()
Esempio n. 57
0
def main(args=None):
    """Entry point for the Numina CLI."""

    # Configuration args from a text file
    config = configparser.SafeConfigParser()

    # Building programatically
    config.add_section('numina')
    config.set('numina', 'format', 'yaml')

    # Custom values, site wide and local
    config.read(['.numina/numina.cfg',
                 os.path.join(xdg_config_home, 'numina/numina.cfg')])

    parser = argparse.ArgumentParser(
        description='Command line interface of Numina',
        prog='numina',
        epilog="For detailed help pass --help to a target"
        )

    parser.add_argument(
        '-l', action="store", dest="logging", metavar="FILE",
        help="FILE with logging configuration"
        )
    parser.add_argument(
        '-d', '--debug',
        action="store_true",
        dest="debug", default=False,
        help="make lots of noise"
        )

    subparsers = parser.add_subparsers(
        title='Targets',
        description='These are valid commands you can ask numina to do.'
        )

    # Init subcommands
    cmds = ['clishowins', 'clishowom', 'clishowrecip',
            'clirun', 'clirunrec']
    for cmd in cmds:
        cmd_mod = import_module('.'+cmd, 'numina.user')
        register = getattr(cmd_mod, 'register', None)
        if register is not None:
            register(subparsers)

    # Load plugin commands
    for entry in pkg_resources.iter_entry_points(group='numina_plugins'):
        reg_fun = entry.load()
        try:
            reg_fun(subparsers)
        except StandardError:
            # Error loading plugin
            pass

    args = parser.parse_args(args)

    # logger file
    if args.logging is not None:
        logging.config.fileConfig(args.logging)
    else:
        # This should be a default path in defaults.cfg
        try:
            args.logging = config.get('numina', 'logging')
            logging.config.fileConfig(args.logging)
        except configparser.Error:
            logging.config.dictConfig(numina_cli_logconf)

    _logger.info('Numina simple recipe runner version %s', __version__)

    args.command(args)
Esempio n. 58
0
def read_or_create_config_file(
        path_to_configfile: Path) -> configparser.ConfigParser:
    """
    Creates config file with default values
    or reads the current config file "config.ini".
    """
    config = configparser.ConfigParser(allow_no_value=True)
    config.optionxform = str
    if not path_to_configfile.is_file():
        config.add_section("Basics")
        config.set("Basics", "# Settings related to the playfield window")
        config.set("Basics", "columns", "10")
        config.set("Basics", "rows", "24")
        config.set("Basics", "fraction_of_vres", "30")
        config.set("Basics", "x_position", "26")
        config.set("Basics", "y_position", "3")
        config.set("Basics", "spawn_row", "3")
        config.set("Basics", "spawn_column", "4")
        config.add_section("Fonts")
        config.set("Fonts", "# Path to the fontfile")
        config.set("Fonts", "file", "fonts/codeman38_deluxefont/dlxfont.ttf")
        config.set("Fonts", "# Default font size")
        config.set("Fonts", "size_fraction_of_vres", "67.5")
        config.add_section("Game_window")
        config.set("Game_window", "# Game Window Title")
        config.set("Game_window", "title", "Pygtris")
        config.set("Game_window", "# Initial Game Window Position")
        config.set("Game_window", "horizontal", "0")
        config.set("Game_window", "vertical", "0")
        config.set("Game_window", "# Game Window Size")
        config.set("Game_window", "width", "1920")
        config.set("Game_window", "height", "1080")
        config.add_section("Technical")
        config.set("Technical", "# Framerate Limit")
        config.set("Technical", "framerate", "100")
        config.add_section("Graphics")
        config.set("Graphics", "folder", "img")
        config.set("Graphics", "empty_playfield_tile",
                   "opaque_playfield_tile.png")
        config.add_section("Colors")
        config.set(
            "Colors",
            "# Color values need to be separated by comma and space \", \"")
        config.set("Colors", "game_window_background_color", "18, 18, 18, 255")
        config.set("Colors", "game_window_foreground_color",
                   "245, 245, 245, 255")
        config.set("Colors", "font_color", "70, 70, 70, 255")
        with open(path_to_configfile, mode="w", encoding="utf-8") as configfh:
            config.write(configfh)
    config.read(path_to_configfile)
    return config
Esempio n. 59
0
def create_config():

    config = ConfigParser.ConfigParser()
    # set some defaults, which may be overwritten
    config.add_section('network')
    config.set('network', 'listen_host', '0.0.0.0')
    config.set('network', 'listen_port', '30303')
    config.set('network', 'num_peers', '5')
    config.set('network', 'remote_port', '30303')
    config.set('network', 'remote_host', '')
    config.set('network', 'client_id', Packeter.CLIENT_ID)
    config.set('network', 'node_id', sha3(str(uuid.uuid1())).encode('hex'))

    config.add_section('api')
    config.set('api', 'listen_host', '127.0.0.1')
    config.set('api', 'listen_port', '30203')

    config.add_section('misc')
    config.set('misc', 'verbosity', '1')
    config.set('misc', 'config_file', None)
    config.set('misc', 'logging', None)
    config.set('misc', 'data_dir', data_dir.path)
    config.set('misc', 'mining', '10')

    config.add_section('wallet')
    config.set('wallet', 'coinbase', '0' * 40)

    usage = "usage: %prog [options]"
    parser = OptionParser(usage=usage,  version=Packeter.CLIENT_ID)
    parser.add_option(
        "-l", "--listen",
        dest="listen_port",
        default=config.get('network', 'listen_port'),
        help="<port>  Listen on the given port for incoming"
        " connected (default: 30303).")
    parser.add_option(
        "-a", "--address",
        dest="coinbase",
        help="Set the coinbase (mining payout) address",
        default=config.get('wallet', 'coinbase'))
    parser.add_option(
        "-d", "--data_dir",
        dest="data_dir",
        help="<path>  Load database from path (default: %s)" % config.get(
            'misc', 'data_dir'),
        default=config.get('misc', 'data_dir'))
    parser.add_option(
        "-r", "--remote",
        dest="remote_host",
        help="<host> Connect to remote host"
        " (try: 54.201.28.117 or 54.204.10.41)")
    parser.add_option(
        "-p", "--port",
        dest="remote_port",
        default=config.get('network', 'remote_port'),
        help="<port> Connect to remote port (default: 30303)"
    )
    parser.add_option(
        "-v", "--verbose",
        dest="verbosity",
        default=config.get('misc', 'verbosity'),
        help="<0 - 3>  Set the log verbosity from 0 to 3 (default: 1)")
    parser.add_option(
        "-m", "--mining",
        dest="mining",
        default=config.get('misc', 'mining'),
        help="<0 - 100> Percent CPU used for mining 0==off (default: 10)")
    parser.add_option(
        "-L", "--logging",
        dest="logging",
        default=config.get('misc', 'logging'),
        help="<logger1:LEVEL,logger2:LEVEL> set the console log level for"
        " logger1, logger2, etc. Empty loggername means root-logger,"
        " e.g. 'pyethereum.wire:DEBUG,:INFO'. Overrides '-v'")
    parser.add_option(
        "-x", "--peers",
        dest="num_peers",
        default=config.get('network', 'num_peers'),
        help="<number> Attempt to connect to given number of peers"
        "(default: 5)")
    parser.add_option("-C", "--config",
                      dest="config_file",
                      help="read coniguration")

    (options, args) = parser.parse_args()

    # set network options
    for attr in ('listen_port', 'remote_host', 'remote_port', 'num_peers'):
        config.set('network', attr, getattr(
            options, attr) or config.get('network', attr))
    # set misc options
    for attr in ('verbosity', 'config_file', 'logging', 'data_dir', 'mining'):
        config.set(
            'misc', attr, getattr(options, attr) or config.get('misc', attr))

    # set wallet options
    for attr in ('coinbase',):
        config.set(
            'wallet', attr, getattr(options, attr) or config.get('wallet', attr))

    if len(args) != 0:
        parser.error("wrong number of arguments")
        sys.exit(1)

    if config.get('misc', 'config_file'):
        config.read(config.get('misc', 'config_file'))

    # set datadir
    if config.get('misc', 'data_dir'):
        data_dir.set(config.get('misc', 'data_dir'))

    # configure logging
    configure_logging(
        config.get('misc', 'logging') or '',
        verbosity=config.getint('misc', 'verbosity'))

    return config
            configfilename = os.path.abspath(args.config)
        else:
            configfilename = 'oftg.cfg'
        config.read(configfilename)
    except ConfigParser.Error as e:
        logger.error('Error reading configuration file: %s' % (e.message))
        quit()

    # Handle user account changes
    if args.user:
        user_update(args.user)
        quit()

    # Assure there are users configured
    if not config.has_section('users'):
        config.add_section('users')

    if len(config.items('users')) == 0:
        print 'To access OFTG-Ninja, you must first create a user...'
        username = str(raw_input('Username: '******'users')) == 0:
        quit(' ! No users defined in configuration')

    sys.path.append('classes/')

    # Process manager
    global manager