Example #1
0
def init_settings(argv):
    """
    Populates SETTINGS with key-value pairs from configuration file.
    """
    conf = ConfigParser()
    conf.read(argv[1])
    SETTINGS['logfile'] = conf.get('ping', 'logfile')
    SETTINGS['workers'] = conf.getint('ping', 'workers')
    SETTINGS['debug'] = conf.getboolean('ping', 'debug')
    SETTINGS['source_address'] = conf.get('ping', 'source_address')
    SETTINGS['protocol_version'] = conf.getint('ping', 'protocol_version')
    SETTINGS['user_agent'] = conf.get('ping', 'user_agent')
    SETTINGS['services'] = conf.getint('ping', 'services')
    SETTINGS['relay'] = conf.getint('ping', 'relay')
    SETTINGS['socket_timeout'] = conf.getint('ping', 'socket_timeout')
    SETTINGS['cron_delay'] = conf.getint('ping', 'cron_delay')
    SETTINGS['ttl'] = conf.getint('ping', 'ttl')
    SETTINGS['ipv6_prefix'] = conf.getint('ping', 'ipv6_prefix')
    SETTINGS['nodes_per_ipv6_prefix'] = conf.getint('ping',
                                                    'nodes_per_ipv6_prefix')

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

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

    # Set to True for master process
    SETTINGS['master'] = argv[2] == "master"
Example #2
0
    def get_conf(self, config_file):
        config = ConfigParser()
        config.read(config_file)

        # Telegram
        self.conf['api'] = config.get('Telegram','api')
        self.conf['group_id'] = int(config.get('Telegram','group_id'))
        # One should use getboolean to fetch boolean values, otherwise they will always be True unless empty
        self.conf['telegram_enable'] = config.getboolean('Telegram','enable')

        # Zabbix
        self.conf['server_name'] = config.get('Zabbix','server_name')
        self.conf['agentd_config'] = config.get('Zabbix','agentd_config')
        self.conf['zabbix_advantage_keys'] = config.getboolean('Zabbix','enable_advantage_keys')
        self.conf['zabbix_enable'] = config.getboolean('Zabbix','enable')

        # Apache
        self.conf['apache_log'] = config.get('General','apache_log')
        self.conf['rules'] = config.get('General','rules')
        self.conf['apache_mask'] = config.get('General','apache_mask')
        self.conf['vhost_enable'] = config.getboolean('General','vhost_enable')

        # CEF_Syslog
        self.conf['cef_syslog_enable'] = config.getboolean('CEF_Syslog','enable')
        self.conf['cef_syslog_server'] = config.get('CEF_Syslog','server_name')

        return self.conf
def config():
    global video_format
    global resolution
    configr = ConfigParser()
    configr.read('settings.ini')
    quality = configr.get('SETTINGS', 'video_quality')
    qualities = {'android': ['107', '71'], '360p': ['106', '60'], '480p': ['106', '61'],
                 '720p': ['106', '62'], '1080p': ['108', '80'], 'highest': ['0', '0']}
    video_format = qualities[quality][0]
    resolution = qualities[quality][1]
    global lang
    global lang2
    lang = configr.get('SETTINGS', 'language')
    lang2 = configr.get('SETTINGS', 'language2')
    langd = {'Espanol_Espana': u'Español (Espana)', 'Francais': u'Français (France)', 'Portugues': u'Português (Brasil)',
            'English': u'English', 'Espanol': u'Español', 'Turkce': u'Türkçe', 'Italiano': u'Italiano',
            'Arabic': u'العربية', 'Deutsch': u'Deutsch'}
    lang = langd[lang]
    lang2 = langd[lang2]
    forcesub = configr.getboolean('SETTINGS', 'forcesubtitle')
    global forceusa
    forceusa = configr.getboolean('SETTINGS', 'forceusa')
    global localizecookies
    localizecookies = configr.getboolean('SETTINGS', 'localizecookies')
    onlymainsub = configr.getboolean('SETTINGS', 'onlymainsub')
    return [lang, lang2, forcesub, forceusa, localizecookies, quality, onlymainsub]
