Example #1
0
def readIni(nb):
    global K, N, cut, gui, distrWE, distrNS, vehphWEA, vehphNSA, maxSumFlow, tlType, intergreenLength, GSum
    global phaseMinWE, phaseMaxWE, phaseMinNS, phaseMaxNS, maxGap, detPos
    filename = 'input' + str(nb).zfill(2) + '.ini'
    ini = ConfigParser()
    ini.read(filename)

    K = ini.getint("general", "K")
    N = ini.getint("general", "N")

    cut = ini.getboolean("general", "cut")

    gui = ini.getboolean("general", "gui")

    distrWE = ini.get("demand", "distrWE")
    distrNS = ini.get("demand", "distrNS")

    vehphWEA = eval(ini.get("demand", "vehphWEA"))
    vehphNSA = eval(ini.get("demand", "vehphNSA"))

    maxSumFlow = ini.getint("demand", "maxSumFlow")

    tlType = ini.get("TL", "tlType")

    intergreenLength = ini.getint("TL", "intergreenLength")
    GSum = ini.getfloat("TL", "GSum")

    [phaseMinWE, phaseMaxWE] = eval(ini.get("TL", "phaseMinMaxWE"))
    [phaseMinNS, phaseMaxNS] = eval(ini.get("TL", "phaseMinMaxNS"))
    maxGap = ini.getfloat("TL", "maxGap")
    detPos = ini.getfloat("TL", "detPos")

    return filename
Example #2
0
    def load_config(self):
        """
        Loads the vPoller Worker Manager configuration settings

        """
        logger.debug('Loading config file %s', self.config_file)

        parser = ConfigParser(self.config_defaults)
        parser.read(self.config_file)

        self.config['mgmt'] = parser.get('worker', 'mgmt')
        self.config['db'] = parser.get('worker', 'db')
        self.config['proxy'] = parser.get('worker', 'proxy')
        self.config['helpers'] = parser.get('worker', 'helpers')
        self.config['tasks'] = parser.get('worker', 'tasks')
        self.config['cache_enabled'] = parser.getboolean('cache', 'enabled')
        self.config['cache_maxsize'] = parser.getint('cache', 'maxsize')
        self.config['cache_ttl'] = parser.getint('cache', 'ttl')
        self.config['cache_housekeeping'] = parser.getint('cache', 'housekeeping')

        if self.config['helpers']:
            self.config['helpers'] = self.config['helpers'].split(',')

        if self.config['tasks']:
            self.config['tasks'] = self.config['tasks'].split(',')
        
        logger.debug(
            'Worker Manager configuration: %s',
            self.config
        )
Example #3
0
def load_arguments(file_name):
    """load arguments from arguments.conf"""
    arg = {}
    cf = ConfigParser()
    cf.read(file_name)

    arg["start_time"] = cf.getint("arguments", "start_time")
    arg["time_length"] = cf.getint("arguments", "time_length")
    arg["bandwidth"] = cf.getint("arguments", "bandwidth")
    arg["out_range"] = cf.getint("arguments", "out_range")
    arg["source"] = cf.get("arguments", "source")
    arg["input"] = cf.get("arguments", "input")
    arg["output"] = cf.get("arguments", "output")

    arg["all_recall"] = cf.getfloat("prediction", "all_recall")
    arg["all_precision"] = cf.getfloat("prediction", "all_precision")
    arg["text_recall"] = cf.getfloat("prediction", "text_recall")
    arg["text_precision"] = cf.getfloat("prediction", "text_precision")
    arg["image_recall"] = cf.getfloat("prediction", "image_recall")
    arg["image_precision"] = cf.getfloat("prediction", "image_precision")
    arg["app_recall"] = cf.getfloat("prediction", "app_recall")
    arg["app_precision"] = cf.getfloat("prediction", "video_precision")
    arg["video_recall"] = cf.getfloat("prediction", "video_recall")
    arg["video_precision"] = cf.getfloat("prediction", "all_precision")
    arg["audio_recall"] = cf.getfloat("prediction", "audio_recall")
    arg["audio_precision"] = cf.getfloat("prediction", "audio_precision")
    arg["other_recall"] = cf.getfloat("prediction", "other_recall")
    arg["other_precision"] = cf.getfloat("prediction", "other_precision")

    return arg
Example #4
0
 def read(self, f):
     '''Read the settings from the given file handle.'''
     cfg = ConfigParser()
     cfg.readfp(f)
     
     netSection = 'Network'
     if cfg.has_section(netSection):
         if cfg.has_option(netSection, 'defaultIpAddress'):
             self.defaultIpAddress = cfg.get(netSection, 'defaultIpAddress')
         if cfg.has_option(netSection, 'defaultPort'):
             self.defaultPort = cfg.getint(netSection, 'defaultPort')
         if cfg.has_option(netSection, 'ephemeralPortsFrom'):
             self.ephemeralPorts[0] = cfg.getint(netSection, 'ephemeralPortsFrom')
         if cfg.has_option(netSection, 'ephemeralPortsTo'):
             self.ephemeralPorts[1] = cfg.getint(netSection, 'ephemeralPortsTo')
                     
     tftpSection = 'TFTP'
     if cfg.has_section(tftpSection):
         if cfg.has_option(tftpSection, 'timeout'):
             self.tftpTimeout = cfg.getfloat(tftpSection, 'timeout')
         if cfg.has_option(tftpSection, 'retries'):
             self.tftpRetries = cfg.getint(tftpSection, 'retries')
                     
     serverSection = 'Server'
     if cfg.has_section(serverSection):
         if cfg.has_option(serverSection, 'defaultDirectory'):
             self.defaultDirectory = cfg.get(serverSection, 'defaultDirectory')
         if cfg.has_option(serverSection, 'saveLastUsed'):
             self.saveLastUsed = cfg.getboolean(serverSection, 'saveLastUsed')
    def __init__(self, conffile):
        Observable.__init__(self)
	cp = ConfigParser()
	cp.read(conffile)

	if not Globals.globSimulate:
	    wiringpi.wiringPiSetupGpio()

	self.md = MotorDriver([
		    cp.getint("MotorDriver", "LEFT_L"),
		    cp.getint("MotorDriver", "LEFT_R"),
		    cp.getint("MotorDriver", "RIGHT_L"),
		    cp.getint("MotorDriver", "RIGHT_R"),
		    cp.getint("MotorDriver", "VERTICAL_L"),
		    cp.getint("MotorDriver", "VERTICAL_R"),
		    ])
	self.md.start()

	self.ds = DistanceSensor(
		    cp.getint("DistanceSensor", "TRIGGER"),
		    cp.getint("DistanceSensor", "ECHO")
		    )
	self.ds.start()

	self.acl = AltitudeControlLoop(self.md, self.ds)

	self.update("MotorDriver", self.md)
	self.update("DistanceSensor", self.ds)
	self.update("AltitudeControlLoop", self.acl)

	self.md.subscribe(self.update)
	self.ds.subscribe(self.update)
	self.acl.subscribe(self.update)

	self.setCamera(False)
