<s> import functools <EOL> import logging <EOL> import os <EOL> import operator <EOL> import argparse <EOL> import zpmlib <EOL> from zpmlib import zpm <EOL> _commands = [ ] <EOL> LOG = zpmlib . get_logger ( __name__ ) <EOL> class SwiftLogFilter ( logging . Filter ) : <EOL> def filter ( self , record ) : <EOL> if ( record . levelname == '<STR_LIT>' and <EOL> record . msg . msg == '<STR_LIT>' and <EOL> record . msg . http_status == <NUM_LIT> ) : <EOL> return False <EOL> return True <EOL> def set_up_arg_parser ( ) : <EOL> parser = argparse . ArgumentParser ( <EOL> description = '<STR_LIT>' , <EOL> epilog = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:version>' , <EOL> help = '<STR_LIT>' , <EOL> version = '<STR_LIT>' % zpmlib . __version__ ) <EOL> subparsers = parser . add_subparsers ( description = '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' ) <EOL> for cmd in all_commands ( ) : <EOL> doclines = cmd . __doc__ . splitlines ( ) <EOL> summary = doclines [ <NUM_LIT:0> ] <EOL> description = '<STR_LIT:\n>' . join ( doclines [ <NUM_LIT:1> : ] ) <EOL> subparser = subparsers . add_parser ( cmd . __name__ , <EOL> help = summary , <EOL> description = description ) <EOL> for args , kwargs in reversed ( getattr ( cmd , '<STR_LIT>' , [ ] ) ) : <EOL> subparser . add_argument ( * args , ** kwargs ) <EOL> subparser . set_defaults ( func = cmd ) <EOL> return parser <EOL> def command ( func ) : <EOL> """<STR_LIT>""" <EOL> _commands . append ( func ) <EOL> return func <EOL> def with_logging ( func ) : <EOL> """<STR_LIT>""" <EOL> log_level_deco = arg ( <EOL> '<STR_LIT>' , '<STR_LIT>' , help = "<STR_LIT>" , <EOL> choices = [ '<STR_LIT>' , '<STR_LIT:info>' , '<STR_LIT>' , '<STR_LIT:error>' , '<STR_LIT>' ] , <EOL> default = '<STR_LIT>' <EOL> ) <EOL> @ functools . wraps ( func ) <EOL> def inner ( namespace , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> log_level = zpmlib . LOG_LEVEL_MAP . get ( namespace . log_level ) <EOL> logging . getLogger ( '<STR_LIT>' ) . setLevel ( log_level ) <EOL> swift_log = zpmlib . get_logger ( '<STR_LIT>' ) <EOL> swift_log . setLevel ( log_level ) <EOL> swift_log . addFilter ( SwiftLogFilter ( ) ) <EOL> return func ( namespace , * args , ** kwargs ) <EOL> return log_level_deco ( inner ) <EOL> def arg ( * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> envvar = kwargs . get ( '<STR_LIT>' ) <EOL> if envvar : <EOL> del kwargs [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' not in os . environ : <EOL> kwargs [ '<STR_LIT:default>' ] = os . environ . get ( envvar ) <EOL> kwargs [ '<STR_LIT>' ] += '<STR_LIT>' % envvar <EOL> else : <EOL> if '<STR_LIT:default>' in kwargs : <EOL> kwargs [ '<STR_LIT>' ] += '<STR_LIT>' % kwargs [ '<STR_LIT:default>' ] <EOL> def decorator ( func ) : <EOL> if not hasattr ( func , '<STR_LIT>' ) : <EOL> func . _args = [ ] <EOL> func . _args . append ( ( args , kwargs ) ) <EOL> return func <EOL> return decorator <EOL> def group_args ( accumulator ) : <EOL> """<STR_LIT>""" <EOL> def decorator ( func ) : <EOL> if not hasattr ( func , '<STR_LIT>' ) : <EOL> func . _args = [ ] <EOL> func . _args . extend ( accumulator . _args ) <EOL> return func <EOL> return decorator <EOL> @ group_args <EOL> @ arg ( '<STR_LIT>' , '<STR_LIT>' , choices = [ '<STR_LIT:1.0>' , '<STR_LIT>' ] , <EOL> help = '<STR_LIT>' ) <EOL> @ arg ( '<STR_LIT>' , '<STR_LIT>' , envvar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> @ arg ( '<STR_LIT>' , '<STR_LIT>' , envvar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> @ arg ( '<STR_LIT>' , '<STR_LIT>' , envvar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> @ arg ( '<STR_LIT>' , envvar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> @ arg ( '<STR_LIT>' , envvar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> @ arg ( '<STR_LIT>' , envvar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> @ arg ( '<STR_LIT>' , envvar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> def login_args ( ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def all_commands ( ) : <EOL> return sorted ( _commands , key = operator . attrgetter ( '<STR_LIT>' ) ) <EOL> @ command <EOL> @ arg ( '<STR_LIT>' , '<STR_LIT>' , help = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' ) <EOL> @ arg ( '<STR_LIT>' , '<STR_LIT>' , help = '<STR_LIT>' , <EOL> choices = [ '<STR_LIT>' ] , default = '<STR_LIT>' ) <EOL> @ arg ( '<STR_LIT>' , help = '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , nargs = '<STR_LIT:?>' , <EOL> default = '<STR_LIT:.>' ) <EOL> @ with_logging <EOL> def new ( args ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> project_files = zpm . create_project ( <EOL> args . dir , <EOL> with_ui = args . with_ui , <EOL> template = args . template ) <EOL> except Exception as err : <EOL> print ( err ) <EOL> else : <EOL> for proj_file in project_files : <EOL> print ( "<STR_LIT>" % proj_file ) <EOL> @ command <EOL> @ with_logging <EOL> @ arg ( '<STR_LIT>' , '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' ) <EOL> def bundle ( args ) : <EOL> """<STR_LIT>""" <EOL> root = zpm . find_project_root ( ) <EOL> zpm . bundle_project ( root , refresh_deps = args . refresh_deps ) <EOL> @ command <EOL> @ arg ( '<STR_LIT:target>' , help = '<STR_LIT>' ) <EOL> @ arg ( '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> @ arg ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> @ arg ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> @ arg ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> @ login_args <EOL> @ arg ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> @ with_logging <EOL> def deploy ( args ) : <EOL> """<STR_LIT>""" <EOL> LOG . info ( '<STR_LIT>' % args . zapp ) <EOL> zpm . deploy_project ( args ) <EOL> @ command <EOL> @ with_logging <EOL> @ arg ( '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> @ arg ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> @ arg ( '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> @ login_args <EOL> def execute ( args ) : <EOL> """<STR_LIT>""" <EOL> resp = zpm . execute ( args ) <EOL> if args . summary : <EOL> total_time , exec_table = zpm . _get_exec_table ( resp ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( exec_table ) <EOL> print ( '<STR_LIT>' % total_time ) <EOL> @ command <EOL> @ arg ( '<STR_LIT>' , nargs = '<STR_LIT:?>' , help = '<STR_LIT>' ) <EOL> def help ( args ) : <EOL> """<STR_LIT>""" <EOL> parser = set_up_arg_parser ( ) <EOL> cmd_names = [ c . __name__ for c in _commands ] <EOL> if args . command is None or args . command not in cmd_names : <EOL> if args . command is not None : <EOL> print ( '<STR_LIT>' % args . command ) <EOL> parser . print_help ( ) <EOL> else : <EOL> parser . parse_args ( [ args . command , '<STR_LIT>' ] ) <EOL> @ command <EOL> def version ( args ) : <EOL> """<STR_LIT>""" <EOL> parser = set_up_arg_parser ( ) <EOL> parser . parse_args ( [ '<STR_LIT>' ] ) <EOL> @ command <EOL> @ login_args <EOL> def auth ( args ) : <EOL> """<STR_LIT>""" <EOL> zpm . auth ( args ) </s>
