Example #1
0
def main(numthreads=10):
    t1 = time.time()
    queue = Queue()
    factory = TokenFactory()
    config = ConfigParser()
    config.read('vk_api.conf')

    url = API.get_url(
        app_id=config.get('api', 'id'), app_key=config.get('api', 'key'), 
        permissions=PERMISSIONS, redirect_uri=URI, display=DISPLAY, api_version=VERSION)

    # TODO: check token expiration
    token_pair = factory.get_token_pair()
    if not token_pair:
        token_pair = factory.store_token_pair(url)
    
    api = API(token=token_pair[0],user_id=token_pair[1])
    audio = api.audio
    data = audio.get

    if data:
        for item in data['response']['items']:
            queue.put(item)

        for i in range(numthreads):
            t = DownloadThread(queue, FILE_DIR)
            t.start()

        queue.join()


    t2 = time.time()
    print('Time: {0}'.format(t2-t1))
Example #2
0
def getDataSources(fName = None):
    ''' return data sources directories for this machine.
    directories are defined in datasources.ini or provided filepath'''
    import socket
    from ConfigParser import ConfigParser

    pcName = socket.gethostname()

    p = ConfigParser()
    p.optionxform = str


    if fName is None:
        fName = 'datasources.ini'

    p.read(fName)

    if pcName not in p.sections():
        raise NameError('Host name section %s not found in file %s' %(pcName,fName))

    dataSources = {}
    for option in p.options(pcName):
        dataSources[option] = p.get(pcName,option)

    return dataSources
Example #3
0
class ConfigLoader():
    def __init__(self):
        try:
            open(cfg_name, 'r').close()
        except:
            sys.stderr.write(u'严重错误,无法读取配置文件!程序自动退出。\n')
            exit(-1)
        self.config = ConfigParser()
        self.config.read(cfg_name)
        self.system = dict(self.config.items('system'))
        self.config_check()

    def config_check(self):
        try:
            # 首先检查设定的全局存储目录是否合法
            check_path(self.read('global_pos'))
            # 然后检查管理员的下载目录是否存在
            root_path = os.path.join(self.read('global_pos'), 'root')
            if not os.path.exists(root_path):
                os.mkdir(root_path)
        except Exception, err:
            sys.stderr.write(u'系统错误,原因:%s\n' % err)
            exit(-1)
        # 接下来检查端口是否可用
        if check_port(self.read('port_name')):
            sys.stderr.write(u'系统错误,端口被占用!\n')
            exit(-1)