Example #6
0
    def load(file):
        config = ConfigParser()
        config.read(file)

        # MongoDB settings
        host = config.get('MongoDB', 'host')
        port = config.getint('MongoDB', 'port')

        # Regex settings
        google_analytics = config.get('Regex', 'google_analytics')
        google_adsense = config.get('Regex', 'google_adsense')

        # Procspy
        threads = config.getint('Procspy', 'threads')

        # RabbitMQ
        rabbit_queue = config.get('RabbitMQ', 'queue')

        if not host or not port or not google_analytics or not google_adsense or not threads:
            print 'Please, specify all required parameters in %s!' % file
            sys.exit(1)

        return {
            'host': host,
            'port': port,
            'google_analytics': google_analytics,
            'google_adsense': google_adsense,
            'threads': threads,
            'queue': rabbit_queue
        }
Example #7
0
def load_config(args=None):
    if args is None or isinstance(args, basestring):
        namespace = argparse.Namespace()
        if args is None:
            namespace.config = DEFAULT_CONFIG_FILE
        else:
            namespace.config = args
        args = namespace
    try:
        config = ConfigParser()
        config.read(args.config)
        args.ip = config.get('manager', 'ip')
        args.port = config.getint('manager', 'port')
        args.authkey = config.get('manager', 'authkey')
        args.batch_size = config.getint('manager', 'batch_size')
        args.columns = config.get('output', 'columns')

        args.uses_sqlite = config.getboolean('worker', 'uses_sqlite')
        args.processes = config.getint('worker', 'processes')
        args.nth = config.getint('worker', 'nth')
        args.distance = config.getint('worker', 'distance')

        args.dbpath = config.get('db', 'path')
        args.zip2ws_db = os.path.join(args.dbpath, config.get('db', 'zip2ws'))
    except Exception as e:
        logging.error(str(e))

    return args
Example #8
0
def parseOpts():
    global config
    argp = ArgumentParser(description='TorCheck')
    argp.add_argument('-c', nargs='?', default='torcheck.conf')
    f = vars(argp.parse_args())['c']

    # config parser with these defaults set
    confp = ConfigParser({
        # getint() method will convert to int
        'reachable_port': '80',
        'listen_port': '8000',
        'listen_address': '127.0.0.1',
        'export_filename': 'torbel_export.csv',
        'status_filename': 'torbel_export.status',
        'log_file': 'torbel.log',
        'use_forwarded_header': 'False',
        })
    confp.add_section('TorCheck')
    if f: confp.read(f) 
    config = dict()
    config['listen_port'] = confp.getint('TorCheck', 'listen_port')
    config['listen_address'] = confp.get('TorCheck', 'listen_address')
    config['reachable_port'] = confp.getint('TorCheck', 'reachable_port')
    config['export_filename'] = confp.get('TorCheck', 'export_filename')
    config['status_filename'] = confp.get('TorCheck', 'status_filename')
    config['log_file'] = confp.get('TorCheck', 'log_file')
    config['use_forwarded_header'] = confp.get('TorCheck', 'use_forwarded_header')
Example #9
0
	def __init__(self):
		defaults = getDefaults()
		config = ConfigParser()
		config.read(defaults)
		self.tapertype = config.get('signal', 'tapertype')
		self.taperwidth = config.getfloat('signal', 'taperwidth')
		self.maxiter = config.getint('iccs', 'maxiter')
		self.convepsi = config.getfloat('iccs', 'convepsi')
		self.convtype = config.get('iccs', 'convtype')
		self.stackwgt = config.get('iccs', 'stackwgt')
		self.srate = config.getfloat('iccs', 'srate')
		self.fstack = config.get('iccs', 'fstack')
		# SAC headers for time window, trace selection, and quality factors
		self.twhdrs = config.get('sachdrs', 'twhdrs').split()
		self.hdrsel = config.get('sachdrs', 'hdrsel')
		self.qfactors = config.get('sachdrs', 'qfactors').split()
		self.qheaders = config.get('sachdrs', 'qheaders').split()
		self.qweights = [ float(val)  for val in config.get('sachdrs', 'qweights').split() ] 
		# SAC headers for ICCS time picks
		self.ichdrs = config.get('sachdrs', 'ichdrs').split()
		# Choose a xcorr module and function
		self.shift = config.getint('iccs', 'shift')
		modu = config.get('iccs', 'xcorr_modu')
		func = config.get('iccs', 'xcorr_func')
		cmd = 'from %s import %s; xcorr=%s'	% (modu, func, func)
		exec cmd
		self.xcorr = xcorr
		self.xcorr_modu = modu
		self.xcorr_func = func