Example #4
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 #5
0
    def run(self):
        """

        """
        try:
            cfg = ConfigParser()
            re = cfg.read(CONFIG_FILE)
            if CONFIG_FILE not in re:
                self.error_parse_config()
        except Exception:
            self.error_parse_config()

        appProcess = list()
        for i in cfg.sections():
            print "Starting push process for App %s" % cfg.get(i, 'app_name')
            p = Process(target=runApp, args=(cfg.getboolean(i, 'app_sandbox'),
                                             cfg.get(i, 'app_cert'),
                                             cfg.get(i, 'app_key'),
                                             cfg.get(i,'driver'),
                                             cfg.get(i, 'queue_host'),
                                             cfg.getint(i,'queue_port'),
                                             cfg.get(i, 'queue_db_name'),
                                             cfg.get(i, 'queue_username'),
                                             cfg.get(i, 'queue_password'),
                                             cfg.get(i, 'app_queue_name'),
                                             cfg.get(i, 'app_name'),
                                             cfg.getboolean(i,'debug'),
                                             cfg.get(i,'feedback_callback'),))
            appProcess.append(p)
            p.name = cfg.get(i, 'app_name')
            p.daemon = True
            p.start()

        for p in appProcess:
            p.join()
Example #6
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 #7
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 #8
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 #9
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
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 #11
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 #12
0
def getConfig( configFile ):

	# defaults
	podlist = "~/.podagg/podlist"
	history = "~/.podagg/history"
	downloadPath = "~/podcasts/"
	separateDirs = True
	updateId3 = True
	latestEpisodeDir = None
	
	cfgFile = ConfigParser()
	cfgFile.read( configFile )
	if cfgFile.has_option( "files", "podlist" ):
		podlist = cfgFile.get( "files", "podlist" )
	if cfgFile.has_option( "files", "history" ):
		history = cfgFile.get( "files", "history" )
	if cfgFile.has_option( "paths", "download_dir" ):
		downloadPath = cfgFile.get( "paths", "download_dir" )
	if cfgFile.has_option( "paths", "separate_dirs" ):
		separateDirs = cfgFile.getboolean( "paths", "separate_dirs" )
	if cfgFile.has_option( "misc", "update_id3" ):
		updateId3 = cfgFile.getboolean( "misc", "update_id3" )
	if cfgFile.has_option( "paths", "latest_episode_dir" ):
		latestEpisodeDir = cfgFile.get( "paths", "latest_episode_dir" )

	# expand paths to support ~	
	podlist = os.path.expanduser( podlist )
	history = os.path.expanduser( history )
	downloadPath = os.path.expanduser( downloadPath )
	if latestEpisodeDir != None:
		latestEpisodeDir = os.path.expanduser( latestEpisodeDir )

	result = Config( podlist = podlist, history = history, downloadPath = downloadPath, separateDirs = separateDirs, updateId3 = updateId3, latestEpisodeDir = latestEpisodeDir )

	return result
Example #13
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)
Example #14
0
def checkin(asset, comment):
    """
    Checks a folder back in as the newest version
    @precondition: toCheckin is a valid path
    @precondition: canCheckin() == True OR all conflicts have been resolved
    """
    print "Checking in asset ", asset

    # First, we'll have to set the comment in here.
    assetToCheckIn = os.path.join(getUserCheckoutDir(), os.path.basename(os.path.dirname(asset)))
    setComment(assetToCheckIn, comment)

    # Then we configure everything that is in here.

    # print toCheckin
    chkoutInfo = ConfigParser()
    chkoutInfo.read(os.path.join(assetToCheckIn, ".checkoutInfo"))
    chkInDest = chkoutInfo.get("Checkout", "checkedoutfrom")
    lockedbyme = chkoutInfo.getboolean("Checkout", "lockedbyme")
    
    nodeInfo = ConfigParser()
    nodeInfo.read(os.path.join(chkInDest, ".nodeInfo"))
    locked = nodeInfo.getboolean("Versioning", "locked")
    toKeep = nodeInfo.getint("Versioning", "Versionstokeep")
    newVersion = nodeInfo.getint("Versioning", "latestversion") + 1
    newVersionPath = os.path.join(chkInDest, "src", "v"+("%03d" % newVersion))
    
    if not canCheckin(asset):
        print "Can not overwrite locked folder."
        raise Exception("Can not overwrite locked folder.")
    
    # Checkin
    shutil.copytree(assetToCheckIn, newVersionPath)

    # And fix permissions for the new version asset so that everyone can access it.
    os.system('chmod 774 -R '+ newVersionPath)
    
    timestamp = time.strftime("%a, %d %b %Y %I:%M:%S %p", time.localtime())
    nodeInfo.set("Versioning", "lastcheckintime", timestamp)
    nodeInfo.set("Versioning", "lastcheckinuser", getUsername())
    nodeInfo.set("Versioning", "latestversion", str(newVersion))
    nodeInfo.set("Versioning", "locked", "False")
    amu._writeConfigFile(os.path.join(chkInDest, ".nodeInfo"), nodeInfo)
    
    #print glob.glob(os.path.join(chkInDest, "src", "*"))
    if toKeep > 0:
        amu.purge(os.path.join(chkInDest, "src"), nodeInfo, newVersion - toKeep)
        amu._writeConfigFile(os.path.join(chkInDest, ".nodeInfo"), nodeInfo)

    # Clean up
    shutil.rmtree(assetToCheckIn)
    os.remove(os.path.join(newVersionPath, ".checkoutInfo"))

    return chkInDest
