本文整理匯總了Python中click.exceptions方法的典型用法代碼示例。如果您正苦於以下問題:Python click.exceptions方法的具體用法?Python click.exceptions怎麽用?Python click.exceptions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類click
的用法示例。
在下文中一共展示了click.exceptions方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: confirm_project
# 需要導入模塊: import click [as 別名]
# 或者: from click import exceptions [as 別名]
def confirm_project(project, watson_projects):
"""
Ask user to confirm creation of a new project
'project' must be a string
'watson_projects' must be an interable.
Returns True on accept and raises click.exceptions.Abort on reject
"""
if project not in watson_projects:
msg = ("Project '%s' does not exist yet. Create it?"
% style('project', project))
click.confirm(msg, abort=True)
return True
示例2: confirm_tags
# 需要導入模塊: import click [as 別名]
# 或者: from click import exceptions [as 別名]
def confirm_tags(tags, watson_tags):
"""
Ask user to confirm creation of new tags (each separately)
Both 'tags' and 'watson_tags" must be iterables.
Returns True if all accepted and raises click.exceptions.Abort on reject
"""
for tag in tags:
if tag not in watson_tags:
msg = "Tag '%s' does not exist yet. Create it?" % style('tag', tag)
click.confirm(msg, abort=True)
return True
示例3: unschedule
# 需要導入模塊: import click [as 別名]
# 或者: from click import exceptions [as 別名]
def unschedule(self):
"""
Given a a list of scheduled functions,
tear down their regular execution.
"""
# Run even if events are not defined to remove previously existing ones (thus default to []).
events = self.stage_config.get('events', [])
if not isinstance(events, list): # pragma: no cover
print("Events must be supplied as a list.")
return
function_arn = None
try:
function_response = self.zappa.lambda_client.get_function(FunctionName=self.lambda_name)
function_arn = function_response['Configuration']['FunctionArn']
except botocore.exceptions.ClientError as e: # pragma: no cover
raise ClickException("Function does not exist, you should deploy first. Ex: zappa deploy {}. "
"Proceeding to unschedule CloudWatch based events.".format(self.api_stage))
print("Unscheduling..")
self.zappa.unschedule_events(
lambda_name=self.lambda_name,
lambda_arn=function_arn,
events=events,
)
# Remove async task SNS
if self.stage_config.get('async_source', None) == 'sns' \
and self.stage_config.get('async_resources', True):
removed_arns = self.zappa.remove_async_sns_topic(self.lambda_name)
click.echo('SNS Topic removed: %s' % ', '.join(removed_arns))
示例4: catch_boto_errors
# 需要導入模塊: import click [as 別名]
# 或者: from click import exceptions [as 別名]
def catch_boto_errors(func):
def _boto_error_wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except botocore.exceptions.NoRegionError:
error(
"You must specify a region. Pass `--aws-region` or run `aws configure`."
)
except botocore.exceptions.NoCredentialsError:
error("No AWS credentials configured. Did you run `aws configure`?")
except botocore.exceptions.BotoCoreError as e:
error("Unexpected AWS error: %s" % e)
return _boto_error_wrapper
示例5: validate_aws_profile
# 需要導入模塊: import click [as 別名]
# 或者: from click import exceptions [as 別名]
def validate_aws_profile(ctx, param, value):
"""A click callback to validate that an AWS profile exists"""
try:
boto3.Session(profile_name=value)
except botocore.exceptions.ProfileNotFound as e:
raise click.BadParameter(e.fmt)
else:
return value