本文整理汇总了Python中DAS.utils.logger.PrintManager类的典型用法代码示例。如果您正苦于以下问题:Python PrintManager类的具体用法?Python PrintManager怎么用?Python PrintManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PrintManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_error
def test_error(self):
"Test logger error method"
old_stdout = sys.stdout
logger = PrintManager(self.name) # verbose is irrelevant
sys.stdout = StringIO()
logger.error('test')
result = sys.stdout.getvalue()
expect = 'ERROR %s:%s test\n' % (self.name, funcname())
self.assertEqual(expect, result)
sys.stdout = old_stdout
示例2: test_warning
def test_warning(self):
"Test logger warning method"
old_stdout = sys.stdout
logger = PrintManager(self.name) # verbose is irrelevant
sys.stdout = StringIO()
logger.warning('test')
result = sys.stdout.getvalue()
expect = 'WARNING %s:%s test\n' % (self.name, funcname())
self.assertEqual(expect, result)
sys.stdout = old_stdout
示例3: test_debug
def test_debug(self):
"Test logger debug method"
old_stdout = sys.stdout
logger = PrintManager(self.name, verbose=2)
sys.stdout = StringIO()
logger.debug('test')
result = sys.stdout.getvalue()
expect = 'DEBUG %s:%s test\n' % (self.name, funcname())
self.assertEqual(expect, result)
sys.stdout = old_stdout
示例4: test_info
def test_info(self):
"Test logger info method"
old_stdout = sys.stdout
logger = PrintManager(self.name, verbose=1)
sys.stdout = StringIO()
logger.info('test')
result = sys.stdout.getvalue()
expect = 'INFO %s:%s test\n' % (self.name, funcname())
self.assertEqual(expect, result)
sys.stdout = old_stdout
示例5: QueryRunner
class QueryRunner(object):
"Replaces das_robot"
task_options = [{'name':'query', 'type':'string', 'default':None,
'help':'Query to issue using das_core::call'}]
def __init__(self, **kwargs):
self.logger = PrintManager('QueryRunner', kwargs.get('verbose', 0))
self.das = kwargs['DAS']
self.dasquery = DASQuery(kwargs['dasquery'])
def __call__(self):
"__call__ implementation"
self.logger.info("Issuing query %s" % self.dasquery)
result = self.das.call(self.dasquery, add_to_analytics=False)
return {'result':result}
示例6: __init__
def __init__(self, config=None):
if not config:
config = das_readconfig()
if not config.has_key('dasmapping'):
config['dasmapping'] = DASMapping(config)
if not config.has_key('dasanalytics'):
config['dasanalytics'] = DASAnalytics(config)
if not config['dasmapping'].check_maps():
msg = "No DAS maps found in MappingDB"
raise Exception(msg)
self.map = config['dasmapping']
self.analytics = config['dasanalytics']
self.dasservices = config['services']
self.daskeysmap = self.map.daskeys()
self.operators = list(das_operators())
self.daskeys = list(das_special_keys())
self.verbose = config['verbose']
self.logger = PrintManager('QLManger', self.verbose)
for val in self.daskeysmap.values():
for item in val:
self.daskeys.append(item)
parserdir = config['das']['parserdir']
self.dasply = DASPLY(parserdir, self.daskeys, self.dasservices,
verbose=self.verbose)
self.enabledb = config['parserdb']['enable']
if self.enabledb:
self.parserdb = DASParserDB(config)
示例7: __init__
def __init__(self, **kwargs):
self.key = kwargs['key']
self.logger = PrintManager('ValueHotspot', kwargs.get('verbose', 0))
self.allow_wildcarding = kwargs.get('allow_wildcarding', False)
self.find_supersets = kwargs.get('find_supersets', False)
self.preempt = int(kwargs.get('preempt', 60))
self.fields = kwargs.get('fields', None)
self.instance = kwargs.get('instance', 'cms_dbs_prod_global')
HotspotBase.__init__(self,
identifier="valuehotspot-%s" % \
(self.key.replace('.','-')),
**kwargs)
# set fields if look-up key is present
if not self.fields and self.key:
self.fields = [self.key.split('.')[0]]
# finally if fields is not yet set, look-up all DAS keys allowed
# for given query
if not self.fields:
try:
self.fields = set()
self.das.mapping.init_presentationcache()
plist = self.das.mapping.presentation(self.key.split('.', 1)[0])
for item in plist:
if 'link' in item:
for link in item['link']:
if len(link['query'].split(' ')) == 2:
self.fields.add(link['query'].split(' ')[0])
self.fields.add(self.key.split('.', 1)[0])
self.fields = list(self.fields)
except:
self.fields = []
示例8: __init__
def __init__(self, name, config):
self.name = name
try:
self.verbose = config['verbose']
title = 'DASAbstactService_%s' % self.name
self.logger = PrintManager(title, self.verbose)
self.dasmapping = config['dasmapping']
self.analytics = config['dasanalytics']
self.write2cache = config.get('write_cache', True)
self.multitask = config['das'].get('multitask', True)
self.error_expire = config['das'].get('error_expire', 300)
if config.has_key('dbs'):
self.dbs_global = config['dbs'].get('dbs_global_instance', None)
else:
self.dbs_global = None
dburi = config['mongodb']['dburi']
engine = config.get('engine', None)
self.gfs = db_gridfs(dburi)
except Exception as exc:
print_exc(exc)
raise Exception('fail to parse DAS config')
# read key/cert info
try:
self.ckey, self.cert = get_key_cert()
except Exception as exc:
print_exc(exc)
self.ckey = None
self.cert = None
if self.multitask:
nworkers = config['das'].get('api_workers', 3)
thr_weights = config['das'].get('thread_weights', [])
for system_weight in thr_weights:
system, weight = system_weight.split(':')
if system == self.name:
nworkers *= int(weight)
if engine:
thr_name = 'DASAbstractService:%s:PluginTaskManager' % self.name
self.taskmgr = PluginTaskManager(\
engine, nworkers=nworkers, name=thr_name)
self.taskmgr.subscribe()
else:
thr_name = 'DASAbstractService:%s:TaskManager' % self.name
self.taskmgr = TaskManager(nworkers=nworkers, name=thr_name)
else:
self.taskmgr = None
self.map = {} # to be defined by data-service implementation
self._keys = None # to be defined at run-time in self.keys
self._params = None # to be defined at run-time in self.parameters
self._notations = {} # to be defined at run-time in self.notations
self.logger.info('initialized')
# define internal cache manager to put 'raw' results into cache
if config.has_key('rawcache') and config['rawcache']:
self.localcache = config['rawcache']
else:
msg = 'Undefined rawcache, please check your configuration'
raise Exception(msg)
示例9: __init__
def __init__(self, **kwargs):
self.logger = PrintManager('HotspotBase', kwargs.get('verbose', 0))
self.das = kwargs['DAS']
self.fraction = float(kwargs.get('fraction', 0.15))
self.mode = kwargs.get('mode','calls').lower()
self.period = int(kwargs.get('period', 86400*30))
self.interval = kwargs['interval']
self.allowed_gap = int(kwargs.get('allowed_gap', 3600))
self.identifier = kwargs['identifier']
示例10: __init__
def __init__(self, config):
self.verbose = config['verbose']
self.logger = PrintManager('DASParserDB', self.verbose)
self.dburi = config['mongodb']['dburi']
self.dbname = config['parserdb']['dbname']
self.sizecap = config['parserdb'].get('sizecap', 5*1024*1024)
self.colname = config['parserdb']['collname']
msg = "DASParserCache::__init__ %[email protected]%s" % (self.dburi, self.dbname)
self.logger.info(msg)
self.create_db()
示例11: __init__
def __init__(self, config):
self.verbose = config['verbose']
self.logger = PrintManager('DASAnalytics', self.verbose)
self.dburi = config['mongodb']['dburi']
self.dbname = config['analyticsdb']['dbname']
self.colname = config['analyticsdb']['collname']
self.history = config['analyticsdb']['history']
msg = "%[email protected]%s" % (self.dburi, self.dbname)
self.logger.info(msg)
self.create_db()
示例12: __init__
def __init__(self, name, config):
self.name = name
try:
self.verbose = config["verbose"]
title = "DASAbstactService_%s" % self.name
self.logger = PrintManager(title, self.verbose)
self.dasmapping = config["dasmapping"]
self.write2cache = config.get("write_cache", True)
self.multitask = config["das"].get("multitask", True)
self.error_expire = config["das"].get("error_expire", 300)
self.dbs_global = None # to be configured at run time
self.dburi = config["mongodb"]["dburi"]
engine = config.get("engine", None)
self.gfs = db_gridfs(self.dburi)
except Exception as exc:
print_exc(exc)
raise Exception("fail to parse DAS config")
# read key/cert info
try:
self.ckey, self.cert = get_key_cert()
except Exception as exc:
print_exc(exc)
self.ckey = None
self.cert = None
if self.multitask:
nworkers = config["das"].get("api_workers", 3)
thr_weights = config["das"].get("thread_weights", [])
for system_weight in thr_weights:
system, weight = system_weight.split(":")
if system == self.name:
nworkers *= int(weight)
if engine:
thr_name = "DASAbstractService:%s:PluginTaskManager" % self.name
self.taskmgr = PluginTaskManager(engine, nworkers=nworkers, name=thr_name)
self.taskmgr.subscribe()
else:
thr_name = "DASAbstractService:%s:TaskManager" % self.name
self.taskmgr = TaskManager(nworkers=nworkers, name=thr_name)
else:
self.taskmgr = None
self.map = {} # to be defined by data-service implementation
self._keys = None # to be defined at run-time in self.keys
self._params = None # to be defined at run-time in self.parameters
self._notations = {} # to be defined at run-time in self.notations
self.logger.info("initialized")
# define internal cache manager to put 'raw' results into cache
if "rawcache" in config and config["rawcache"]:
self.localcache = config["rawcache"]
else:
msg = "Undefined rawcache, please check your configuration"
raise Exception(msg)
示例13: __init__
def __init__(self, config):
self.verbose = config['verbose']
self.logger = PrintManager('DASKeyLearning', self.verbose)
self.services = config['services']
self.dburi = config['mongodb']['dburi']
self.dbname = config['keylearningdb']['dbname']
self.colname = config['keylearningdb']['collname']
self.mapping = config['dasmapping']
msg = "%[email protected]%s" % (self.dburi, self.dbname)
self.logger.info(msg)
self.col = None
self.create_db()
示例14: __init__
def __init__(self, config):
self.verbose = config['verbose']
self.logger = PrintManager('DASKeyLearning', self.verbose)
self.services = config['services']
self.dburi = config['mongodb']['dburi']
self.dbname = config['keylearningdb']['dbname']
self.colname = config['keylearningdb']['collname']
self.mapping = config['dasmapping']
msg = "%[email protected]%s" % (self.dburi, self.dbname)
self.logger.info(msg)
self.das_son_manipulator = DAS_SONManipulator()
index_list = [('system', ASCENDING), ('urn', ASCENDING), \
('members', ASCENDING), ('stems', ASCENDING)]
create_indexes(self.col, index_list)
示例15: __init__
def __init__(self, config):
self.verbose = config["verbose"]
self.logger = PrintManager("DASMapping", self.verbose)
self.services = config["services"]
self.dburi = config["mongodb"]["dburi"]
self.dbname = config["mappingdb"]["dbname"]
self.colname = config["mappingdb"]["collname"]
self.map_test = config.get("map_test", True)
self.main_dbs = config["das"].get("main_dbs", "dbs")
self.dbsinsts = config["das"].get("dbs_instances", [])
msg = "%[email protected]%s" % (self.dburi, self.dbname)
self.logger.info(msg)
self.init()
self.on_reload = Event()
# Monitoring thread which performs auto-reconnection to MongoDB
thname = "mappingdb_monitor"
sleep = 5
reload_time = config["mappingdb"].get("reload_time", 86400)
reload_time_bad_maps = config["mappingdb"].get("reload_time_bad_maps", 120)
start_new_thread(
thname,
db_monitor,
(self.dburi, self.init, sleep, self.load_maps, reload_time, self.check_maps, reload_time_bad_maps),
)
self.daskeyscache = {} # to be filled at run time
self.systems = [] # to be filled at run time
self.dasmapscache = {} # to be filled at run time
self.keymap = {} # to be filled at run time
self.presentationcache = {} # to be filled at run time
self.reverse_presentation = {} # to be filled at run time
self.notationcache = {} # to be filled at run time
self.diffkeycache = {} # to be filled at run time
self.apicache = {} # to be filled at run time
self.dbs_global_url = None # to be determined at run time
self.dbs_inst_names = None # to be determined at run time
self.load_maps(notify=False)