Example #15
0
 def __init__(self):
     config = ConfigParser()
     config.read(App.__config__)
         
     self.host = config.get('Host','host')
     self.port = config.getint('Host','port')     
     self.logger = config.get('Log','logger')
     self.log_debug = config.getboolean('Log','debug')
     self.log_screen = config.getboolean('Log','screen')
             
     Storage.root = self.root = config.get('Path','root')
     Storage.loadConfig(App.dirname + config.get('Path', 's3_ini'))
Example #16
0
	def init(self):
		self.button = Plasma.IconWidget(self.parent)
		self.iconStopped = KIcon(ICON_STOPPED)
		self.iconRunning = KIcon(ICON_RUNNING)
		self.iconUnknown = KIcon(ICON_UNKNOWN)
		self.pid = None
		self.subp = None
		self.waiting = False

		self.setHasConfigurationInterface(True)
		#set size of Plasmoid
		self.resize(50, 50)
		self.setAspectRatioMode(Plasma.KeepAspectRatio)
		self.setBackgroundHints(Plasma.Applet.DefaultBackground)

		self.theme = Plasma.Svg(self)
		self.theme.setImagePath(THEME)
		self.layout = QGraphicsGridLayout(self.applet)
		self.layout.setContentsMargins(3,3,3,3)
		self.setMinimumSize(10,10)

		#set timer interval
		self.timer = self.startTimer(REFRESH)
		self.button.setIcon(self.iconUnknown)
		QObject.connect(self.button, SIGNAL('clicked()'), self.toggle)
		self.appletDestroyed.connect(self.destroy)

		self.cfgfile = '.plasma-flux.cfg'
		strFile = os.path.join(os.path.expanduser('~'), self.cfgfile)
		if os.path.exists(strFile):
			cfgParser = ConfigParser()
			cfgFile = open(strFile)
			cfgParser.readfp(cfgFile)
			try:
				self.lon = cfgParser.getfloat('settings', 'lon')
				self.lat = cfgParser.getfloat('settings', 'lat')
				self.nighttmp = cfgParser.getint('settings', 'nighttmp')
				self.daytmp = cfgParser.getint('settings', 'daytmp')
				self.smooth = cfgParser.getboolean('settings', 'smooth')
				self.program = cfgParser.get('settings', 'program')
				self.mode = cfgParser.get('settings', 'mode')
				self.gamma = cfgParser.get('settings', 'gamma')
				self.auto = cfgParser.getboolean('settings', 'auto')
				cfgFile.close()
			except:
				self.defaultOptions()
		else:
			self.defaultOptions()
		self.updateStatus()
		if self.auto and self.checkStatus() == 'Stopped':
			print('Auto-starting %s' % self.program)
			self.toggle()