Example #10
0
	def __init__(self):
		config = ConfigParser()
		defaults = getDefaults()
		config.read(defaults)
		# SAC headers for time window, trace selection, and quality factors
		self.twhdrs = config.get('sachdrs', 'twhdrs').split()
		self.hdrsel = config.get('sachdrs', 'hdrsel')
		self.qfactors = config.get('sachdrs', 'qfactors').split()
		self.qheaders = config.get('sachdrs', 'qheaders').split()
		self.qweights = [ float(val)  for val in config.get('sachdrs', 'qweights').split() ] 
		# SAC plots
		self.figsize = [ float(val)  for val in config.get('sacplot', 'figsize').split() ]
		self.rectseis = [ float(val)  for val in config.get('sacplot', 'rectseis').split() ]
		self.colorwave = config.get('sacplot', 'colorwave')
		self.colorwavedel = config.get('sacplot', 'colorwavedel')
		self.colortwfill = config.get('sacplot', 'colortwfill')
		self.colortwsele = config.get('sacplot', 'colortwsele')
		self.alphatwfill = config.getfloat('sacplot', 'alphatwfill')
		self.alphatwsele = config.getfloat('sacplot', 'alphatwsele')
		self.npick = config.getint('sacplot', 'npick')
		self.pickcolors = config.get('sacplot', 'pickcolors')
		self.pickstyles = config.get('sacplot', 'pickstyles').split()
		self.minspan = config.getint('sacplot', 'minspan')
		self.srate = config.getfloat('sacplot', 'srate')
		self.tapertype = config.get('signal', 'tapertype')
		self.taperwidth = config.getfloat('signal', 'taperwidth')
def canCheckin(toCheckin):
	"""
	@returns: True if destination is not locked by another user
		AND this checkin will not overwrite a newer version
	"""
	chkoutInfo = ConfigParser()
	chkoutInfo.read(os.path.join(toCheckin, ".checkoutInfo"))
	chkInDest = chkoutInfo.get("Checkout", "checkedoutfrom")
	version = chkoutInfo.getint("Checkout", "version")
	lockedbyme = chkoutInfo.getboolean("Checkout", "lockedbyme")
	
	nodeInfo = ConfigParser()
	nodeInfo.read(os.path.join(chkInDest, ".nodeInfo"))
	locked = nodeInfo.getboolean("Versioning", "locked")
	latestVersion = nodeInfo.getint("Versioning", "latestversion")
	
	#TODO raise different exceptions to give override options to the user
	result = True
	if lockedbyme == False:
		if locked == True:
			result = False
		if version < latestVersion:
			result = False
	
	return result
Example #12
0
 def __init__(self):
     defaults = getDefaults()
     config = ConfigParser()
     config.read(defaults)
     # SAC headers for time window, trace selection, and quality factors
     self.twhdrs = config.get("sachdrs", "twhdrs").split()
     self.hdrsel = config.get("sachdrs", "hdrsel")
     self.qfactors = config.get("sachdrs", "qfactors").split()
     self.qheaders = config.get("sachdrs", "qheaders").split()
     self.qweights = [float(val) for val in config.get("sachdrs", "qweights").split()]
     # SAC headers for ICCS time picks
     self.ichdrs = config.get("sachdrs", "ichdrs").split()
     # plots
     self.colorwave = config.get("sacplot", "colorwave")
     self.colortwfill = config.get("sacplot", "colortwfill")
     self.colortwsele = config.get("sacplot", "colortwsele")
     self.alphatwfill = config.get("sacplot", "alphatwfill")
     self.alphatwsele = config.get("sacplot", "alphatwsele")
     self.npick = config.getint("sacplot", "npick")
     self.pickcolors = config.get("sacplot", "pickcolors")
     self.pickstyles = config.get("sacplot", "pickstyles").split()
     self.minspan = config.getint("sacplot", "minspan")
     self.fstack = config.get("iccs", "fstack")
     self.thresholds = [float(val) for val in config.get("sacplot", "thresholds").split()]
     self.colorthresholds = config.get("sacplot", "colorthresholds").split()
Example #13
0
 def __init__(self):
     config = ConfigParser()
     defaults = getDefaults()
     config.read(defaults)
     # SAC headers for time window, trace selection, and quality factors
     self.twhdrs = config.get("sachdrs", "twhdrs").split()
     self.hdrsel = config.get("sachdrs", "hdrsel")
     self.qfactors = config.get("sachdrs", "qfactors").split()
     self.qheaders = config.get("sachdrs", "qheaders").split()
     self.qweights = [float(val) for val in config.get("sachdrs", "qweights").split()]
     # SAC plots
     self.figsize = [float(val) for val in config.get("sacplot", "figsize").split()]
     self.rectseis = [float(val) for val in config.get("sacplot", "rectseis").split()]
     self.colorwave = config.get("sacplot", "colorwave")
     self.colorwavedel = config.get("sacplot", "colorwavedel")
     self.colortwfill = config.get("sacplot", "colortwfill")
     self.colortwsele = config.get("sacplot", "colortwsele")
     self.alphatwfill = config.getfloat("sacplot", "alphatwfill")
     self.alphatwsele = config.getfloat("sacplot", "alphatwsele")
     self.npick = config.getint("sacplot", "npick")
     self.pickcolors = config.get("sacplot", "pickcolors")
     self.pickstyles = config.get("sacplot", "pickstyles").split()
     self.minspan = config.getint("sacplot", "minspan")
     self.srate = config.getfloat("sacplot", "srate")
     self.tapertype = config.get("signal", "tapertype")
     self.taperwidth = config.getfloat("signal", "taperwidth")
     self.thresholds = [float(val) for val in config.get("sacplot", "thresholds").split()]
     self.colorthresholds = config.get("sacplot", "colorthresholds").split()
