本文整理汇总了Python中Factory.Factory.getValidParams方法的典型用法代码示例。如果您正苦于以下问题:Python Factory.getValidParams方法的具体用法?Python Factory.getValidParams怎么用?Python Factory.getValidParams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Factory.Factory
的用法示例。
在下文中一共展示了Factory.getValidParams方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Factory import Factory [as 别名]
# 或者: from Factory.Factory import getValidParams [as 别名]
#.........这里部分代码省略.........
def parseGetPotTestFormat(self, filename):
tests = []
test_dir = os.path.abspath(os.path.dirname(filename))
relative_path = test_dir.replace(self.run_tests_dir, '')
# Filter tests that we want to run
# Under the new format, we will filter based on directory not filename since it is fixed
will_run = False
if len(self.tests) == 0:
will_run = True
else:
for item in self.tests:
if test_dir.find(item) > -1:
will_run = True
if not will_run:
return tests
try:
data = ParseGetPot.readInputFile(filename)
except: # ParseGetPot class
print "Parse Error: " + test_dir + "/" + filename
return tests
# We expect our root node to be called "Tests"
if 'Tests' in data.children:
tests_node = data.children['Tests']
for testname, test_node in tests_node.children.iteritems():
# First retrieve the type so we can get the valid params
if 'type' not in test_node.params:
print "Type missing in " + test_dir + filename
sys.exit(1)
params = self.factory.getValidParams(test_node.params['type'])
# Now update all the base level keys
params_parsed = set()
params_ignored = set()
for key, value in test_node.params.iteritems():
params_parsed.add(key)
if key in params:
if params.type(key) == list:
params[key] = value.split(' ')
else:
if re.match('".*"', value): # Strip quotes
params[key] = value[1:-1]
else:
# Prevent bool types from being stored as strings. This can lead to the
# strange situation where string('False') evaluates to true...
if params.isValid(key) and (type(params[key]) == type(bool())):
# We support using the case-insensitive strings {true, false} and the string '0', '1'.
if (value.lower()=='true') or (value=='1'):
params[key] = True
elif (value.lower()=='false') or (value=='0'):
params[key] = False
else:
print "Unrecognized (key,value) pair: (", key, ',', value, ")"
sys.exit(1)
# Otherwise, just do normal assignment
else:
params[key] = value
else:
params_ignored.add(key)
# Make sure that all required parameters are supplied
示例2: __init__
# 需要导入模块: from Factory import Factory [as 别名]
# 或者: from Factory.Factory import getValidParams [as 别名]
class ClusterLauncher:
def __init__(self):
self.factory = Factory()
def parseJobsFile(self, template_dir, job_file):
jobs = []
# We expect the job list to be named "job_list"
filename = template_dir + job_file
try:
data = ParseGetPot.readInputFile(filename)
except: # ParseGetPot class
print "Parse Error: " + filename
return jobs
# We expect our root node to be called "Jobs"
if 'Jobs' in data.children:
jobs_node = data.children['Jobs']
# Get the active line
active_jobs = None
if 'active' in jobs_node.params:
active_jobs = jobs_node.params['active'].split(' ')
for jobname, job_node in jobs_node.children.iteritems():
# Make sure this job is active
if active_jobs != None and not jobname in active_jobs:
continue
# First retrieve the type so we can get the valid params
if 'type' not in job_node.params:
print "Type missing in " + filename
sys.exit(1)
params = self.factory.getValidParams(job_node.params['type'])
params['job_name'] = jobname
# Now update all the base level keys
params_parsed = set()
params_ignored = set()
for key, value in job_node.params.iteritems():
params_parsed.add(key)
if key in params:
if params.type(key) == list:
params[key] = value.split(' ')
else:
if re.match('".*"', value): # Strip quotes
params[key] = value[1:-1]
else:
params[key] = value
else:
params_ignored.add(key)
# Make sure that all required parameters are supplied
required_params_missing = params.required_keys() - params_parsed
if len(required_params_missing):
print 'Required Missing Parameter(s): ', required_params_missing
sys.exit(1)
if len(params_ignored):
print 'Ignored Parameter(s): ', params_ignored
jobs.append(params)
return jobs
def createAndLaunchJob(self, template_dir, job_file, specs, options):
next_dir = getNextDirName(specs['job_name'], os.listdir('.'))
os.mkdir(template_dir + next_dir)
# Log it
if options.message:
f = open(template_dir + 'jobs.log', 'a')
f.write(next_dir.ljust(20) + ': ' + options.message + '\n')
f.close()
saved_cwd = os.getcwd()
os.chdir(template_dir + next_dir)
# Turn the remaining work over to the Job instance
# To keep everything consistent we'll also append our serial number to our job name
specs['job_name'] = next_dir
job_instance = self.factory.create(specs['type'], specs)
# Copy files
job_instance.copyFiles(job_file)
# Prepare the Job Script
job_instance.prepareJobScript()
# Launch it!
job_instance.launch()
os.chdir(saved_cwd)
def registerJobType(self, type, name):
self.factory.register(type, name)
### Parameter Dump ###
def printDump(self):
self.factory.printDump("Jobs")
#.........这里部分代码省略.........