Example #17
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['network'] = conf.get('crawl', 'network')
    SETTINGS['seeders'] = conf.get('crawl', 'seeders').strip().split("\n")
    SETTINGS['workers'] = conf.getint('crawl', 'workers')
    SETTINGS['debug'] = conf.getboolean('crawl', 'debug')
    SETTINGS['source_address'] = conf.get('crawl', 'source_address')
    SETTINGS['protocol_version'] = conf.getint('crawl', 'protocol_version')
    SETTINGS['user_agent'] = conf.get('crawl', 'user_agent')
    SETTINGS['services'] = conf.getint('crawl', 'services')
    SETTINGS['relay'] = conf.getint('crawl', 'relay')
    SETTINGS['socket_timeout'] = conf.getint('crawl', 'socket_timeout')
    SETTINGS['cron_delay'] = conf.getint('crawl', 'cron_delay')
    SETTINGS['snapshot_delay'] = conf.getint('crawl', 'snapshot_delay')
    SETTINGS['max_age'] = conf.getint('crawl', 'max_age')
    SETTINGS['ipv6'] = conf.getboolean('crawl', 'ipv6')
    SETTINGS['ipv6_prefix'] = conf.getint('crawl', 'ipv6_prefix')
    SETTINGS['nodes_per_ipv6_prefix'] = conf.getint('crawl',
                                                    'nodes_per_ipv6_prefix')

    SETTINGS['exclude_ipv4_networks'] = list_excluded_networks(
        conf.get('crawl', 'exclude_ipv4_networks'))
    SETTINGS['exclude_ipv6_networks'] = list_excluded_networks(
        conf.get('crawl', 'exclude_ipv6_networks'))

    SETTINGS['exclude_ipv4_bogons'] = conf.getboolean('crawl',
                                                      'exclude_ipv4_bogons')

    SETTINGS['initial_exclude_ipv4_networks'] = \
        SETTINGS['exclude_ipv4_networks']

    SETTINGS['onion'] = conf.getboolean('crawl', 'onion')
    SETTINGS['tor_proxy'] = None
    if SETTINGS['onion']:
        tor_proxy = conf.get('crawl', 'tor_proxy').split(":")
        SETTINGS['tor_proxy'] = (tor_proxy[0], int(tor_proxy[1]))
    SETTINGS['onion_nodes'] = conf.get('crawl',
                                       'onion_nodes').strip().split("\n")

    SETTINGS['include_checked'] = conf.getboolean('crawl', 'include_checked')

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

    # Set to True for master process
    SETTINGS['master'] = argv[2] == "master"
Example #18
0
 def ReadCfg(self, cfg_filename):
     cfg_file = file(cfg_filename)
     cp = ConfigParser()
     cp.readfp(cfg_file)
     self._delimiter = cp.get('CSV', 'delimiter')
     self._date_format = cp.get('CSV', 'date')
     self._csv_columns = cp.get('CSV', 'columns')
     if cp.has_option('CSV', 'encoding'):
         self._encoding = cp.get('CSV', 'encoding')
     if cp.has_option('CSV', 'locale-decimal-sep'):
         self._locale_decimal_sep = cp.getboolean('CSV', 'locale-decimal-sep')
     if cp.has_option('CSV', 'negate-amount'):
         self._negate_amount = cp.getboolean('CSV', 'negate-amount')
Example #19
0
 def get_config(self):
     '''get_config
     Gets the stored configuration from the config file applies those
     settings to the object.
     '''
     section = 'World: %s' % self.name
     conf = ConfigParser()
     conf.read(self._config_file)
     if not conf.has_section(section):
         self.set_config()
     self.env = conf.get('Server', 'environment')
     self.ramdisk = conf.getboolean(section, 'ramdisk')
     self.automount = conf.getboolean(section, 'automount')
Example #20
0
def fn(options, args):
    cfg = ConfigParser()
    cfg.read('LoginAccount.txt')

    flag = 'mailClient'
    keys = ('host', 'port', 'user', 'pass', 'fr', 'to', 'debuglevel', 'login', 'starttls')
    stor = {}
    for k in keys: stor.setdefault(k, '')

    try:
        stor['host'] = cfg.get(flag, 'host')
        stor['port'] = cfg.getint(flag, 'port')
        stor['user'] = cfg.get(flag, 'user')
        stor['pass'] = cfg.get(flag, 'pass')
        stor['fr'] = cfg.get(flag, 'fr')
        stor['to'] = cfg.get(flag, 'to')
        stor['debuglevel'] = cfg.getboolean(flag, 'debuglevel')
        stor['login'] = cfg.getboolean(flag, 'login')
        stor['starttls'] = cfg.getboolean(flag, 'starttls')
    except NoOptionError: pass

    if options.addr:
        stor['to'] = options.addr
   
    s = get_smtp_client(stor)
    for arg in args:
        sys.stdout.write('sending... ' + arg)
        msg = MIMEMultipart()
        msg['From'] = stor['fr']
        msg['Subject'] = arg
        msg['To'] = stor['to']
        msg.set_boundary('===== Baby, python is good =====')

        if not options.atta:
            data = MIMEBase('application', 'octet-stream')
            data.set_payload(open(arg, 'rb').read())
            Encoders.encode_base64(data)
            data.add_header('Content-Disposition', 'attachment', filename = arg)
            msg.attach(data)
        else:
            b = '''<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head><body><pre>'''
            b += open(arg, 'rb').read()
            b += '''</pre></body></html>'''

            body = MIMEText(b, _subtype = 'html', _charset = 'utf-8')
            msg.attach(body)
        sendmail(s, msg)
        sys.stdout.write(' done.\n')
    s.close()