Example #14
0
 def __init__(self):
     defaults = getDefaults()
     config = ConfigParser()
     config.read(defaults)
     self.tapertype = config.get("signal", "tapertype")
     self.taperwidth = config.getfloat("signal", "taperwidth")
     self.maxiter = config.getint("iccs", "maxiter")
     self.convepsi = config.getfloat("iccs", "convepsi")
     self.convtype = config.get("iccs", "convtype")
     self.stackwgt = config.get("iccs", "stackwgt")
     self.srate = config.getfloat("iccs", "srate")
     self.fstack = config.get("iccs", "fstack")
     # SAC headers for time window, trace selection, and quality factors
     self.twhdrs = config.get("sachdrs", "twhdrs").split()
     self.hdrsel = config.get("sachdrs", "hdrsel")
     self.qfactors = config.get("sachdrs", "qfactors").split()
     self.qheaders = config.get("sachdrs", "qheaders").split()
     self.qweights = [float(val) for val in config.get("sachdrs", "qweights").split()]
     # SAC headers for ICCS time picks
     self.ichdrs = config.get("sachdrs", "ichdrs").split()
     # Choose a xcorr module and function
     self.shift = config.getint("iccs", "shift")
     modu = config.get("iccs", "xcorr_modu")
     func = config.get("iccs", "xcorr_func")
     cmd = "from %s import %s; xcorr=%s" % (modu, func, func)
     exec cmd
     self.xcorr = xcorr
     self.xcorr_modu = modu
     self.xcorr_func = func
Example #15
0
def init_settings(argv):
    """
    Populates SETTINGS with key-value pairs from configuration file.
    """
    conf = ConfigParser()
    conf.read(argv[1])
    SETTINGS['logfile'] = conf.get('crawl', 'logfile')
    SETTINGS['seeders'] = conf.get('crawl', 'seeders').strip().split("\n")
    SETTINGS['workers'] = conf.getint('crawl', 'workers')
    SETTINGS['debug'] = conf.getboolean('crawl', 'debug')
    SETTINGS['user_agent'] = conf.get('crawl', 'user_agent')
    SETTINGS['socket_timeout'] = conf.getint('crawl', 'socket_timeout')
    SETTINGS['cron_delay'] = conf.getint('crawl', 'cron_delay')
    SETTINGS['max_age'] = conf.getint('crawl', 'max_age')
    SETTINGS['ipv6'] = conf.getboolean('crawl', 'ipv6')
    exclude_nodes = conf.get('crawl', 'exclude_nodes').strip().split("\n")
    exclude_networks = conf.get('crawl',
                                'exclude_networks').strip().split("\n")
    for network in exclude_networks:
        exclude_nodes.extend(
            [str(address) for address in list(ip_network(unicode(network)))])
    SETTINGS['exclude_nodes'] = set(exclude_nodes)
    SETTINGS['crawl_dir'] = conf.get('crawl', 'crawl_dir')
    if not os.path.exists(SETTINGS['crawl_dir']):
        os.makedirs(SETTINGS['crawl_dir'])
    SETTINGS['master'] = argv[2] == "master"
Example #16
0
def init(config_file="ganglia-alert.conf"):
    global INTERVAL, SENDER, SERVER, RECIPIENTS, ALERTS, SMS_NUMBER, DEBUG, LOG_FILE, PID_FILE, API_KEY, API_SECRET
    config = ConfigParser()
    try:
        config.read(config_file)
        INTERVAL = config.getint("options", "interval")
        DEBUG = config.getboolean("options", "debug")
        LOG_FILE = config.get("options", "log_file")
        PID_FILE = config.get("options", "pid_file")
        SENDER = config.get("mail", "sender")
        SERVER = config.get("mail", "server")
        RECIPIENTS = [s.strip() for s in config.get("mail", "recipients").split(",")]
        SMS_NUMBER = config.get("sms", "recipient")
        API_KEY = config.get("sms", "api_key")
        API_SECRET = config.get("sms", "api_secret")
        for section in config.sections():
            if section[:5] == 'Alert':
                severity = config.get(section, 'type')
                expression = config.get(section, 'expression')
                message = config.get(section, 'message')
                action = config.get(section, 'action')
                occurences = config.getint(section, 'occurences')
                ALERTS.append(Alert(severity, expression, message, action, occurences))
        logging.basicConfig(format=FORMAT, filename=LOG_FILE, level=logging.DEBUG)
    except:
        debug("Bad configuration");
        sys.exit(2)
