本文整理汇总了Python中config.config.Config类的典型用法代码示例。如果您正苦于以下问题:Python Config类的具体用法?Python Config怎么用?Python Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Config类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: device_manager
def device_manager(context):
global manager
global publisher
worker_address = Config.get('services', 'worker_address')
worker_port = Config.get('services', 'worker_port')
worker_address = "tcp://" + worker_address + ":" + worker_port
publisher_address = Config.get('device_service', 'publisher_address')
publisher_port = Config.get('device_service', 'publisher_port')
publisher_address = "tcp://" + publisher_address + ":" + publisher_port
service = Config.get('device_service', 'service_name')
publisher = DeviceServicePublisher(context, publisher_address)
manager = DeviceServiceManager(context, worker_address, service)
try:
IOLoop.instance().start()
except KeyboardInterrupt:
IOLoop.instance().stop()
publisher.shutdown()
manager.shutdown()
return
示例2: get_old_articles_for_query
def get_old_articles_for_query(query):
"""
Fetches items for a query that are older than the oldest item that has
already been fetched.
"""
logging.error("$$$$ nytArticles.get_old_articles_for_query[]")
n_to_fetch = 10
query.doc['n_fetched'] = query.doc['n_fetched'] + n_to_fetch
n_requests = int(math.ceil(n_to_fetch / int(Config.get("nyt_article")["response_size"])))
if n_requests == 0:
n_requests = 1
prior_cached = len(query.children)
logging.error(prior_cached)
prior_offset = int(int(prior_cached) / int(Config.get("nyt_article")["response_size"]))
logging.error(prior_offset)
req_pars = {
'query_id': query.id(),
'functions': [api.make_api_request,cache_response,fetch_comments]
}
for i in range(0,n_requests):
request = {}
for k,v in req_pars.iteritems():
request[k] = v
request['url'] = 'http://api.nytimes.com/svc/search/v1/article?query=text:'+query.doc['query_text'].replace(' ','+')+'+comments:y'
request['url'] = request['url'] + '&offset='+str(int(prior_offset) + int(i))
request['url'] = request['url'] + '&fields=body,byline,date,title,url,geo_facet,per_facet,des_facet,org_facet'
request['url'] = request['url'] + '&api-key='+Config.get('nyt_article')['key']
#logging.critical('BSM[get_old_articles_for_query] Size:'+str(sys.getsizeof(pickle.dumps(request))))
with voxpop.VPE.beanstalkd_lock:
voxpop.VPE.get_beanstalkd().use("nytarticle")
voxpop.VPE.get_beanstalkd().put(pickle.dumps(request), pri=100000)
query.save()
return query
示例3: test_load_from_exports
def test_load_from_exports(self):
# grab the file as needed
Config._load_exports(fixtures.EXPORTS)
assert hasattr(Config, "PATH")
assert hasattr(Config, "UNDEFINED") == False
示例4: import_tournament
def import_tournament(type, path, bracket, region, name):
config = Config()
mongo_client = MongoClient(host=config.get_mongo_url())
if type == 'tio':
scraper = TioScraper(path, bracket)
elif type =='challonge':
scraper = ChallongeScraper(path)
else:
click.echo("Illegal type")
dao = Dao(region, mongo_client=mongo_client)
player_map = get_player_alias_to_id_map(scraper, dao)
# TODO pass in a map of overrides for specific players
tournament = Tournament.from_scraper(type, scraper, player_map, region)
if name:
tournament.name = name
dao.insert_tournament(tournament)
click.echo("Generating new ranking...")
rankings.generate_ranking(dao)
click.echo("Done!")
示例5: setUpClass
def setUpClass(cls):
super(TestVolume,cls).setUpClass()
cls.host = FixtureFactory(cls.api).create_host_with_depends(Config.get_instance().hosts[0].create()).host
result = FixtureFactory(cls.api).create_host_with_depends(Config.get_instance().hosts[1].create())
cls.host2 = result.host
cls.cluster = result.cluster
cls.datacenter = result.datacenter
示例6: setUp
def setUp(self):
self.api = TestBase.api
self.host = FixtureFactory(self.api).create_host_with_depends(Config.get_instance().hosts[0].create()).host
result = FixtureFactory(api).create_host_with_depends(Config.get_instance().hosts[1].create())
self.host2 = result.host
self.cluster = result.cluster
self.datacenter = result.datacenter
self.vol = create_distributed_volume()
VolumePopulator().fileForEachBrick(volume)
示例7: test_load_from_json
def test_load_from_json(self):
# ensure that the json was parsed properly
json_config = json.loads(fixtures.JSON)
Config._load_json(fixtures.JSON)
for key, value in json_config.iteritems():
assert hasattr(Config, key)
assert getattr(Config, key) == value
示例8: get_connection
def get_connection():
config = Config()
mysql_config = {
'user': config.get_db_user(),
'password': config.get_db_password(),
'host': config.get_db_host(),
'database': config.get_db_name()
}
return mysql.connector.connect(**mysql_config)
示例9: test_load_from_yaml
def test_load_from_yaml(self):
# parse the yaml file
yaml_config = yaml.load(fixtures.YAML)
Config._load_yaml(fixtures.YAML)
for key, value in yaml_config.iteritems():
assert hasattr(Config, key)
assert getattr(Config, key) == value
示例10: refresh_device
def refresh_device(device):
address = Config.get('services', 'client_address')
port = Config.get('services', 'client_port')
address = "tcp://" + address + ":" + port
socket = zmq.Context().socket(zmq.REQ)
socket.setsockopt(zmq.LINGER, 0)
socket.connect(address)
message = ['00000000', 'control', 'refresh', device]
mdp_request(socket, 'device', message, 1)
示例11: TestConfig
class TestConfig(unittest.TestCase):
def setUp(self):
self.config = Config(TEMPLATE_CONFIG_FILE)
def test_get_mongo_url(self):
self.assertEquals(self.config.get_mongo_url(), 'mongodb://USER:[email protected]/AUTH_DB')
def test_get_db_host(self):
self.assertEquals(self.config.get_db_host(), 'HOSTNAME')
def test_get_auth_db_name(self):
self.assertEquals(self.config.get_auth_db_name(), 'AUTH_DB')
def test_get_db_user(self):
self.assertEquals(self.config.get_db_user(), 'USER')
def test_get_db_password(self):
self.assertEquals(self.config.get_db_password(), 'PASSWORD')
def test_challonge_api_key(self):
self.assertEquals(self.config.get_challonge_api_key(), 'API_KEY')
def test_get_fb_app_id(self):
self.assertEquals(self.config.get_fb_app_id(), 'FB_APP_ID')
def test_get_fb_app_token(self):
self.assertEquals(self.config.get_fb_app_token(), 'FB_APP_TOKEN')
示例12: __init__
def __init__(self):
# regular expressions:
# regexp denoting successful collection index/directory listing save:
self.cindex = re.compile(r'(index|listing).*saved')
# regexp for timestamp string containing an 'http' hdf (or xml) target:
self.timestamp = r'--\d{4}-\d{2}-\d{2} *\d{2}:\d{2}:\d{2}--'
self.target = r'(http|ftp).*\.(hdf|nc).*$'
self.regex_save_loc = ".*('/.*/.*') saved.*"
self.timestamp_and_target = re.compile( self.timestamp + ' *' + '(' + self.target + ')') # save target as group
self.regex_saved_file_loc = re.compile(r'=> (\'.*\')')
# regexp denoting target was successfully downloaded (saved):
self.saved = re.compile(r'saved')
# regexp denoting overall completion:
self.finished = re.compile(r'FINISHED')
# regex for 'Remote file no newer than local file'
self.regex_no_retrieve = re.compile(r'Remote file no newer than local file*not retrieving\.')
# regex for 'failed: Network is unreachable'
self.regex_unreachable_network = re.compile(r'Connecting.*failed: Network is unreachable')
self.download_list = []
self.saved_file_locs = []
self.summary = 'Wget Log Summary (' + str(date.today()) + '):*************************************************************************\n\n'
self.config = Config()
示例13: fetch_comments_for_article_id
def fetch_comments_for_article_id(pars={}, **kwargs):
if "article_id" not in pars:
logging.error("**** nytCommunity.fetch_comments_for_article: NO ARTICLE ID PROVIDED")
return False
if "article_url" not in pars:
logging.error("**** nytCommunity.fetch_comments_for_article: NO ARTICLE URL PROVIDED")
return False
logging.info(
"$$$$ nytCommunity.fetch_comments_for_article_id[id:" + pars["article_id"] + ",url:" + pars["article_url"] + "]"
)
_url = "http://api.nytimes.com/svc/community/v2/comments/url/exact-match.json?"
_url = _url + "url=" + urllib.quote_plus(pars["article_url"])
_url = _url + "&sort=oldest"
_url = _url + "&api-key=" + Config.get("nyt_community")["key"]
request = {
"url": _url,
"article_id": pars["article_id"],
"article_url": pars["article_url"],
"functions": [api.make_api_request, fetch_remainder],
}
# logging.critical('BSM[fetch_comments_for_article_id] Size:'+str(sys.getsizeof(pickle.dumps(request))))
with voxpop.VPE.beanstalkd_lock:
voxpop.VPE.get_beanstalkd().use("nytcommunity")
voxpop.VPE.get_beanstalkd().put(pickle.dumps(request), pri=100000)
return True
示例14: inject_details
def inject_details():
g.devices = db_session.query(Device).order_by(Device.creation_time.desc())\
.all()
g.connected_devices = []
g.configured_devices = []
g.new_devices = []
g.grainbin_service = Config.getboolean('services', 'grainbin_service')
if g.grainbin_service:
g.grainbins = []
g.configured_grainbins = []
g.new_grainbins = []
for dev in g.devices:
if dev.connected:
g.connected_devices.append(dev)
if dev.user_configured:
g.configured_devices.append(dev)
else:
g.new_devices.append(dev)
if g.grainbin_service:
if dev.user_configured:
bins = dev.bins
g.grainbins.extend(bins)
for grainbin in bins:
if grainbin.user_configured:
g.configured_grainbins.append(grainbin)
else:
g.new_grainbins.append(grainbin)
return dict()
示例15: ChallongeScraper
class ChallongeScraper(object):
def __init__(self, tournament_id):
self.tournament_id = tournament_id
self.config = Config(config_file_path=CONFIG_FILE_PATH)
self.api_key = self.config.get_challonge_api_key()
self.api_key_dict = {'api_key': self.api_key}
self.raw_dict = None
self.get_raw()
def get_raw(self):
if self.raw_dict == None:
self.raw_dict = {}
url = TOURNAMENT_URL % self.tournament_id
self.raw_dict['tournament'] = self._check_for_200(requests.get(url, params=self.api_key_dict)).json()
url = MATCHES_URL % self.tournament_id
self.raw_dict['matches'] = self._check_for_200(requests.get(url, params=self.api_key_dict)).json()
url = PARTICIPANTS_URL % self.tournament_id
self.raw_dict['participants'] = self._check_for_200(requests.get(url, params=self.api_key_dict)).json()
return self.raw_dict
def get_name(self):
return self.get_raw()['tournament']['tournament']['name'].strip()
def get_date(self):
return iso8601.parse_date(self.get_raw()['tournament']['tournament']['created_at'])
def get_matches(self):
player_map = dict((p['participant']['id'], p['participant']['name'].strip()
if p['participant']['name']
else p['participant']['username'].strip())
for p in self.get_raw()['participants'])
matches = []
for m in self.get_raw()['matches']:
m = m['match']
winner_id = m['winner_id']
loser_id = m['loser_id']
if winner_id is not None and loser_id is not None:
winner = player_map[winner_id]
loser = player_map[loser_id]
match_result = MatchResult(winner=winner, loser=loser)
matches.append(match_result)
return matches
def get_players(self):
return [p['participant']['name'].strip() if p['participant']['name'] else p['participant']['username'].strip() \
for p in self.get_raw()['participants']]
def _check_for_200(self, response):
if response.status_code != 200:
raise Exception('Received status code of %d' % response.status_code)
return response