本文整理汇总了Python中gflags.FlagsError方法的典型用法代码示例。如果您正苦于以下问题:Python gflags.FlagsError方法的具体用法?Python gflags.FlagsError怎么用?Python gflags.FlagsError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gflags
的用法示例。
在下文中一共展示了gflags.FlagsError方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_flags
# 需要导入模块: import gflags [as 别名]
# 或者: from gflags import FlagsError [as 别名]
def process_flags(flags=[]):
"""Uses the command-line flags to set the logging level.
Args:
argv: List of command line arguments passed to the python script.
"""
# Let the gflags module process the command-line arguments.
try:
FLAGS(flags)
except gflags.FlagsError as e:
print('%s\nUsage: %s ARGS\n%s' % (e, str(flags), FLAGS))
sys.exit(1)
# Set the logging according to the command-line flag.
logging.getLogger().setLevel(getattr(logging, FLAGS.logging_level))
示例2: InstallExceptionHandler
# 需要导入模块: import gflags [as 别名]
# 或者: from gflags import FlagsError [as 别名]
def InstallExceptionHandler(handler):
"""Install an exception handler.
Args:
handler: an object conforming to the interface defined in ExceptionHandler
Raises:
TypeError: handler was not of the correct type
All installed exception handlers will be called if main() exits via
an abnormal exception, i.e. not one of SystemExit, KeyboardInterrupt,
FlagsError or UsageError.
"""
if not isinstance(handler, ExceptionHandler):
raise TypeError('handler of type %s does not inherit from ExceptionHandler'
% type(handler))
EXCEPTION_HANDLERS.append(handler)
示例3: ParseFlagsWithUsage
# 需要导入模块: import gflags [as 别名]
# 或者: from gflags import FlagsError [as 别名]
def ParseFlagsWithUsage(argv):
"""Parse the flags, exiting (after printing usage) if they are unparseable.
Args:
argv: command line arguments
Returns:
remaining command line arguments after parsing flags
"""
# Update the global commands.
# pylint: disable=global-statement
global _cmd_argv
try:
_cmd_argv = FLAGS(argv)
return _cmd_argv
except flags.FlagsError, error:
ShortHelpAndExit('FATAL Flags parsing error: %s' % error)
示例4: main
# 需要导入模块: import gflags [as 别名]
# 或者: from gflags import FlagsError [as 别名]
def main():
try:
gflags.FLAGS(sys.argv)
except gflags.FlagsError as e:
print '%s\nUsage: %s ARGS\n%s' % (e, sys.argv[0], gflags.FLAGS)
sys.exit(1)
logging.basicConfig(level=logging.INFO)
if gflags.FLAGS.mindmap_file is None:
print 'Usage: %s ARGS\n%s' % (sys.argv[0], gflags.FLAGS)
sys.exit(1)
org = Organization(
codecs.open(gflags.FLAGS.mindmap_file, 'r', 'utf8').read())
if gflags.FLAGS.html_file is not None:
org.OutputToHTML(gflags.FLAGS.html_file)
if gflags.FLAGS.beamer_latex_file is not None:
org.OutputToBeamerLatex(gflags.FLAGS.beamer_latex_file)
if gflags.FLAGS.latex_file is not None:
org.OutputToLatex(gflags.FLAGS.latex_file)
示例5: main
# 需要导入模块: import gflags [as 别名]
# 或者: from gflags import FlagsError [as 别名]
def main(argv):
# Utility main to load flags
try:
argv = FLAGS(argv) # parse flags
except gflags.FlagsError:
print ('Usage: %s ARGS\\n%s' % (sys.argv[0], FLAGS))
sys.exit(1)
_main()
示例6: main
# 需要导入模块: import gflags [as 别名]
# 或者: from gflags import FlagsError [as 别名]
def main(argv):
# Utility main to load flags
try:
argv = FLAGS(argv) # parse flags
except gflags.FlagsError:
print ('Usage: %s ARGS\\n%s' % (sys.argv[0], FLAGS))
sys.exit(1)
_main()
示例7: parse_flags_with_usage
# 需要导入模块: import gflags [as 别名]
# 或者: from gflags import FlagsError [as 别名]
def parse_flags_with_usage(args):
"""Try parsing the flags, printing usage and exiting if unparseable."""
try:
argv = FLAGS(args)
return argv
except flags.FlagsError, error:
sys.stderr.write('FATAL Flags parsing error: %s\n' % error)
sys.stderr.write('Pass --helpshort or --helpfull to see help on flags.\n')
sys.exit(1)
示例8: prepare_flags
# 需要导入模块: import gflags [as 别名]
# 或者: from gflags import FlagsError [as 别名]
def prepare_flags(argv):
'''Set up flags. Returns true if the flag settings are acceptable.'''
try:
argv = FLAGS(argv) # parse flags
except gflags.FlagsError, e:
return False
示例9: prepare_flags
# 需要导入模块: import gflags [as 别名]
# 或者: from gflags import FlagsError [as 别名]
def prepare_flags(argv):
'''Set up flags. Returns true if the flag settings are acceptable.'''
try:
argv = FLAGS(argv) # parse flags
except gflags.FlagsError, e:
print '%s\\nUsage: %s ARGS\\n%s' % (e, sys.argv[0], FLAGS)
return False
示例10: main
# 需要导入模块: import gflags [as 别名]
# 或者: from gflags import FlagsError [as 别名]
def main(argv):
# Utility main to load flags
try:
argv = FLAGS(argv) # parse flags
except gflags.FlagsError:
print ('Usage: %s ARGS\\n%s' % (sys.argv[0], FLAGS))
sys.exit(1)
_test_masks()