Example #17
0
def init_conf(argv):
    """
    Populates CONF with key-value pairs from configuration file.
    """
    conf = ConfigParser()
    conf.read(argv[1])
    CONF['logfile'] = conf.get('ping', 'logfile')
    CONF['magic_number'] = unhexlify(conf.get('ping', 'magic_number'))
    CONF['db'] = conf.getint('ping', 'db')
    CONF['workers'] = conf.getint('ping', 'workers')
    CONF['debug'] = conf.getboolean('ping', 'debug')
    CONF['source_address'] = conf.get('ping', 'source_address')
    CONF['protocol_version'] = conf.getint('ping', 'protocol_version')
    CONF['user_agent'] = conf.get('ping', 'user_agent')
    CONF['services'] = conf.getint('ping', 'services')
    CONF['relay'] = conf.getint('ping', 'relay')
    CONF['socket_timeout'] = conf.getint('ping', 'socket_timeout')
    CONF['cron_delay'] = conf.getint('ping', 'cron_delay')
    CONF['ttl'] = conf.getint('ping', 'ttl')
    CONF['ipv6_prefix'] = conf.getint('ping', 'ipv6_prefix')
    CONF['nodes_per_ipv6_prefix'] = conf.getint('ping',
                                                'nodes_per_ipv6_prefix')

    CONF['onion'] = conf.getboolean('ping', 'onion')
    CONF['tor_proxy'] = None
    if CONF['onion']:
        tor_proxy = conf.get('ping', 'tor_proxy').split(":")
        CONF['tor_proxy'] = (tor_proxy[0], int(tor_proxy[1]))

    CONF['crawl_dir'] = conf.get('ping', 'crawl_dir')
    if not os.path.exists(CONF['crawl_dir']):
        os.makedirs(CONF['crawl_dir'])

    # Set to True for master process
    CONF['master'] = argv[2] == "master"
Example #18
0
def parseConfig(config_file):
    config = ConfigParser()
    if not config.read(config_file):
        print("ERROR: config file '", config_file, "' not found")
        sys.exit(1)

    if not config.has_section("system.ruby.network"):
        print("ERROR: Ruby network not found in '", config_file)
        sys.exit(1)

    if config.get("system.ruby.network", "type") != "GarnetNetwork_d" :
        print("ERROR: Garnet network not used in '", config_file)
        sys.exit(1)

    number_of_virtual_networks = config.getint("system.ruby.network",
                                               "number_of_virtual_networks")
    vcs_per_vnet = config.getint("system.ruby.network", "vcs_per_vnet")

    buffers_per_data_vc = config.getint("system.ruby.network",
                                        "buffers_per_data_vc")
    buffers_per_control_vc = config.getint("system.ruby.network",
                                           "buffers_per_ctrl_vc")

    ni_flit_size_bits = 8 * config.getint("system.ruby.network",
                                          "ni_flit_size")

    routers = config.get("system.ruby.network", "routers").split()
    int_links = config.get("system.ruby.network", "int_links").split()
    ext_links = config.get("system.ruby.network", "ext_links").split()

    return (config, number_of_virtual_networks, vcs_per_vnet,
            buffers_per_data_vc, buffers_per_control_vc, ni_flit_size_bits,
            routers, int_links, ext_links)
Example #19
0
def parse_config(config_file):
    if not os.path.isfile(config_file):
        sys.exit("Could not find configuration file: {0}".format(config_file))

    parser = ConfigParser()
    parser.read(config_file)

    log_file = None
    loggly_token = None

    if parser.getboolean('file_log', 'enabled'):
        log_file = parser.get('file_log', 'file')

    do_logging(log_file, loggly_token)

    config = {}

    if parser.getboolean('loggly_log', 'enabled'):
        config['loggly_token'] = parser.get('loggly_log', 'token')

    config['mongo_db'] = parser.get('mongodb', 'database')

    config['hpf_feeds'] = parser.get('hpfriends', 'channels').split(',')
    config['hpf_ident'] = parser.get('hpfriends', 'ident')
    config['hpf_secret'] = parser.get('hpfriends', 'secret')
    config['hpf_port'] = parser.getint('hpfriends', 'port')
    config['hpf_host'] = parser.get('hpfriends', 'host')

    config['webapi_port'] = parser.getint('webapi', 'port')
    config['webapi_host'] = parser.get('webapi', 'host')

    return config
Example #20
0
 def parseConfigurationFile(self, configFile):
     """
     Parse the configuration file to get base model parameters
     """
     # Initialize defaults
     defaultParams = {}
     
     # CUDA kernels are defined externally in a .cu file
     defaultParams["cu_dir"]  = os.path.join("pyhawkes", "cuda", "cpp")
     defaultParams["cu_file"] = "process_id_kernels.cu"
     defaultParams["thin"] = 1
     
     # K is now the number of meta processes. 
     defaultParams["K"] = 1
     
     # Create a config parser object and read in the file
     cfgParser = ConfigParser(defaultParams)
     cfgParser.read(configFile)
     
     self.params = {}
     self.params["cu_dir"]  = cfgParser.get("proc_id_model", "cu_dir")
     self.params["cu_file"] = cfgParser.get("proc_id_model", "cu_file")
     self.params["thin"] = cfgParser.getint("proc_id_model", "thin")
     self.params["blockSz"] = cfgParser.getint("cuda", "blockSz")
     
     # Parse the params for the meta process model
     self.params["K"] = cfgParser.getint("proc_id_model", "K")
Example #21
0
def main():
    script_path = os.path.dirname(os.path.realpath(__file__))
    config_path = os.path.join(script_path, 'etc/harvest.cfg')

    config = ConfigParser()
    config.read(config_path)

    sockets = bind_sockets(config.get('server', 'port'),
                           config.get('server', 'address'))
    fork_processes(config.getint('server', 'instances'))

    datastore = DataStore(config.get('datastore', 'host'),
                          config.getint('datastore', 'port'),
                          config.get('datastore', 'username'),
                          config.get('datastore', 'password'),
                          config.get('datastore', 'database'))

    app = Application([(r"/rpc/store", Handler,
                       {'datastore': datastore,
                        'api_key': config.get('server', 'api_key')})])

    server = HTTPServer(app,
                        no_keep_alive=config.get('server', 'no_keep_alive'),
                        ssl_options={
                            'certfile': config.get('server', 'certfile'),
                            'keyfile': config.get('server', 'keyfile')})

    server.add_sockets(sockets)
    IOLoop.instance().start()
