本文整理汇总了Python中PyInquirer.prompt方法的典型用法代码示例。如果您正苦于以下问题:Python PyInquirer.prompt方法的具体用法?Python PyInquirer.prompt怎么用?Python PyInquirer.prompt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyInquirer
的用法示例。
在下文中一共展示了PyInquirer.prompt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_output_path
# 需要导入模块: import PyInquirer [as 别名]
# 或者: from PyInquirer import prompt [as 别名]
def read_output_path(output: str, meta: PluginMeta) -> Optional[str]:
directory = os.getcwd()
filename = f"{meta.id}-v{meta.version}.mbp"
if not output:
output = os.path.join(directory, filename)
elif os.path.isdir(output):
output = os.path.join(output, filename)
elif os.path.exists(output):
override = prompt({
"type": "confirm",
"name": "override",
"message": f"{output} exists, override?"
})["override"]
if not override:
return None
os.remove(output)
return os.path.abspath(output)
示例2: command
# 需要导入模块: import PyInquirer [as 别名]
# 或者: from PyInquirer import prompt [as 别名]
def command(help: str) -> Callable[[Callable], Callable]:
def decorator(func) -> Callable:
questions = func.__inquirer_questions__.copy()
@functools.wraps(func)
def wrapper(*args, **kwargs):
for key, value in kwargs.items():
if key not in questions:
continue
if value is not None and (questions[key]["type"] != "confirm" or value != "null"):
questions.pop(key, None)
question_list = list(questions.values())
question_list.reverse()
resp = prompt(question_list, keyboard_interrupt_msg="Aborted!")
if not resp and question_list:
return
kwargs = {**kwargs, **resp}
func(*args, **kwargs)
return app.command(help=help)(wrapper)
return decorator
示例3: get_output_formats
# 需要导入模块: import PyInquirer [as 别名]
# 或者: from PyInquirer import prompt [as 别名]
def get_output_formats(self):
'''Returns a dictionary of output formats.'''
args = get_args()
formats = args.output_formats
if not (formats or args.suppress):
answer = prompt([
{
'type': 'checkbox',
'name': 'formats',
'message': 'Which output formats to create?',
'choices': [{'name': x, 'checked': x == 'epub'} for x in available_formats],
},
])
formats = answer['formats']
# end if
if not formats or len(formats) == 0:
formats = ['epub'] # default to epub if none selected
# end if
return {x: (x in formats) for x in available_formats}
# end def
示例4: open_folder
# 需要导入模块: import PyInquirer [as 别名]
# 或者: from PyInquirer import prompt [as 别名]
def open_folder(self):
args = get_args()
if args.suppress:
return False
# end if
answer = prompt([
{
'type': 'confirm',
'name': 'exit',
'message': 'Open the output folder?',
'default': True,
},
])
return answer['exit']
# end def
示例5: option
# 需要导入模块: import PyInquirer [as 别名]
# 或者: from PyInquirer import prompt [as 别名]
def option(short: str, long: str, message: str = None, help: str = None,
click_type: Union[str, Callable[[str], Any]] = None, inq_type: str = None,
validator: Validator = None, required: bool = False, default: str = None,
is_flag: bool = False, prompt: bool = True) -> Callable[[Callable], Callable]:
if not message:
message = long[2].upper() + long[3:]
click_type = validator.click_type if isinstance(validator, ClickValidator) else click_type
if is_flag:
click_type = yesno
def decorator(func) -> Callable:
click.option(short, long, help=help, type=click_type)(func)
if not prompt:
return func
if not hasattr(func, "__inquirer_questions__"):
func.__inquirer_questions__ = {}
q = {
"type": (inq_type if isinstance(inq_type, str)
else ("input" if not is_flag
else "confirm")),
"name": long[2:],
"message": message,
}
if default is not None:
q["default"] = default
if required:
q["validator"] = Required(validator)
elif validator:
q["validator"] = validator
func.__inquirer_questions__[long[2:]] = q
return func
return decorator
示例6: ask_direction
# 需要导入模块: import PyInquirer [as 别名]
# 或者: from PyInquirer import prompt [as 别名]
def ask_direction():
directions_prompt = {
'type': 'list',
'name': 'direction',
'message': 'Which direction would you like to go?',
'choices': ['Forward', 'Right', 'Left', 'Back']
}
answers = prompt(directions_prompt)
return answers['direction']
# TODO better to use while loop than recursion!
示例7: encounter2b
# 需要导入模块: import PyInquirer [as 别名]
# 或者: from PyInquirer import prompt [as 别名]
def encounter2b():
prompt({
'type': 'list',
'name': 'weapon',
'message': 'Pick one',
'choices': [
'Use the stick',
'Grab a large rock',
'Try and make a run for it',
'Attack the wolf unarmed'
]
}, style=custom_style_2)
print('The wolf mauls you. You die. The end.')
示例8: _validate_configuration
# 需要导入模块: import PyInquirer [as 别名]
# 或者: from PyInquirer import prompt [as 别名]
def _validate_configuration(self, configuration):
if not is_os_supported(configuration["distribution"]):
message = (
"Sorry, currently we do not support packages indices that are "
"running on your current operating system. Please select an operating system "
"you'd like to use to search packages for:"
)
configuration["distribution"] = prompt(
[
{
"type": "list",
"message": message,
"name": "distribution",
"choices": ["ubuntu", "debian"],
}
]
)["distribution"]
if not is_version_supported(
configuration["distribution"], configuration["codename"]
):
message = (
f"Sorry, the codename '{configuration['codename']}' is not recognised by fetchy for "
f"the distribution {configuration['distribution']}. Please select a codename for which "
"you'd like to search packages for:"
)
configuration["codename"] = prompt(
[
{
"type": "list",
"message": message,
"name": "codename",
"choices": get_supported_versions_for(
configuration["distribution"]
),
}
]
)["codename"]
示例9: get_output_path
# 需要导入模块: import PyInquirer [as 别名]
# 或者: from PyInquirer import prompt [as 别名]
def get_output_path(self):
'''Returns a valid output path where the files are stored'''
args = get_args()
output_path = args.output_path
if args.suppress:
if not output_path:
output_path = self.app.output_path
# end if
if not output_path:
output_path = os.path.join('Lightnovels', 'Unknown Novel')
# end if
# end if
if not output_path:
answer = prompt([
{
'type': 'input',
'name': 'output',
'message': 'Enter output direcotry:',
'default': os.path.abspath(self.app.output_path),
},
])
output_path = answer['output']
# end if
output_path = os.path.abspath(output_path)
if os.path.exists(output_path):
if self.force_replace_old():
shutil.rmtree(output_path, ignore_errors=True)
# end if
# end if
os.makedirs(output_path, exist_ok=True)
return output_path
# end def
示例10: force_replace_old
# 需要导入模块: import PyInquirer [as 别名]
# 或者: from PyInquirer import prompt [as 别名]
def force_replace_old(self):
args = get_args()
if args.force:
return True
elif args.ignore:
return False
# end if
if args.suppress:
return False
# end if
# answer = prompt([
# {
# 'type': 'confirm',
# 'name': 'force',
# 'message': 'Detected existing folder. Replace it?',
# 'default': False,
# },
# ])
# return answer['force']
answer = prompt([
{
'type': 'list',
'name': 'replace',
'message': 'What to do with existing folder?',
'choices': [
'Remove old folder and start fresh',
'Download remaining chapters only',
],
},
])
return answer['replace'].startswith('Remove')
# end def
示例11: should_pack_by_volume
# 需要导入模块: import PyInquirer [as 别名]
# 或者: from PyInquirer import prompt [as 别名]
def should_pack_by_volume(self):
'''Returns whether to generate single or multiple files by volumes'''
args = get_args()
if args.single:
return False
elif args.multi:
return True
# end if
if args.suppress:
return False
# end if
# answer = prompt([
# {
# 'type': 'confirm',
# 'name': 'volume',
# 'message': 'Split file by volumes?',
# 'default': False,
# },
# ])
# return answer['volume']
answer = prompt([
{
'type': 'list',
'name': 'split',
'message': 'How many files to generate?',
'choices': [
'Pack everything into a single file',
'Split by volume into multiple files'
],
},
])
return answer['split'].startswith('Split')
# end def
示例12: get_novel_url
# 需要导入模块: import PyInquirer [as 别名]
# 或者: from PyInquirer import prompt [as 别名]
def get_novel_url(self):
'''Returns a novel page url or a query'''
args = get_args()
if args.query and len(args.query) > 1:
return args.query
# end if
url = args.novel_page
if url:
if re.match(r'^https?://.+\..+$', url):
return url
else:
raise Exception('Invalid URL of novel page')
# end if
# end if
try:
if args.suppress:
raise Exception()
# end if
answer = prompt([
{
'type': 'input',
'name': 'novel',
'message': 'Enter novel page url or query novel:',
'validate': lambda val: 'Input should not be empty'
if len(val) == 0 else True,
},
])
return answer['novel'].strip()
except Exception:
raise Exception('Novel page url or query was not given')
# end try
# end def
示例13: get_range_from_volumes
# 需要导入模块: import PyInquirer [as 别名]
# 或者: from PyInquirer import prompt [as 别名]
def get_range_from_volumes(self, times=0):
'''Returns a range created using volume list'''
selected = None
args = get_args()
if times == 0 and args.volumes:
selected = [int(x) for x in args.volumes]
# end if
if not selected and args.suppress:
selected = [x['id'] for x in self.app.crawler.volumes]
# end if
if not selected:
answer = prompt([
{
'type': 'checkbox',
'name': 'volumes',
'message': 'Choose volumes to download:',
'choices': [
{
'name': '%d - %s (Chapter %d-%d) [%d chapters]' % (
vol['id'], vol['title'], vol['start_chapter'],
vol['final_chapter'], vol['chapter_count'])
}
for vol in self.app.crawler.volumes
],
'validate': lambda ans: True if len(ans) > 0
else 'You must choose at least one volume.'
}
])
selected = [int(val.split(' ')[0]) for val in answer['volumes']]
# end if
if times < 3 and len(selected) == 0:
return self.get_range_from_volumes(times + 1)
# end if
return selected
# end def
示例14: loadtweets
# 需要导入模块: import PyInquirer [as 别名]
# 或者: from PyInquirer import prompt [as 别名]
def loadtweets():
while True:
tweets = datadb.load_data_for_tag();
for tweet in tweets:
print(tweet[3] +" \t" + tweet[0])
answers = prompt(questions)
if answers["tag"]=="exit":
sys.exit()
print("set tags:"+str(tweet[0])+" to "+str(answers["tag"]))
datadb.tag_data(tweet[0], answers["tag"], by_user_id)
示例15: validate
# 需要导入模块: import PyInquirer [as 别名]
# 或者: from PyInquirer import prompt [as 别名]
def validate(self, document):
"""Validate the module name for the prompt"""
if not re.match(r'^\w+$', document.text):
raise ValidationError(
message='Enter a valid module name',
cursor_position=len(document.text))
elif document.text.lower() in [module.lower() for module in self.modules]:
raise ValidationError(
message="Try a different name, this module name is not available.",
cursor_position=len(document.text))