本文整理汇总了Python中socorro.lib.ConfigurationManager类的典型用法代码示例。如果您正苦于以下问题:Python ConfigurationManager类的具体用法?Python ConfigurationManager怎么用?Python ConfigurationManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConfigurationManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
"""Create a configuration context and a database connection. """
self.config = ConfigurationManager.newConfiguration(
configurationModule=commonconfig, applicationName="PostgreSQL Tests"
)
try:
self.database = db.Database(self.config)
except (AttributeError, KeyError):
raise
self.connection = self.database.connection()
示例2: __init__
def __init__(self,*args,**kwargs):
"""
Passes appropriate kwargs to Config, pays local attention to these keys:
updateInterval: default: '0' format: 'dd:hh:mm:ss', leading parts optional. Must be >= 0 seconds.
updateFunction: default: noop(). Takes self as argument. Behavior: Updates default values in argument
reEvaluateFunction: default: noop(). Takes self as argument. Behavior: Mutates values in argument
signalNumber: default: SIGALRM (14). If 0, then signals will not be handled.
Instances that share the same signalNumber will all be update()-ed at every signal.
self.internal.updateFunction may be set after construction if desired: Avoids double-work at construction
self.internal.reEvalutateFunction may be set after construction if desired, but this is not recommended.
"""
skwargs = dict([(x,kwargs[x]) for x in socorro_config.getDefaultedConfigOptions().keys() if x in kwargs])
for i in range(len(args)):
skwargs[socorro_config.namedConfigOptions[i]] = args[i]
super(DynamicConfig,self).__init__(**skwargs)
self.internal.updateFunction = kwargs.get('updateFunction',noop)
self.internal.reEvaluateFunction = kwargs.get('reEvaluateFunction',noop)
self.internal.signalNumber = kwargs.get('signalNumber',14)
self.internal.nextUpdate = None
updateInterval = kwargs.get('updateInterval','0:0:0:0')
self.internal.updateDelta = socorro_config.timeDeltaConverter(updateInterval)
if self.internal.updateDelta:
if self.internal.updateDelta < datetime.timedelta(0):
raise ValueError("updateInterval must be non-negative, but %s"%self.internal.updateDelta)
self.internal.nextUpdate = utc_now() + self.internal.updateDelta
# finally: make sure we are current
if self.internal.signalNumber:
priorSignal = signal.signal(self.internal.signalNumber,DynamicConfig.handleAlarm)
self.doUpdate()
DynamicConfig.instances[id(self)] = self
示例3: testAcceptConfigFile
def testAcceptConfigFile(self):
# Test failure with good config file, unknown option in that file
try:
copt = [('c', 'config', True, self.configTstPath, "the test config file")]
CM.newConfiguration(configurationOptionsList=copt,optionNameForConfigFile = 'config', configurationFileRequired = True)
assert(False)
except CM.NotAnOptionError, e:
assert(True)
示例4: getProcessingWindow
def getProcessingWindow(configContext,tableName, productVersionRestriction,cursor,logger, **kwargs):
"""
ProcessingWindow is a single time window over which to aggregate materialized view data.
Returns (startWindow,deltaWindow,endWindow) using this heuristic:
kwargs beats configContext which beats latest table row
if two among startWindow, endWindow, deltaWindow in config or kwargs: they are used.
if all three: assert startWindow + deltaWindow == endWindow
Backward compatibility: if processingDay is present and windowXxx are not:
startWindow = midnight of given day, deltaWindow = timedelta(days=1)
else: try to read window_end and window_size from the given table
if one is available from config/kwargs it beats the same (or calculated) one from the table
On inconsistency or failure, logs the problem and aborts
BEWARE: You can get inconsitency by having one item in config and the other two in kwargs: BEWARE
"""
config = {}
config.update(configContext)
config.update(kwargs)
startWindow = config.get('startWindow')
if type(startWindow) is str:
startWindow = cm.dateTimeConverter(startWindow)
deltaWindow = config.get('deltaWindow')
if type(deltaWindow) is str:
deltaWindow = cm.timeDeltaConverter(deltaWindow)
endWindow = config.get('endWindow')
if type(endWindow) is str:
endWindow = cm.dateTimeConverter(endWindow)
processingDay = config.get('processingDay')
if type(processingDay) is str:
processingDay = cm.dateTimeConverter(processingDay)
try:
if startWindow or deltaWindow or endWindow:
if startWindow and endWindow and deltaWindow:
assert startWindow + deltaWindow == endWindow,"inconsistent: %s + %s != %s"%(startWindow,deltaWindow,endWindow)
elif startWindow and endWindow:
deltaWindow = endWindow - startWindow
elif startWindow and deltaWindow:
endWindow = startWindow + deltaWindow
elif deltaWindow and endWindow:
startWindow = endWindow - deltaWindow
else:
assert not (startWindow or deltaWindow or endWindow), "insufficient: Need two of window ...Start: %s, ...Delta: %s, ...End:%s"%(startWindow,deltaWindow,endWindow)
elif processingDay:
dayt = datetime.datetime.fromtimestamp(time.mktime(processingDay.timetuple()))
startWindow = dayt.replace(hour=0,minute=0,second=0,microsecond=0)
assert startWindow == dayt,'processingDay must be some midnight, but was %s'%dayt
deltaWindow = datetime.timedelta(days=1)
endWindow = startWindow + deltaWindow
else: # no params: try table
startWindow,deltaWindow = getLastWindowAndSizeFromTable(cursor,tableName, productVersionRestriction,logger)
if startWindow:
endWindow = startWindow+deltaWindow
return (startWindow,deltaWindow,endWindow)
except:
lib_util.reportExceptionAndAbort(logger)
示例5: newConfiguration
def newConfiguration(**kwargs):
""" This used as an alternate constructor for class Config so that applications can
be lax in defining all the required paramters in the right order.
"""
kw = socorro_config.getDefaultedConfigOptions()
kw.update(kwargs)
return DynamicConfig(**kw)
示例6: main
def main():
logger = logging.getLogger("topcrashes_summary")
logger.setLevel(logging.WARNING)
stderrLog = logging.StreamHandler()
stderrLog.setLevel(logging.WARNING)
stderrLogFormatter = logging.Formatter('%(asctime)s %(levelname)s - %(message)s')
stderrLog.setFormatter(stderrLogFormatter)
logger.addHandler(stderrLog)
kwargs = {}
for i in sys.argv[1:]:
if i.startswith('-h') or i.startswith('--he'):
help()
sys.exit(0)
j = i
if i.startswith('-'):
j = i.lstrip('-')
if '=' in j:
name,value = (s.strip() for s in j.split('='))
kwargs[name] = value
else:
print >> sys.stderr,"Ignoring unkown argument '%s'"%(i)
sys.argv = sys.argv[:1]
config = configurationManager.newConfiguration(configurationModule = testConfig, applicationName='Create Database')
config.update(kwargs)
testDB = TestDB()
testDB.removeDB(config,logger)
testDB.createDB(config,logger)
示例7: setup_module
def setup_module():
global me
if me:
return
# else initialize
# print "MODULE setup"
me = Me()
me.markingTemplate = "MARK %s: %s"
me.startMark = 'start'
me.endMark = 'end'
me.testDB = TestDB()
me.config = configurationManager.newConfiguration(configurationModule = testConfig, applicationName='Testing Monitor')
myDir = os.path.split(__file__)[0]
if not myDir: myDir = '.'
replDict = {'testDir':'%s'%myDir}
for i in me.config:
try:
me.config[i] = me.config.get(i)%(replDict)
except:
pass
knownTests = [x for x in dir(TestMonitor) if x.startswith('test')]
me.logWasExtracted = {}
for t in knownTests:
me.logWasExtracted[t] = False
me.logger = monitor.logger
me.logger.setLevel(logging.DEBUG)
me.logFilePathname = me.config.logFilePathname
logfileDir = os.path.split(me.config.logFilePathname)[0]
try:
os.makedirs(logfileDir)
except OSError,x:
if errno.EEXIST != x.errno: raise
示例8: setup_module
def setup_module():
global me
if me:
return
me = Me()
me.config = cfgManager.newConfiguration(configurationModule=testConfig,
applicationName='Testing ftpscraper')
myDir = os.path.split(__file__)[0]
if not myDir:
myDir = '.'
replDict = {'testDir': '%s' % myDir}
for i in me.config:
try:
me.config[i] = me.config.get(i) % (replDict)
except:
pass
me.logFilePathname = me.config.logFilePathname
if not me.logFilePathname:
me.logFilePathname = 'logs/ftpscraper_test.log'
logFileDir = os.path.split(me.logFilePathname)[0]
try:
os.makedirs(logFileDir)
except OSError, x:
if errno.EEXIST == x.errno:
pass
else:
raise
示例9: setup_module
def setup_module():
global me
if me:
return
me = Me()
tutil.nosePrintModule(__file__)
me.config = configurationManager.newConfiguration(
configurationModule=testConfig, applicationName="Testing Postgresql Utils"
)
myDir = os.path.split(__file__)[0]
if not myDir:
myDir = "."
replDict = {"testDir": "%s" % myDir}
for i in me.config:
try:
me.config[i] = me.config.get(i) % (replDict)
except:
pass
me.logFilePathname = me.config.logFilePathname
if not me.logFilePathname:
me.logFilePathname = "logs/db_test.log"
logFileDir = os.path.split(me.logFilePathname)[0]
try:
os.makedirs(logFileDir)
except OSError, x:
if errno.EEXIST == x.errno:
pass
else:
raise
示例10: setup_module
def setup_module():
global me
if me:
return
me = Me()
tutil.nosePrintModule(__file__)
# config gets messed up by some tests. Use this one during module setup and teardown
me.config = configurationManager.newConfiguration(configurationModule = testConfig, applicationName='Testing Postgresql Utils')
myDir = os.path.split(__file__)[0]
if not myDir: myDir = '.'
replDict = {'testDir':'%s'%myDir}
for i in me.config:
try:
me.config[i] = me.config.get(i)%(replDict)
except:
pass
me.logFilePathname = me.config.logFilePathname
if not me.logFilePathname:
me.logFilePathname = 'logs/db_test.log'
logFileDir = os.path.split(me.logFilePathname)[0]
try:
os.makedirs(logFileDir)
except OSError,x:
if errno.EEXIST == x.errno: pass
else: raise
示例11: setup_module
def setup_module():
global me
if me:
return
me = Me()
tutil.nosePrintModule(__file__)
me.testDB = TestDB()
me.config = configurationManager.newConfiguration(configurationModule = testConfig, applicationName='TestingCachedIdAccess')
myDir = os.path.split(__file__)[0]
if not myDir: myDir = '.'
replDict = {'testDir':'%s'%myDir}
for i in me.config:
try:
me.config[i] = me.config.get(i)%(replDict)
except:
pass
cia.logger.setLevel(logging.DEBUG)
me.logFilePathname = me.config.logFilePathname
logfileDir = os.path.split(me.config.logFilePathname)[0]
try:
os.makedirs(logfileDir)
except OSError,x:
if errno.EEXIST != x.errno: raise
f = open(me.config.logFilePathname,'w')
f.close()
示例12: setupConfig
def setupConfig():
try:
return configurationManager.newConfiguration(configurationModule=config, applicationName="Migrate Process Type")
except configurationManager.NotAnOptionError, x:
print >>sys.stderr, x
print >>sys.stderr, "for usage, try --help"
sys.exit(1)
示例13: fixupContextByProcessingDay
def fixupContextByProcessingDay(self,context):
pday = context.get('processingDay')
if pday:
logger.info("Adjusting startDate and deltaDate per processingDay %s",pday)
pday = cm.dateTimeConverter(pday)
startDate = datetime.datetime.fromtimestamp(time.mktime(pday.timetuple()))
startDate.replace(hour=0,minute=0,second=0,microsecond=0)
context['startDate'] = startDate
context['deltaDate'] = datetime.timedelta(days=1)
context['startWindw'] = startDate
示例14: testAcceptAutoCommandLineHelp
def testAcceptAutoCommandLineHelp(self):
opts = []
args = {}
args['automaticHelp'] = True
args['configurationOptionsList'] = opts
hh = HelpHandler()
args['helpHandler'] = hh.handleHelp
sys.argv.append('--help')
conf = CM.newConfiguration(**args)
assert("--help" in hh.data)
assert("print this list" in hh.data)
示例15: setUp
def setUp(self):
global me
# config gets messed up by some tests. Use this one by preference
self.config = configurationManager.newConfiguration(configurationModule = testConfig, applicationName='Testing Postgresql Utils')
for i in self.config:
try:
self.config[i] = self.config.get(i)%(replDict)
except:
pass
self.connection = psycopg2.connect(me.dsn)
self.testDB = TestDB()