Example #22
0
def run_gui(input_start_page, end_page, strict):
    """ Batch cleans the pages in text/clean."""
    config = ConfigParser()
    config.read('book.cnf')
    if strict and \
        config.has_option('process', 'last_strict_page'):
        hold_page = config.getint('process', 'last_strict_page')
    elif not strict and \
        config.has_option('process', 'last_checked_page'):
        hold_page = config.getint('process', 'last_checked_page')
    else:
        hold_page = input_start_page
    print hold_page
    if input_start_page == 0:
        start_page = hold_page
    else:
        start_page = input_start_page
    lang = get_lang()
    lm = line_manager.LineManager(
        spell_checker.AspellSpellChecker(lang, './dict.{}.pws'.format(lang)),
        start_page,
        end_page
        )
    lm.load('text/clean')
    app = gui.main(lm, strict)
    lm.write_pages('text/clean', False)

    if strict and int(app.last_page) >= hold_page:
        config.set('process', 'last_strict_page', app.last_page)
    elif not strict and int(app.last_page) >= hold_page:
        config.set('process', 'last_checked_page', app.last_page)
    with open('book.cnf', 'wb') as f:
        config.write(f)
Example #23
0
def parse_input(config_file):

    config = ConfigParser()
    config.read(config_file)

    # get params from file, using test values as defaults if missing options
    lambd = (
        config.getfloat("Material Parameters", "lambd") if config.has_option("Material Parameters", "lambd") else 0.5
    )
    mu = config.getfloat("Material Parameters", "mu") if config.has_option("Material Parameters", "mu") else 1.0
    rho = config.getfloat("Material Parameters", "rho") if config.has_option("Material Parameters", "rho") else 3.0

    min_x = config.getfloat("Coordinates", "min_x") if config.has_option("Coordinates", "min_x") else 0.0
    max_x = config.getfloat("Coordinates", "max_x") if config.has_option("Coordinates", "max_x") else 5.0
    min_y = config.getfloat("Coordinates", "min_y") if config.has_option("Coordinates", "min_y") else 0.0
    max_y = config.getfloat("Coordinates", "max_y") if config.has_option("Coordinates", "max_y") else 5.0
    min_z = config.getfloat("Coordinates", "min_z") if config.has_option("Coordinates", "min_z") else 0.0
    max_z = config.getfloat("Coordinates", "max_z") if config.has_option("Coordinates", "max_z") else 5.0

    N_x = config.getint("Grid Points", "N_x") if config.has_option("Grid Points", "N_x") else 100
    N_y = config.getint("Grid Points", "N_y") if config.has_option("Grid Points", "N_y") else 100
    N_z = config.getint("Grid Points", "N_z") if config.has_option("Grid Points", "N_z") else 100

    t_0 = config.getfloat("Time Parameters", "t_0") if config.has_option("Time Parameters", "t_0") else 0.0
    t_f = config.getfloat("Time Parameters", "t_f") if config.has_option("Time Parameters", "t_f") else 2.5
    N_t = config.getint("Time Parameters", "N_t") if config.has_option("Time Parameters", "N_t") else 100

    output = config.get("Output File", "data") if config.has_option("Output File", "data") else "output.dat"

    return lambd, mu, rho, min_x, max_x, min_y, max_y, min_z, max_z, N_x, N_y, N_z, t_0, t_f, N_t, output
Example #24
0
    def get_value(self, section, option):
        """
        Retourne la valeur de l'option contenue dans la section passée en
        paramètre.
        """

        # On travaille sur le nom de la section parente
        # au cas où s'il s'agit d'une sous-section.
        parent_section = self.get_parent_section_name(section)


        # On vérifie d'abord que la section existe.
        if self.__spec_sections.has_key(parent_section):
            # Puis on récupère la spécification de la section.
            section_spec = self.__spec_sections.get(parent_section)
            option_type  = None

            # On parcours les options de la spécification à la recherche
            # du type de la valeur de l'option que l'on souhaite obtenir.
            for option_spec in section_spec[2]:
                if option_spec[0] == option:
                    option_type = option_spec[1]

            # Introuvable dans les options de la section ?
            # On regarde dans ceux de la sous-section si elle existe.
            if self.__spec_has_subsection(parent_section):
                for sub_option_spec in section_spec[3]:
                    if sub_option_spec[0] == option:
                        option_type = sub_option_spec[1]


            # On appelle la fonction qui va bien en fonction du type à obtenir.
            #
            # Les sous-sections héritent des options de leur section parente.
            # Si l'option n'existe pas dans la section, il doit sûrement s'agir
            # d'une sous-section. On cherche alors l'option dans la section
            # parente.
            if option_type == 'string':
                try:
                    return ConfigParser.get(self, section, option)
                except NoOptionError:
                    return ConfigParser.get(self, parent_section, option)

            if option_type == 'int':
                try:
                    return ConfigParser.getint(self, section, option)
                except NoOptionError:
                    return ConfigParser.getint(self, parent_section, option)

            if option_type == 'bool':
                try:
                    return ConfigParser.getboolean(self, section, option)
                except NoOptionError:
                    return ConfigParser.getboolean(self, parent_section, option)


            return None
        else:
            raise NameError("Invalid section name: '%(section)s'." % \
                            {'section': section})