Example #4
0
class Config(object):

	def __init__(self):
		self.parser = ConfigParser()
		self.read_configuration()

	def read_configuration(self):
		# check if we are in svn working dir
		if not os.path.isdir('.svn'):
			raise ExsvnError("Current directory is not a svn working directory")

		fullcfgname = os.path.join('.svn', CONFIG_FILENAME)
		if not os.path.exists(fullcfgname):
			self.create_configuration(fullcfgname)
		
		self.parser.read(fullcfgname)

	def create_configuration(self, fname):
		"""Create new configuration file"""
		print "Creating default configuration in %s" % fname
		cfg = self.get_default_configuration()

		f = file(fname, "w")
		f.write(cfg)
		f.close()

		# protect from others
		os.chmod(fname, 0600)

	def get_default_configuration(self):
		return """
Example #5
0
class Config(object):
    def __new__(type, *args, **kwargs):
        if not '_the_instance' in type.__dict__:
            type._the_instance = object.__new__(type)
        return type._the_instance
    
    def __init__(self, filename = None):
        if filename != None:
            self.filename = filename
            self.config = ConfigParser()
            self.config.read(self.filename)
    
    def get_section(self,name):
        if self.config.has_section(name):
            return _Section(name, self.config.items(name), self)
        else:
            return _Section(name, [], self)
    
    def __getattr__(self, attr):
        if attr == 'irc':
            return self.get_section('IRC')
        elif attr == 'ldap':
            return self.get_section('LDAP')
        elif attr == 'rpc':
            return self.get_section('RPC')
        elif attr == 'bot':
            return self.get_section('Bot')
        elif attr == 'smtp':
            return self.get_section('SMTP')
        elif attr == 'db':
            return self.get_section('Database')
        elif attr == 'identica':
            return self.get_section('Identi.ca')
        else:
            raise AttributeError('No section \'%s\' in Config.' % attr)
Example #6
0
def process_config(directory, config_file, sp):
	
	config = ConfigParser()
	config.read(config_file)
	sections = config.sections()
	
	db_or_element = db_or_element_format(sp, sections)
	
	if db_or_element == "db":
		invalid_sections = fc.invalid_config_sections(directory, config_file, sp.full_header_data("db"))
	elif db_or_element == "element":
		invalid_sections = fc.invalid_config_sections(directory, config_file, sp.full_header_data("element"))
	else:
		return "error"

	for s in sections:
		fname = config.get(s, "file_name")
		header = config.get(s, "header")
		if s in invalid_sections:
			if os.path.exists(directory + fname):
				os.remove(directory + fname)
		else:
			with open(directory + s + "_temp.txt", "w") as w:
				w.write(header + "\n")
				with open(directory + fname, "r") as r:
					for line in r:
						w.write(line)
				os.remove(directory + fname)
			os.rename(directory + s + "_temp.txt", directory + fname)
	os.remove(config_file)
	if len(invalid_sections) == 0:
		return None
	return {"invalid_sections":invalid_sections}
Example #7
0
	def getMysqlConfig(self, db = 'test'):
		"""获取mysql连接配置

		- 依赖配置文件[conf/config.ini],节点[db]

		Returns:
			dbconfig dict.
		"""

		try:
			cf = ConfigParser()
			cf.read('conf/config.ini')
			dbconfig = {
				'host': cf.get('db', 'host'), 
				'port': cf.getint('db', 'port'), 
				'user': cf.get('db', 'user'), 
				'passwd': cf.get('db', 'passwd'), 
				'db': db
			}
			return dbconfig			
		except Exception as e:
			error = """Can't load config from [conf/config.ini] or [db] node doesn't exist.\n
			Please make sure this file."""
			logging.warning(error)
			print(error)
			raise Exception(e)
Example #8
0
    def restore_rois(self, roifile):
        """restore ROI setting from ROI.dat file"""
        cp =  ConfigParser()
        cp.read(roifile)
        rois = []
        self.mcas[0].clear_rois()
        prefix = self.mcas[0]._prefix
        if prefix.endswith('.'):
            prefix = prefix[:-1]
        iroi = 0
        for a in cp.options('rois'):
            if a.lower().startswith('roi'):
                name, dat = cp.get('rois', a).split('|')
                lims = [int(i) for i in dat.split()]
                lo, hi = lims[0], lims[1]
                roi = ROI(prefix=prefix, roi=iroi)
                roi.left = lo
                roi.right = hi
                roi.name = name.strip()
                rois.append(roi)
                iroi += 1

        epics.poll(0.050, 1.0)
        self.mcas[0].set_rois(rois)
        cal0 = self.mcas[0].get_calib()
        for mca in self.mcas[1:]:
            mca.set_rois(rois, calib=cal0)
def _load_configuration(environment, path):
        """Loads a given configuration file specified by path and environment header (ini file).
        returns a key value representing the configuration. Values enclosed in {} are automatically
        decrypted using the $FURTHER_PASSWORD variable. Values that equal [RND] will be replaced with
        a random string."""

        # Read configuration file
        parser = ConfigParser()
        parser.read(path)

        config = {}
        for option in parser.options(environment):
                value = parser.get(environment, option)

                # Handle encrypted configuration
                if (re.match(r'^\{.*\}$', value)):
                        encrypted_value = re.match(r'^\{(.*)\}$', value).group(1)
                        value = (local('decrypt.sh input="' + encrypted_value + '" password=$FURTHER_PASSWORD algorithm="PBEWithSHA1AndDESede" verbose="false"', capture=True))

                # Handle random values
                if (re.match(r'\[RND\]', value)):
                        value = _random_string()

                config[option] = value;

        return config
Example #10
0
    def test_import_local(self):
        self.tool.run(
            config=(self.yaml_config, self.config),
            verbose=True,
            clobber=False,
            repo_dir=self.working_dir,
            repo_url=self.workspace.working_dir,
            ini_config=self.ini_config,
            ini_section='app:main',
            update_config=True,
            repo_name=None,
            repo_host=None)

        cp = ConfigParser()
        cp.read(self.ini_config)
        self.assertEqual(
            cp.get('app:main', 'unicore.content_repo_urls').strip(),
            os.path.basename(self.workspace.working_dir))

        with open(self.yaml_config, 'r') as fp:
            data = yaml.safe_load(fp)
            repo_name = parse_repo_name(self.workspace.working_dir)
            self.assertEqual(data['repositories'], {
                repo_name: self.workspace.working_dir
            })
Example #11
0
    def test_import_remote(self):
        repo_name = parse_repo_name(self.workspace.working_dir)
        repo_location = 'http://localhost:8080/repos/%s.json' % repo_name
        responses.add_callback(
            responses.POST,
            'http://localhost:8080/repos.json',
            callback=lambda _: (301, {'Location': repo_location}, ''))

        self.tool.run(
            config=(self.yaml_config, self.config),
            verbose=True,
            clobber=False,
            repo_dir=self.working_dir,
            repo_url=self.workspace.working_dir,
            ini_config=self.ini_config,
            ini_section='app:main',
            update_config=True,
            repo_name=None,
            repo_host='http://localhost:8080')

        cp = ConfigParser()
        cp.read(self.ini_config)
        self.assertEqual(
            cp.get('app:main', 'unicore.content_repo_urls').strip(),
            repo_location)

        with open(self.yaml_config, 'r') as fp:
            data = yaml.safe_load(fp)
            self.assertEqual(data['repositories'], {
                repo_name: self.workspace.working_dir
            })
Example #12
0
 def _set_config_all(self, path_to_file):
     out = sys.stdout
     if not os.access(path_to_file, os.R_OK):
         self.log.warning( "cannot access file %s" % path_to_file )
         return
     elif not self.env.config:
         self.log.warning( "cannot access config file trac.ini" )
         return
     
     cfg = ConfigParser()
     cfg.read(path_to_file)
     
     if os.access(self.env.path, os.W_OK):
         path_to_trac_ini = os.path.join(self.env.path, 'conf', 'trac.ini')
         shutil.copy(path_to_trac_ini, path_to_trac_ini + '.bak')
         out.write( "created a backup of trac.ini to %s.bak" % path_to_trac_ini )
         out.write('\n')
     else:
         out.write( "could not create backup of trac.ini - continue anyway? [y|n] "  )
         input = sys.stdin.readline()
         if not input or not input.strip() == 'y':
             return
     
     for sect in cfg.sections():
         for opt in cfg.options(sect):
             self.config.set(sect, opt, cfg.get(sect, opt))
             out.write( "added config [%s] %s = %s" % (sect, opt, cfg.get(sect, opt)) )
             out.write('\n')
     self.config.save()
    def initConfig(self):
        kate.debug("initConfig()")
        config_path = kate.pate.pluginDirectories[1] + "/%s/%s.conf" % (__name__, __name__)
        config_file = QFileInfo(config_path)

        if not config_file.exists():
            open(config_path, "w").close()

        config = ConfigParser()
        config.read(config_path)

        # init the DEFAULT options if they don't exist
        # the DEFAULT section is special and doesn't need to be created: if not config.has_section('DEFAULT'): config.add_section('DEFAULT')
        if not config.has_option("DEFAULT", "ignore"):
            config.set("DEFAULT", "ignore", "")
        if not config.has_option("DEFAULT", "filter"):
            config.set("DEFAULT", "filter", "*")
        if not config.has_option("DEFAULT", "finder_size"):
            config.set("DEFAULT", "finder_size", "400x450")
        if not config.has_option("DEFAULT", "config_size"):
            config.set("DEFAULT", "config_size", "300x350")
        if not config.has_option("DEFAULT", "search_type"):
            config.set("DEFAULT", "search_type", "word")

        # create the general section if it doesn't exist
        if not config.has_section("general"):
            config.add_section("general")

        # flush the config file
        config.write(open(config_path, "w"))

        # save the config object and config path as instance vars for use later
        self.config = config
        self.config_path = config_path
Example #14
0
    def start(self):
        from scheduler import Tree

        loog = self.addLog("stdio")
        self.pending = 0
        properties = self.build.getProperties()
        self.rendered_tree = tree = properties.render(self.treename)
        l10nbuilds = properties.render(self.l10nbuilds)
        cp = ConfigParser()
        cp.read(l10nbuilds)
        repo = cp.get(tree, "repo")
        branch = cp.get(tree, "mozilla")
        path = cp.get(tree, "l10n.ini")
        l10nbranch = cp.get(tree, "l10n")
        locales = cp.get(tree, "locales")
        if locales == "all":
            alllocales = "yes"
        else:
            alllocales = "no"
            properties.update({"locales": filter(None, locales.split())}, "Build")
        self.tree = Tree(self.rendered_tree, repo, branch, l10nbranch, path)
        loog.addStdout("Loading l10n.inis for %s\n" % self.rendered_tree)
        logger.debug(
            "scheduler.l10n.tree", "Loading l10n.inis for %s, alllocales: %s" % (self.rendered_tree, alllocales)
        )
        self.loadIni(repo, branch, path, alllocales)
Example #15
0
	def getConfig(self):
		self.cursor.execute("SELECT name, host, port, account, account_password, base_dn, attr_login, attr_firstname, attr_lastname, attr_mail, tls FROM auth_sources")
		self.results = self.cursor.fetchall()
		dic = {}
		if self.results <> ():
			for i in range(0,11):
				dic[ self.indice[ ( i ) ] ] = self.results[0][i]
			dic["fonte_config"] = "redmine"
			return dic
		else:
			for i in self.indice:
				dic[ i ] = "Sem regsitro"
			from ConfigParser import ConfigParser
			conf = ConfigParser()
			conf.read('/etc/ldap/netcontrol')
			dic["nomeServidor"] = conf.get('base','organization')
			dic["enderecoServidor"] = conf.get('base','server')
			dic["contaLDAP"]        = "cn=admin,%s"%conf.get('base','bindDN')
			dic["baseDN"]           = conf.get('base','bindDN')
			dic["senhaContLDAP"]    = conf.get('base','adminPW')
			dic["email"]     		= conf.get('base','email')
			dic["porta"]			= "389"
			dic["usuario"]	    	= "uid"
			dic["nomeUser"]			= "giverName"
			dic["sobrenome"]		= "sN"
			dic["fonte_config"] = "arquivo_ldap"
			del conf
		return dic
def get_config_parameter(jobname, parameter_name, is_parameter_collection = False):
    """Detect export method of JOBNAME.  Basically, parse JOBNAME.cfg
       and return export_method.  Return None if problem found."""
    jobconfig = ConfigParser()
    jobconffile = CFG_ETCDIR + os.sep + 'bibexport' + os.sep + jobname + '.cfg'

    if not os.path.exists(jobconffile):
        write_message("ERROR: cannot find config file %s." % jobconffile)
        return None

    jobconfig.read(jobconffile)

    if is_parameter_collection:
        all_items = jobconfig.items(section='export_job')

        parameters = []

        for item_name, item_value in all_items:
            if item_name.startswith(parameter_name):
                parameters.append(item_value)

        return parameters
    else:
        parameter = jobconfig.get('export_job', parameter_name)
        return parameter
Example #17
0
    def _load_object_post_as_copy_conf(self, conf):
        if ('object_post_as_copy' in conf or '__file__' not in conf):
            # Option is explicitly set in middleware conf. In that case,
            # we assume operator knows what he's doing.
            # This takes preference over the one set in proxy app
            return

        cp = ConfigParser()
        if os.path.isdir(conf['__file__']):
            read_conf_dir(cp, conf['__file__'])
        else:
            cp.read(conf['__file__'])

        try:
            pipe = cp.get("pipeline:main", "pipeline")
        except (NoSectionError, NoOptionError):
            return

        proxy_name = pipe.rsplit(None, 1)[-1]
        proxy_section = "app:" + proxy_name

        try:
            conf['object_post_as_copy'] = cp.get(proxy_section,
                                                 'object_post_as_copy')
        except (NoSectionError, NoOptionError):
            pass
Example #18
0
 def read_config(self, config_path):
     config_parser = ConfigParser()
     config_parser.read(config_path)
     for section in config_parser.sections():
         for option in config_parser.options(section):
             value = config_parser.get(section, option)
             setattr(self, option, value)
Example #19
0
 def get_mapping_fields(self, cr, uid, shop_id, context=None, reverse=False):
                         
     result = {}
     
     if not context:
         context = {}
         
     shop_pool = self.pool.get('sale.shop')
     shop_data = shop_pool.read(cr, uid, shop_id,
                                ['prestashop_config_path'])
     
     if not shop_data['prestashop_config_path'] or  \
        not shop_data['prestashop_config_path'].endswith(".conf") or\
        not self._prestashop:
         
         return result,False
     
     config = ConfigParser()
     config.read(shop_data['prestashop_config_path'])
     
     if not self._name in config.sections():
         return result,False
     
     mapping = dict(config.items(self._name))
     
     return eval(mapping.get('type_mapping',"[]"))
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 #21
0
File: api.py Project: akurz/cobbler
    def version(self, extended=False):
        """
        What version is cobbler?

        If extended == False, returns a float for backwards compatibility

        If extended == True, returns a dict:

            gitstamp      -- the last git commit hash
            gitdate       -- the last git commit date on the builder machine
            builddate     -- the time of the build
            version       -- something like "1.3.2"
            version_tuple -- something like [ 1, 3, 2 ]
        """
        config = ConfigParser()
        config.read("/etc/cobbler/version")
        data = {}
        data["gitdate"] = config.get("cobbler", "gitdate")
        data["gitstamp"] = config.get("cobbler", "gitstamp")
        data["builddate"] = config.get("cobbler", "builddate")
        data["version"] = config.get("cobbler", "version")
        # dont actually read the version_tuple from the version file
        data["version_tuple"] = []
        for num in data["version"].split("."):
            data["version_tuple"].append(int(num))

        if not extended:
            # for backwards compatibility and use with koan's comparisons
            elems = data["version_tuple"]
            return int(elems[0]) + 0.1 * int(elems[1]) + 0.001 * int(elems[2])
        else:
            return data
Example #22
0
def auth_springpad_client(config_file=None):
    """
    Auth the application to make to be allowed to access to user's springpad
    account. If not a valid config file is provided it will prompt the user to
    visit an url in order to allow the application to access to its account
    and it will store authentication details in `config_file`.
    args:
        config_file: the configuration file path to be used. If it is not
            provided, '~/.springpad' will be used instead.
    returns: SpringpadClient instance to interact with the authenticated
        account.
    """
    config_file = config_file or os.path.expanduser("~/.springpad")
    config = ConfigParser()
    config.read([config_file])
    token = config.get("access", "token") if config.has_option("access", "token") else None
    if token:
        token = oauth.OAuthToken.from_string(token)

    client = SpringpadClient(SPRINGPAD_CONSUMER_KEY, SPRINGPAD_CONSUMER_PRIVATE, token)

    if not client.access_token:
        req_token = client.get_request_token()
        print "Please grant access to your springpad account in the following url:\n"
        print "http://springpad.com/api/oauth-authorize?{0}\n".format(req_token)
        print "Once authorized, press intro to continue:",
        raw_input()
        client.access_token = client.get_access_token(req_token)
        config.add_section("access")
        config.set("access", "token", str(client.access_token))
        with open(os.path.expanduser(config_file), "w") as cf:
            config.write(cf)
    return client
Example #23
0
def sync():
    # Add or replace the relevant properites from galaxy.ini
    # into reports.ini
    reports_config_file = "config/reports.ini"
    if len(argv) > 1:
        reports_config_file = argv[1]

    universe_config_file = "config/galaxy.ini"
    if len(argv) > 2:
        universe_config_file = argv[2]

    parser = ConfigParser()
    parser.read(universe_config_file)

    with open(reports_config_file, "r") as f:
        reports_config_lines = f.readlines()

    replaced_properties = set([])
    with open(reports_config_file, "w") as f:
        # Write all properties from reports config replacing as
        # needed.
        for reports_config_line in reports_config_lines:
            (line, replaced_property) = get_synced_line(reports_config_line, parser)
            if replaced_property:
                replaced_properties.add(replaced_property)
            f.write(line)

        # If any properties appear in universe config and not in
        # reports write these as well.
        for replacement_property in REPLACE_PROPERTIES:
            if parser.has_option(MAIN_SECTION, replacement_property) and \
                    not (replacement_property in replaced_properties):
                f.write(get_universe_line(replacement_property, parser))
Example #24
0
 def startService(self):
     BaseUpstreamScheduler.startService(self)
     log.msg("starting l10n scheduler")
     if self.inipath is None:
         # testing, don't trigger tree builds
         return
     # trigger tree builds for our trees, clear() first
     cp = ConfigParser()
     cp.read(self.inipath)
     self.trees.clear()
     _ds = []
     for tree in cp.sections():
         # create a BuildSet, submit it to the BuildMaster
         props = properties.Properties()
         props.update({
                 'tree': tree,
                 'l10nbuilds': self.inipath,
                 },
                      "Scheduler")
         bs = buildset.BuildSet([self.treebuilder],
                                SourceStamp(),
                                properties=props)
         self.submitBuildSet(bs)
         _ds.append(bs.waitUntilFinished())
     d = defer.DeferredList(_ds)
     d.addCallback(self.onTreesBuilt)
     self.waitOnTree = d
Example #25
0
    def __init__(self, fn):
        p = ConfigParser()
        p.read(fn)

        self._page_store_mongodb_url = p.get("page_store", "mongo_db_url")
        self._cv_page_store_mongodb_url = p.get("cv_page_store", "mongo_db_url")

        self._jd_51job_raw_store_mongo_url = p.get("jd_51job_parse_measure", "jd_raw_store_mongo_url")
        self._jd_51job_measure_store_mongo_url = p.get("jd_51job_parse_measure", "jd_measure_store_mongo_url")

        self._cv_51job_raw_store_mongo_url = p.get("cv_51job_parse_measure", "cv_raw_store_mongo_url")
        self._cv_51job_measure_store_mongo_url = p.get("cv_51job_parse_measure", "cv_measure_store_mongo_url")

        self._jd_zhilian_raw_store_mongo_url = p.get("jd_zhilian_parse_measure", "jd_raw_store_mongo_url")
        self._jd_zhilian_measure_store_mongo_url = p.get("jd_zhilian_parse_measure", "jd_measure_store_mongo_url")

        self._cv_zhilian_raw_store_mongo_url = p.get("cv_zhilian_parse_measure", "cv_raw_store_mongo_url")
        self._cv_zhilian_measure_store_mongo_url = p.get("cv_zhilian_parse_measure", "cv_measure_store_mongo_url")

        self._cv_liepin_raw_store_mongo_url = p.get('cv_liepin_parse_measure', 'cv_raw_store_mongo_url')
        self._cv_liepin_measure_store_mongo_url = p.get('cv_liepin_parse_measure', 'cv_measure_store_mongo_url')

        self._cv_hash_table = p.get('cv_hash_table', 'mongo_db_url')

        self._jd_lagou_raw_store_mongo_url = p.get("jd_lagou_parse_measure", "jd_raw_store_mongo_url")
        self._jd_lagou_measure_store_mongo_url = p.get("jd_lagou_parse_measure", "jd_measure_store_mongo_url")

        self._zhineng_salary5_charts_mongo_url = p.get("zhineng", "zhineng_salary5_charts_mongodb_url")
        self._inc_stats2_mongo_url = p.get("zhineng", "inc_stats2_mongo_url")

        self._2c_ipin_mongo_url = p.get("2c_ipin", "mongo_db_url")
Example #26
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)
def init():

    options.config = os.path.abspath( options.config )
    if options.username == 'all':
        options.username = None
    if options.email == 'all':
        options.email = None

    os.chdir( os.path.dirname( options.config ) )
    sys.path.append( 'lib' )

    from galaxy import eggs
    import pkg_resources

    import galaxy.config
    from galaxy.objectstore import build_object_store_from_config

    # lazy
    globals()['nice_size'] = __import__( 'galaxy.util', globals(), locals(), ( 'nice_size', ) ).nice_size

    config_parser = ConfigParser( dict( here = os.getcwd(),
                                        database_connection = 'sqlite:///database/universe.sqlite?isolation_level=IMMEDIATE' ) )
    config_parser.read( os.path.basename( options.config ) )

    config_dict = {}
    for key, value in config_parser.items( "app:main" ):
        config_dict[key] = value

    config = galaxy.config.Configuration( **config_dict )
    object_store = build_object_store_from_config( config )

    from galaxy.model import mapping

    return mapping.init( config.file_path, config.database_connection, create_tables = False, object_store = object_store ), object_store, config.database_connection.split(':')[0]
Example #28
0
class Config(object):

    _raw_options = ('fetch_command', 'player_command')
    _options = ('media_dir',)
    _expanduser = ('media_dir',)

    def __init__(self, my_file):
        my_file = os.path.expanduser(my_file)
        if not os.path.exists(my_file):
            with codecs.open(my_file, 'w', encoding='utf-8') as fp:
                fp.write(config_file)
            raise MarrieError(
                'Missing config file: %s. It will be created for you.' % my_file)
        self._cp = ConfigParser()
        self._cp.read(my_file)
        for opt in (self._raw_options + self._options):
            if not self._cp.has_option('config', opt):
                raise MarrieError('Missing needed config option: config:%s' \
                                  % opt)

    def __getattr__(self, attr):
        opt = None
        if attr in self._raw_options:
            opt = self._cp.get('config', attr, True)
        elif attr in self._options:
            opt = self._cp.get('config', attr)
        elif attr == 'podcast':
            opt = OrderedDict(self._cp.items('podcast'))
        if opt is None:
            raise AttributeError(attr)
        if attr in self._expanduser and not isinstance(opt, dict):
            return os.path.expanduser(opt)
        return opt
Example #29
0
class SecretSanta(object):
    
    def __init__(self, config):
        log.debug("Constructing SecretSanta main object.")
        self.people = []
        self.givers = []
        self.receivers = []
        self.pcfile = config.get('global','peopleconf')
        log.debug("Peopleconf is %s" % self.pcfile)
        self.pc=ConfigParser()
        self.pc.read(self.pcfile)
        for sect in self.pc.sections():
            p = SecretSantaPerson(sect, self.pc)
            self.people.append(p)
        for p in self.givers:
            self.receivers.append(p)
        
    
    def matchall(self):
        '''
        Perform matching for all people with constraints. 
        '''
        
        rlist = []
        for p in self.people:
            rlist.append(p)
        shuffle(rlist)
        
        log.debug("Performing matching...")
        for p in self.people:
            r = rlist.pop()
            while not p.matchok(r):
                rlist.append(r)
                shuffle(rlist)
                r = rlist.pop()
            p.receiver = r        
            log.debug("%s -> %s\n" % (p.name, p.receiver.name))
    
    def list(self):
        '''
        Return string representation of all people in config.
        '''
        log.debug("List all users...")
        s = ""
        for p in self.people:
            s+= str(p)
        return s    
    
    def giverslist(self):
        '''
        Return string in form of: 
        Joe Bloe -> Mary Margaret
        Mary Margaret -> Susan Strong
        Susan Strong -> Joe Bloe
        
        '''
        s = ""
        for p in self.people:
            s+= "%s -> %s\n" % ( p.name, p.receiver.name)
        return s
Example #30
0
def read_metadata(filename):
    if filename.endswith('bz2'):
        fname = os.path.splitext(filename)[0]
    else:
        fname = filename
    if os.path.splitext(fname)[1] == '.cbf':
        try:
            import pycbf
        except ImportError:
            raise NeXusError('Reading CBF files requires the pycbf module')
        cbf = pycbf.cbf_handle_struct()
        cbf.read_file(fname, pycbf.MSG_DIGEST)
        cbf.select_datablock(0)
        cbf.select_category(0)
        cbf.select_column(1)
        meta_text = cbf.get_value().splitlines()
        date_string = meta_text[2][2:]
        time_stamp = epoch(date_string)
        exposure = float(meta_text[5].split()[2])
        summed_exposures = 1
        return time_stamp, exposure, summed_exposures
    elif os.path.exists(fname+'.metadata'):
        parser = ConfigParser()
        parser.read(fname+'.metadata')
        return (parser.getfloat('metadata', 'timeStamp'),
                parser.getfloat('metadata', 'exposureTime'),
                parser.getint('metadata', 'summedExposures'))
    else:
        return time.time(), 1.0, 1