本文整理匯總了Python中params.Params.askFor方法的典型用法代碼示例。如果您正苦於以下問題:Python Params.askFor方法的具體用法?Python Params.askFor怎麽用?Python Params.askFor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類params.Params
的用法示例。
在下文中一共展示了Params.askFor方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Run
# 需要導入模塊: from params import Params [as 別名]
# 或者: from params.Params import askFor [as 別名]
class Run(object):
debug = False
dryrun = False
params = None
answers_data = {GLOBAL_CONF: {}}
tmpdir = None
answers_file = None
provider = DEFAULT_PROVIDER
installed = False
plugins = []
update = False
app_path = None
target_path = None
app_id = None
app = None
answers_output = None
kwargs = None
def __init__(self, answers, APP, dryrun = False, debug = False, stop = False, **kwargs):
self.debug = debug
self.dryrun = dryrun
self.stop = stop
self.kwargs = kwargs
if "answers_output" in kwargs:
self.answers_output = kwargs["answers_output"]
if os.environ and "IMAGE" in os.environ:
self.app_path = APP
APP = os.environ["IMAGE"]
del os.environ["IMAGE"]
if APP and os.path.exists(APP):
self.app_path = APP
else:
self.app_path = os.getcwd()
install = Install(answers, APP, dryrun = dryrun, target_path = self.app_path)
install.install()
self.params = Params(target_path=self.app_path)
if "ask" in kwargs:
self.params.ask = kwargs["ask"]
workdir = None
if "workdir" in kwargs:
workdir = kwargs["workdir"]
self.utils = Utils(self.params, workdir)
if not "workdir" in kwargs:
kwargs["workdir"] = self.utils.workdir
self.answers_file = answers
self.plugin = Plugin()
self.plugin.load_plugins()
def _dispatchGraph(self):
if not "graph" in self.params.mainfile_data:
raise Exception("Graph not specified in %s" % MAIN_FILE)
for component, graph_item in self.params.mainfile_data["graph"].iteritems():
if self.utils.isExternal(graph_item):
component_run = Run(self.answers_file, self.utils.getExternalAppDir(component), self.dryrun, self.debug, **self.kwargs)
ret = component_run.run()
if self.answers_output:
self.params.loadAnswers(ret)
else:
self._processComponent(component, graph_item)
def _applyTemplate(self, data, component):
template = Template(data)
config = self.params.getValues(component)
logger.debug("Config: %s ", config)
output = None
while not output:
try:
logger.debug(config)
output = template.substitute(config)
except KeyError as ex:
name = ex.args[0]
logger.debug("Artifact contains unknown parameter %s, asking for it", name)
config[name] = self.params.askFor(name, {"description": "Missing parameter '%s', provide the value or fix your %s" % (name, MAIN_FILE)})
if not len(config[name]):
raise Exception("Artifact contains unknown parameter %s" % name)
self.params.loadAnswers({component: {name: config[name]}})
return output
def _processArtifacts(self, component, provider):
artifacts = self.utils.getArtifacts(component)
artifact_provider_list = []
if not provider in artifacts:
raise Exception("Data for provider \"%s\" are not part of this app" % self.params.provider)
dst_dir = os.path.join(self.utils.workdir, component)
data = None
for artifact in artifacts[provider]:
if "inherit" in artifact:
#.........這裏部分代碼省略.........
示例2: Create
# 需要導入模塊: from params import Params [as 別名]
# 或者: from params.Params import askFor [as 別名]
#.........這裏部分代碼省略.........
elif isinstance(element["contents"], collections.Mapping):
fp.write(anymarkup.serialize(self._generateContents(element["contents"]), format='yaml'))
# elif element["contentType"] == "application/json":
# if element["name"] == "Atomicfile":
# element["contents"] = self._updateAtomicfile(element["contents"])
# fp.write(json.dumps(element["contents"]))
def _pickOne(self, what, info, options):
options_text = ""
for i, option in enumerate(options):
options_text += "%s. %s\n" % (i+1, option)
required = False
if "required" in info:
required = info["required"]
value = raw_input("%s (%s)\n Options:\n%s\nYour choice (default: 1): " % (what, info["description"], options_text))
if len(value) == 0:
value = 1
elif int(value) == 0 and not required:
return None
return options[int(value)-1]
def _getName(self, element, content, path = None):
name = None
if not "name" in content:
name = element
elif not content["name"]:
name = self._generateValue(path)
if not name:
name = self.params.askFor(element, content)
elif type(content["name"]) is list:
name = self._pickOne(element, content, content["name"])
else:
name = content["name"]
logger.debug(name)
return name
def _generateContents(self, contents, path="root"):
result = {}
for element, content in contents.iteritems():
local_path = "%s.%s" % (path, element)
name = self._getName(element, content, local_path)
print("Filling %s" % name)
if not content["required"]:
skip = self.params.askFor("Element %s not required, do you want to skip it?" % name, {"description": "Type y or n", "default": "Y"})
if isTrue(skip):
continue
#logger.debug("Key: %s, value %s", element, content["value"])
if content["type"] == "object":
result[name] = self._generateContents(content["value"], local_path)
elif content["type"] == "list":
tmp_results = []
while True:
value = self.params.askFor(content["value"].keys()[0], content["value"][content["value"].keys()[0]])
if len(value) == 0:
break