Example #25
0
class ConfigReader(object):
    """
    为傲世堂的游戏项目配置文件定制的配置读取类。
    陈超写的arg.gameOption耦合性太强,只能在bible内使用。
    但是配置文件的结构设计的很合理。

    此类就是根据原来的结构设计重新写的解耦并且适用性更广的类。

    Example::

        conf = ConfigReader(game, region)
        ip = conf.get("mobile_www_ip")
        if conf.has_option("mobile_www_port")
            port = conf.getint("mobile_www_port")     
    """
    def __init__(self, game, section, conf_dir='/app/opbin/work/bible/conf'):
        self.game = game
        self.section = section
        self.conf_file = '{}/{}.conf'.format(conf_dir.rstrip('/'), self.game)
        self.config = ConfigParser()
        self.config.read(self.conf_file)
        self.has_section = self.config.has_section(self.section)

    def has_option(self, option):
        return self._has_option(self.section, option) or self._has_option('common', option)

    def _has_option(self, section, option):
        return self.config.has_option(section, option)

    def get(self, option, raw=0, var=None):
        if self._has_option(self.section, option):
            return self.config.get(self.section, option, raw, var)
        elif self._has_option('common', option):
            return self.config.get('common', option, raw, var)
        else:
            raise Exception("Can't find option: {} in {}".format(option, self.conf_file))

    def getint(self, option):
        if self._has_option(self.section, option):
            return self.config.getint(self.section, option)
        elif self._has_option('common', option):
            return self.config.getint('common', option)
        else:
            raise Exception("Can't find option: {} in {}".format(option, self.conf_file))

    def getfloat(self, option):
        if self._has_option(self.section, option):
            return self.config.getfloat(self.section, option)
        elif self._has_option('common', option):
            return self.config.getfloat('common', option)
        else:
            raise Exception("Can't find option: {} in {}".format(option, self.conf_file))

    def getboolean(self, option):
        if self._has_option(self.section, option):
            return self.config.getboolean(self.section, option)
        elif self._has_option('common', option):
            return self.config.getboolean('common', option)
        else:
            raise Exception("Can't find option: {} in {}".format(option, self.conf_file))
Example #26
0
def cloneShot(src, src_name, dst, dst_name):
	src_cfg = ConfigParser()
	dst_cfg = ConfigParser()
	src_cfg.read(os.path.join(src, ".nodeInfo"))
	src_version = src_cfg.getint("Versioning", "latestversion")
	dst_cfg.read(os.path.join(dst, ".nodeInfo"))
	dst_version = dst_cfg.getint("Versioning", "latestversion")
	if dst_cfg.getboolean("Versioning", "locked"):
		return False
	src_path = os.path.join(src, "src", 'v'+"%03d" % src_version)
	src_filepath = os.path.join(src_path, src_name+'_animation.mb')
	print dst_version
	dst_path = os.path.join(dst, "src", 'v'+"%03d" % (dst_version+1))
	os.mkdir(dst_path)
	dst_filepath = os.path.join(dst_path, dst_name+'_animation.mb')
	print 'copying '+src_filepath+' to '+dst_filepath
	shutil.copyfile(src_filepath, dst_filepath)

	#write out new animation info
	timestamp = time.strftime("%a, %d %b %Y %I:%M:%S %p", time.localtime())
	user = getUsername()
	comment = 'copied from '+src_name
	dst_cfg.set("Versioning", "lastcheckintime", timestamp)
	dst_cfg.set("Versioning", "lastcheckinuser", user)
	dst_cfg.set("Versioning", "latestversion", str(dst_version+1))
	commentLine = user + ': ' + timestamp + ': ' + '"' + comment + '"' 
	dst_cfg.set("Comments", 'v' + "%03d" % (dst_version+1,), commentLine)	
	_writeConfigFile(os.path.join(dst, ".nodeInfo"), dst_cfg)
	return True
Example #27
0
def canCheckin(filePath):
    """
    @returns: True if destination is not locked by another user
        AND this checkin will not overwrite a newer version
    """
    toCheckin = os.path.join(getUserCheckoutDir(), os.path.basename(os.path.dirname(filePath)))
    chkoutInfo = ConfigParser()
    chkoutInfo.read(os.path.join(toCheckin, ".checkoutInfo"))
    chkInDest = chkoutInfo.get("Checkout", "checkedoutfrom")
    version = chkoutInfo.getint("Checkout", "version")
    lockedbyme = chkoutInfo.getboolean("Checkout", "lockedbyme") # currently we call it "lockedbyme"... but it's true for everyone, no matter what. Not a particuarly good name.
    
    nodeInfo = ConfigParser()
    nodeInfo.read(os.path.join(chkInDest, ".nodeInfo"))
    locked = nodeInfo.getboolean("Versioning", "locked") # This actually checks if it is locked.
    latestVersion = nodeInfo.getint("Versioning", "latestversion")
    
    result = True
    if lockedbyme == False:
        if locked == True:
            result = False
        if version < latestVersion:
            result = False
    
    return result
Example #28
0
    def __init__(self, hosts, topo_list=None, config_file=None):
        """Create a new Hadoop cluster with the given hosts and topology.
        
        Args:
          hosts (list of Host):
            The hosts to be assigned a topology.
          topo_list (list of str, optional):
            The racks to be assigned to each host. len(hosts) should be equal to
            len(topo_list).
          configFile (str, optional):
            The path of the config file to be used.
        """

        # Load cluster properties
        config = ConfigParser(self.defaults)
        config.add_section("cluster")
        config.add_section("local")

        if config_file:
            config.readfp(open(config_file))

        self.base_dir = config.get("cluster", "hadoop_base_dir")
        self.conf_dir = config.get("cluster", "hadoop_conf_dir")
        self.logs_dir = config.get("cluster", "hadoop_logs_dir")
        self.hadoop_temp_dir = config.get("cluster", "hadoop_temp_dir")
        self.hdfs_port = config.getint("cluster", "hdfs_port")
        self.mapred_port = config.getint("cluster", "mapred_port")
        self.local_base_conf_dir = config.get("local", "local_base_conf_dir")

        self.bin_dir = self.base_dir + "/bin"
        self.sbin_dir = self.base_dir + "/bin"

        # Configure master and slaves
        self.hosts = hosts
        self.master = hosts[0]

        # Create topology
        self.topology = HadoopTopology(hosts, topo_list)
        # Store cluster information
        self.host_clusters = {}
        for h in self.hosts:
            g5k_cluster = get_host_cluster(h)
            if g5k_cluster in self.host_clusters:
                self.host_clusters[g5k_cluster].append(h)
            else:
                self.host_clusters[g5k_cluster] = [h]

        # Create a string to display the topology
        t = {v: [] for v in self.topology.topology.values()}
        for key, value in self.topology.topology.iteritems():
            t[value].append(key.address)
        log_topo = ', '.join([style.user2(k) + ': ' +
                              ' '.join(map(lambda x: style.host(x.split('.')[0]), v)) 
                              for k, v in t.iteritems()])
        
        logger.info("Hadoop cluster created with master %s, hosts %s and topology %s",
                    style.host(self.master.address), 
                    ' '.join([style.host(h.address.split('.')[0]) for h in self.hosts]),
                    log_topo)