Example #21
0
def clean(start_page, end_page):
    """ Batch cleans the pages in text/clean."""

    config = ConfigParser()
    config.read('book.cnf')
    try:
        clean_headers = config.getboolean('process', 'clean_headers')
    except NoOptionError:
        clean_headers = True
    try:
        join_lines = config.getboolean('process', 'join_lines')
    except NoOptionError:
        join_lines = True

    if clean_headers:
	print 'cleaning headers'
        remove_headers()
        if not config.has_section('process'):
            config.add_section('process')
        config.set('process', 'clean_headers', 'false')
        with open('book.cnf', 'wb') as f:
            config.write(f)
        lm =_loaded_aspell_line_manager(start_page, end_page)
        lm.quick_fix()
    elif join_lines:
	print 'joining lines'
        if not config.has_section('process'):
            config.add_section('process')
        config.set('process', 'join_lines', 'false')
        with open('book.cnf', 'wb') as f:
            config.write(f)
        lm =_loaded_file_line_manager(start_page, end_page)
        lm.join_lines()
    else:
        # if interrupted by keyboard, go ahead and write changes
        lang = get_lang()
#           spell_checker.FileConfiguredSpellChecker(lang, './dict.{}.pws'.format(lang)),
#           spell_checker.AspellSpellChecker(lang, './dict.{}.pws'.format(lang)),
        lm = line_manager.LineManager(
#           spell_checker.AspellSpellChecker(lang, './dict.{}.pws'.format(lang)),
            spell_checker.FileConfiguredSpellChecker(lang),
            start_page,
            end_page
            )
        lm.load('text/clean')
        try:
            lm.fix_lines()
        except KeyboardInterrupt:
            pass
    lm.write_pages('text/clean', False)
Example #22
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')

    if os.getenv("REMOTE_MONGO") == "true":
        config['mongo_host'] = os.getenv("MONGO_HOST")
        config['mongo_port'] = int(os.getenv("MONGO_PORT"))

        config['mongo_auth'] = False
        if os.getenv("MONGO_AUTH") == "true":
            config['mongo_auth'] = True
            config['mongo_user'] = os.getenv("MONGO_USER")
            config['mongo_password'] = os.getenv("MONGO_PASSWORD")
            config['mongo_auth_mechanism'] = os.getenv("MONGO_AUTH_MECHANISM")
    else:
        config['mongo_auth'] = False
        config['mongo_host'] = "127.0.0.1"
        config['mongo_port'] = 27017

    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')

    config['normalizer_ignore_rfc1918'] = parser.getboolean('normalizer', 'ignore_rfc1918')

    return config
Example #23
0
 def __init__(self):
     if not os.path.exists('ilm.conf'):
         logging.error('we need a valid config, none found!')
         raise
     parser = ConfigParser()
     parser.read('ilm.conf')
     self.aws_region = parser.get('aws', 'region')
     self.aws_secret = parser.get('aws', 'secret_key')
     self.aws_access = parser.get('aws', 'access_key')
     self.aws_seqgrp = parser.get('aws', 'security_group')
     self.aws_req_max_wait = parser.get('aws', 'request_max_wait_time')
     self.auto_remove_failed = parser.getboolean('parameters', 'auto_remove_failed')
     self.recycle_workers = parser.getboolean('parameters', 'recycle_workers')
     self.max_instances = parser.getint('parameters', 'max_instances')
     self.max_storage = parser.getint('parameters', 'max_storage')
