本文整理匯總了Python中conda.cli.conda_argparse.ArgumentParser.error方法的典型用法代碼示例。如果您正苦於以下問題:Python ArgumentParser.error方法的具體用法?Python ArgumentParser.error怎麽用?Python ArgumentParser.error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類conda.cli.conda_argparse.ArgumentParser
的用法示例。
在下文中一共展示了ArgumentParser.error方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: from conda.cli.conda_argparse import ArgumentParser [as 別名]
# 或者: from conda.cli.conda_argparse.ArgumentParser import error [as 別名]
def main():
from conda.cli.conda_argparse import ArgumentParser
p = ArgumentParser(
description="""\
Tool for signing conda packages. Signatures will be written alongside the
files as FILE.sig.""")
p.add_argument('files',
help="Files to sign.",
nargs='*',
metavar="FILE",)
p.add_argument('-k', '--keygen',
action="store",
help="Generate a public-private "
"key pair ~/.conda/keys/<NAME>(.pub).",
metavar="NAME")
p.add_argument('--size',
action="store",
help="Size of generated RSA public-private key pair in bits "
"(defaults to 2048).",
metavar="BITS")
p.add_argument('-v', '--verify',
action="store_true",
help="Verify FILE(s).")
args = p.parse_args()
if args.keygen:
if args.files:
p.error('no arguments expected for --keygen')
try:
keygen(args.keygen, int(2048 if args.size is None else args.size))
except ValueError as e:
sys.exit('Error: %s' % e)
return
if args.size is not None:
p.error('--size option is only allowed with --keygen option')
if args.verify:
for path in args.files:
try:
disp = 'VALID' if verify(path) else 'INVALID'
except SignatureError as e:
disp = 'ERROR: %s' % e
print('%-40s %s' % (path, disp))
return
key_name = get_default_keyname()
if key_name is None:
sys.exit("Error: no private key found in %s" % KEYS_DIR)
print("Using private key '%s' for signing." % key_name)
key = RSA.importKey(open(join(KEYS_DIR, key_name)).read())
for path in args.files:
print('signing: %s' % path)
with open('%s.sig' % path, 'w') as fo:
fo.write('%s ' % key_name)
fo.write(sign(path, key))
fo.write('\n')