Example #29
0
def main():
    if len(sys.argv) < 2:
        sys.stderr.write('Usage: %s CONFIG_URI\n'
                         % sys.argv[0])
        sys.exit(1)
    config_uri = sys.argv.pop(1)
    config = ConfigParser()
    config.read(config_uri)

    vroot = getenv('VIRTUOSO_ROOT')
    assert vroot, 'Please define the VIRTUOSO_ROOT environment variable'
    assert exists(vroot), "VIRTUOSO_ROOT directory does not exist"
    assert exists(join(vroot, 'bin', 'virtuoso-t')),\
        "VIRTUOSO_ROOT directory does not contain bin/virtuoso-t"
    assert exists('var/db/virtuoso.ini.tmpl'),\
        "Please run this script from the assembl root."
    vroot_var = join(vroot, 'var')
    if not exists(vroot_var):
        vroot_var = '/var'
    vroot_lib = join(vroot, 'lib')
    assert exists(vroot_lib)
    if not exists(join(vroot_lib, 'virtodbcu.so'))\
            and exists(join(vroot_lib, 'odbc', 'virtodbcu.so')):
        vroot_lib = join(vroot_lib, 'odbc')
    vname = 'virtuoso'
    if not exists(join(vroot, 'share', vname)):
        names = listdir(join(vroot, 'share'))
        names = [n for n in names
                 if exists(join(vroot, 'share', n, 'vad'))]
        assert len(names) == 1, "Cannot identify the vad directory"
        vname = names[0]
    assert exists(join(vroot_var, 'lib', vname, 'vsp')),\
        "Cannot identify the VSP directory"
    assert exists(join(vroot, 'lib', vname, 'hosting')),\
        "Cannot identify the Virtuoso hosting directory"
    vars = {
        'VIRTUOSO_SERVER_PORT': config.getint('virtuoso', 'http_port'),
        'VIRTUOSO_PORT': config.getint('virtuoso', 'port'),
        'VIRTUOSO_ROOT': vroot,
        'VIRTUOSO_ROOT_VAR': vroot_var,
        'VIRTUOSO_ROOT_LIB': vroot_lib,
        'VIRTUOSO_SUBDIR_NAME': vname,
        'CELERY_BROKER': config.get('app:main', 'celery.broker'),
        'here': dirname(abspath('supervisord.conf')),
        'CONFIG_FILE': config_uri
    }
    for fname in ('var/db/virtuoso.ini', 'odbc.ini', 'supervisord.conf',):
        tmpl = open(fname+'.tmpl').read()
        inifile = open(fname, 'w')
        inifile.write(tmpl % vars)
        inifile.close()
    if not exists('var'):
        mkdir('var')
    if not exists('var/log'):
        mkdir('var/log')
    if not exists('var/run'):
        mkdir('var/run')
Example #30
0
    def __init__(self, cfg_file, template):
        """
        @param cfg_file: file path of the configuration file.
        @param template: list of tuples with {section:(key_name, key_type)}
        """
        config = ConfigParser()
        config.read(cfg_file)

        # load configuration file
        for section in config.sections():
            setattr(self, section, ConfigurationSection())
            for name in config.options(section):
                try:
                    value = config.getboolean(section, name)
                except ValueError:
                    try:
                        value = config.getint(section, name)
                    except ValueError:
                        value = config.get(section, name)
                setattr(getattr(self, section), name, value)

        # override with default values from template
        for section in template.keys():
            # setattr even if section is not present in ini file
            # as it may have default value, check at value fetching
            setattr(self, section, ConfigurationSection())
            if type(template[section]) != list:
                reason = "Malformed Template section type should be list"
                raise IrmaConfigurationError(reason)
            for (key_name, key_type, key_def_value) in template[section]:
                if not config.has_option(section, key_name):
                    # If key not found but a default value exists, set it
                    if key_def_value is not None:
                        setattr(getattr(self, section),
                                key_name,
                                key_def_value)
                        continue
                    else:
                        reason = ("file {0} ".format(cfg_file) +
                                  "missing section {0} ".format(section) +
                                  "key {0}".format(key_name))
                        raise IrmaConfigurationError(reason)
                try:
                    if key_type == self.boolean:
                        value = config.getboolean(section, key_name)
                    elif key_type == self.integer:
                        value = config.getint(section, key_name)
                    else:
                        value = config.get(section, key_name)
                    setattr(getattr(self, section), key_name, value)
                except ValueError:
                    reason = ("file {0} ".format(cfg_file) +
                              "missing section {0} ".format(section) +
                              "Wrong type for key {0}".format(key_name))
                    raise IrmaConfigurationError(reason)