Example #24
0
 def __init__(self):
     cfg = ConfigParser()
     try:
         cfg.read(globalcfgfile)
     except:
         pass
     if not cfg.has_section("userconfig"):
         self.loadlasttime = True
         self.openremote = True
         self.fontfamily = None
         self.fontsize = None
         self.__lastdir = home
         self.sengine_own = True
     if not cfg.has_section("searchext"):
         self.searchext = {"html": True, "htm": True, "js": False, "txt": False, "css": False}
     else:
         self.searchext = {}
         for a, b in cfg.items("searchext"):
             if b.lower() == "false":
                 self.searchext[a] = False
             else:
                 self.searchext[a] = True
     try:
         self.loadlasttime = cfg.getboolean("userconfig", "loadlasttime")
     except:
         self.lastlasttime = True
     try:
         self.sengine_own = cfg.getboolean("userconfig", "default_search_engine")
     except:
         self.sengine_own = True
     try:
         self.openremote = cfg.getboolean("userconfig", "openremote")
     except:
         self.openremote = True
     try:
         self.fontfamily = cfg.get("userconfig", "fontfamily").decode("utf-8")
         if self.fontfamily == "default":
             self.fontfamily = None
     except:
         self.fontfamily = None
     try:
         self.fontsize = cfg.getint("userconfig", "fontsize")
     except:
         self.fontsize = None
     try:
         self.__lastdir = cfg.get("userconfig", "lastdir")
     except:
         self.__lastdir = home
Example #25
0
 def getboolean(self, section, option):
     try:
         value = ConfigParser.getboolean(self, section, option)
     except ValueError: # not a boolean
         logger.warning("Value %s->%s is not a boolean" % (section, option))
         return False
     return value
Example #26
0
  def readFrom(self, path, section):
    parser = ConfigParser()
    if not parser.read(path):
      raise CarbonConfigException("Failed to read config file %s" % path)

    if not parser.has_section(section):
      return

    for key, value in parser.items(section):
      key = key.upper()

      # Detect type from defaults dict
      if key in defaults:
        valueType = type(defaults[key])
      else:
        valueType = str

      if valueType is list:
        value = [v.strip() for v in value.split(',')]

      elif valueType is bool:
        value = parser.getboolean(section, key)

      else:
        # Attempt to figure out numeric types automatically
        try:
          value = int(value)
        except:
          try:
            value = float(value)
          except:
            pass

      self[key] = value
Example #27
0
class UserConfig:

    def __init__(self, filename=default_user_config_file):
        self.parser = ConfigParser()
        self.parser.read(filename)
        self.filename = filename
        if not isfile(self.filename):
            self.parser.add_section('diaspora')
            self.set_activated(False)
            self.__save()
        else:
            self.parser.read(self.filename)

        if not self.parser.has_section('diaspora'):
            self.parser.add_section('diaspora')

    def is_installed(self):
        return self.parser.getboolean('diaspora', 'activated')

    def set_activated(self, value):
        self.parser.set('diaspora', 'activated', str(value))
        self.__save()

    def __save(self):
        with open(self.filename, 'wb') as f:
            self.parser.write(f)
Example #28
0
def isCheckedOut(dirPath):
	nodeInfo = os.path.join(dirPath, ".nodeInfo")
	if not os.path.exists(nodeInfo):
		return False
	cp = ConfigParser()
	cp.read(nodeInfo)
	return cp.getboolean("Versioning", "locked")
Example #29
0
def setVersion(dirPath, version):	
    """
    Sets the 'latest version' as the specified version and deletes later versions
    @precondition: dirPath is a valid path
    @precondition: version is an existing version
    @precondition: the folder has been checked out by the user

    @postcondition: the folder will be checked in and unlocked
    """

    chkoutInfo = ConfigParser()
    chkoutInfo.read(os.path.join(dirPath, ".checkoutInfo"))
    chkInDest = chkoutInfo.get("Checkout", "checkedoutfrom")
    lockedbyme = chkoutInfo.getboolean("Checkout", "lockedbyme")
    
    nodeInfo = ConfigParser()
    nodeInfo.read(os.path.join(chkInDest, ".nodeInfo"))
    newVersionPath = os.path.join(chkInDest, "src", "v"+str(version))

    if lockedbyme == False:
        print "Cannot overwrite locked folder."
        raise Exception("Can not overwrite locked folder.")
        
    # Set version
    timestamp = time.strftime("%a, %d %b %Y %I:%M:%S %p", time.localtime())
    nodeInfo.set("Versioning", "lastcheckintime", timestamp)
    nodeInfo.set("Versioning", "lastcheckinuser", getUsername())
    nodeInfo.set("Versioning", "latestversion", str(version))
    nodeInfo.set("Versioning", "locked", "False")
    _writeConfigFile(os.path.join(chkInDest, ".nodeInfo"), nodeInfo)
    
    # Clean up
    purgeAfter(os.path.join(chkInDest, "src"), version)
    shutil.rmtree(dirPath)
Example #30
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