本文整理汇总了Python中cli.CLI.parse方法的典型用法代码示例。如果您正苦于以下问题:Python CLI.parse方法的具体用法?Python CLI.parse怎么用?Python CLI.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cli.CLI
的用法示例。
在下文中一共展示了CLI.parse方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from cli import CLI [as 别名]
# 或者: from cli.CLI import parse [as 别名]
def run():
cli = CLI()
try:
(options, args) = cli.parse()
if options.simple_db_migrate_version:
msg = 'simple-db-migrate v%s' % SIMPLE_DB_MIGRATE_VERSION
cli.info_and_exit(msg)
if options.show_colors:
CLI.show_colors()
# Create config
config = FileConfig(options.config_file, options.environment)
config.put('schema_version', options.schema_version)
config.put('show_sql', options.show_sql)
config.put('show_sql_only', options.show_sql_only)
config.put('new_migration', options.new_migration)
config.put('drop_db_first', options.drop_db_first)
config.put('paused_mode', options.paused_mode)
config.put('log_dir', options.log_dir)
config.put('label_version', options.label_version)
config.put('force_use_files_on_down', options.force_use_files_on_down)
config.put('force_execute_old_migrations_versions', options.force_execute_old_migrations_versions)
# paused mode forces log_level to 2
log_level = int(options.log_level)
if options.paused_mode:
log_level = 2
config.put('log_level', log_level)
# Ask the password for user if configured
if config.get('db_password') == '<<ask_me>>':
if options.password:
passwd = options.password
else:
cli.msg('\nPlease inform password to connect to database "%[email protected]%s:%s"' % (config.get('db_user'), config.get('db_host'), config.get('db_name')))
passwd = getpass()
config.remove('db_password')
config.put('db_password', passwd)
# If CLI was correctly parsed, execute db-migrate.
Main(config).execute()
except KeyboardInterrupt:
cli.info_and_exit("\nExecution interrupted by user...")
except Exception, e:
cli.error_and_exit(str(e))
示例2: run
# 需要导入模块: from cli import CLI [as 别名]
# 或者: from cli.CLI import parse [as 别名]
def run():
cli = CLI()
try:
(options, args) = cli.parse()
if options.torneira_version:
msg = "torneira v%s" % torneira.__version__
cli.info_and_exit(msg)
if options.show_colors:
CLI.show_colors()
Main().excecute()
except KeyboardInterrupt:
cli.info_and_exit("\nExecution interrupted by user...")
except Exception, e:
cli.error_and_exit(str(e))
示例3: run
# 需要导入模块: from cli import CLI [as 别名]
# 或者: from cli.CLI import parse [as 别名]
def run():
cli = CLI()
(options, args) = cli.parse()
if options.enable_colors:
cli.enable_colors()
try:
main = Main(cli, options, args)
if options.print_version:
main.print_version()
else:
main.start()
except KeyboardInterrupt:
cli.print_info("\nExecution interrupted by user")
sys.exit(2)
sys.exit(0)
示例4: Main
# 需要导入模块: from cli import CLI [as 别名]
# 或者: from cli.CLI import parse [as 别名]
class Main(object):
def __init__(self):
self.cli = CLI()
def start(self, options, args):
# set path
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(options.settings_file)), ".."))
sys.path.insert(0, os.path.dirname(os.path.abspath(options.settings_file)))
# set setting
exec("import %s as settings" % os.path.splitext(os.path.basename(options.settings_file))[0])
torneira.settings = settings
from torneira.core.server import TorneiraServer
server = TorneiraServer(
pidfile=options.pidfile,
port=options.port,
media_dir=os.path.abspath(options.media_dir),
xheaders=options.xheaders,
)
if options.daemon:
if args[0] == "start":
server.start()
elif args[0] == "stop":
server.stop()
elif args[0] == "restart":
server.restart()
else:
server.run()
def excecute(self):
(options, args) = self.cli.parse()
if args and args[0] in ("start", "stop", "restart"):
try:
self.start(options, args)
except Exception, e:
traceback.print_exc(file=sys.stderr)
示例5: run_from_argv
# 需要导入模块: from cli import CLI [as 别名]
# 或者: from cli.CLI import parse [as 别名]
def run_from_argv(args=None):
(options, _) = CLI.parse(args)
run(options.__dict__)
示例6: run_from_argv
# 需要导入模块: from cli import CLI [as 别名]
# 或者: from cli.CLI import parse [as 别名]
def run_from_argv(args=sys.argv[1:]):
if not args:
args = ["-h"]
(options, _) = CLI.parse(args)
run(options.__dict__)