<s> from __future__ import with_statement <EOL> import sys <EOL> import os <EOL> import copy <EOL> import optparse <EOL> import re <EOL> import types <EOL> import inspect <EOL> import itertools <EOL> import operator <EOL> import traceback <EOL> import platform <EOL> from os . path import * <EOL> import paver . deps . six as six <EOL> from paver . deps . six import print_ <EOL> from paver . version import VERSION <EOL> if six . PY3 : <EOL> xrange = range <EOL> class PavementError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class BuildFailure ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class Environment ( object ) : <EOL> _task_in_progress = None <EOL> _task_output = None <EOL> _all_tasks = None <EOL> _dry_run = False <EOL> verbose = False <EOL> interactive = False <EOL> quiet = False <EOL> _file = "<STR_LIT>" <EOL> def __init__ ( self , pavement = None ) : <EOL> self . pavement = pavement <EOL> self . task_finders = [ ] <EOL> try : <EOL> from paver import options <EOL> self . options = options . Namespace ( ) <EOL> self . options . dry_run = False <EOL> self . options . pavement_file = self . pavement_file <EOL> except ImportError : <EOL> pass <EOL> def info ( self , message , * args ) : <EOL> self . _log ( <NUM_LIT:2> , message , args ) <EOL> def debug ( self , message , * args ) : <EOL> self . _log ( <NUM_LIT:1> , message , args ) <EOL> def error ( self , message , * args ) : <EOL> self . _log ( <NUM_LIT:3> , message , args ) <EOL> def _log ( self , level , message , args ) : <EOL> if args : <EOL> output = message % args <EOL> else : <EOL> output = message <EOL> if self . _task_output is not None : <EOL> self . _task_output . append ( output ) <EOL> if level > <NUM_LIT:2> or ( level > <NUM_LIT:1> and not self . quiet ) or self . verbose : <EOL> self . _print ( output ) <EOL> def _print ( self , output ) : <EOL> print_ ( output ) <EOL> sys . stdout . flush ( ) <EOL> def _exit ( self , code ) : <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> def _set_dry_run ( self , dr ) : <EOL> self . _dry_run = dr <EOL> try : <EOL> self . options . dry_run = dr <EOL> except AttributeError : <EOL> pass <EOL> def _get_dry_run ( self ) : <EOL> return self . _dry_run <EOL> dry_run = property ( _get_dry_run , _set_dry_run ) <EOL> def _set_pavement_file ( self , pavement_file ) : <EOL> self . _file = pavement_file <EOL> try : <EOL> self . options . pavement_file = pavement_file <EOL> except AttributeError : <EOL> pass <EOL> def _get_pavement_file ( self ) : <EOL> return self . _file <EOL> pavement_file = property ( _get_pavement_file , _set_pavement_file ) <EOL> file = property ( fset = _set_pavement_file ) <EOL> def get_task ( self , taskname ) : <EOL> task = getattr ( self . pavement , taskname , None ) <EOL> if not task : <EOL> for finder in self . task_finders : <EOL> task = finder . get_task ( taskname ) <EOL> if task : <EOL> break <EOL> if not task : <EOL> task = _import_task ( taskname ) <EOL> if not task : <EOL> all_tasks = self . get_tasks ( ) <EOL> matches = [ t for t in all_tasks <EOL> if t . shortname == taskname ] <EOL> if len ( matches ) > <NUM_LIT:1> : <EOL> matched_names = [ t . name for t in matches ] <EOL> raise BuildFailure ( "<STR_LIT>" % <EOL> ( taskname , matched_names ) ) <EOL> elif matches : <EOL> task = matches [ <NUM_LIT:0> ] <EOL> return task <EOL> def call_task ( self , task_name , args = None , options = None ) : <EOL> task = self . get_task ( task_name ) <EOL> if hasattr ( task , '<STR_LIT>' ) : <EOL> task . paver_constraint ( ) <EOL> if options : <EOL> for option in options : <EOL> task . _set_value_to_task ( task_name , option , None , options [ option ] ) <EOL> if args is not None and task . consume_args > <NUM_LIT:0> : <EOL> args = _consume_nargs ( task , args ) <EOL> elif args and ( task . consume_args == <NUM_LIT:0> ) : <EOL> raise BuildFailure ( "<STR_LIT>" <EOL> "<STR_LIT>" % task ) <EOL> task ( ) <EOL> def _run_task ( self , task_name , needs , func ) : <EOL> ( funcargs , varargs , varkw , defaults ) = inspect . getargspec ( func ) <EOL> kw = dict ( ) <EOL> for i in xrange ( <NUM_LIT:0> , len ( funcargs ) ) : <EOL> arg = funcargs [ i ] <EOL> if arg == '<STR_LIT>' : <EOL> kw [ '<STR_LIT>' ] = self <EOL> elif ( defaults is not None and <EOL> ( i - ( len ( funcargs ) - len ( defaults ) ) ) >= <NUM_LIT:0> ) : <EOL> pass <EOL> else : <EOL> try : <EOL> kw [ arg ] = getattr ( self , arg ) <EOL> except AttributeError : <EOL> raise PavementError ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( task_name , arg ) ) <EOL> if not self . _task_in_progress : <EOL> self . _task_in_progress = task_name <EOL> self . _task_output = [ ] <EOL> running_top_level = True <EOL> else : <EOL> running_top_level = False <EOL> def do_task ( ) : <EOL> self . info ( "<STR_LIT>" + task_name ) <EOL> for req in needs : <EOL> task = self . get_task ( req ) <EOL> if not task : <EOL> raise PavementError ( "<STR_LIT>" % <EOL> ( req , task_name ) ) <EOL> if not isinstance ( task , Task ) : <EOL> raise PavementError ( "<STR_LIT>" <EOL> % ( req , task_name ) ) <EOL> if not task . called : <EOL> task ( ) <EOL> return func ( ** kw ) <EOL> if running_top_level : <EOL> try : <EOL> return do_task ( ) <EOL> except Exception : <EOL> e = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> self . _print ( """<STR_LIT>""" ) <EOL> self . _print ( "<STR_LIT:\n>" . join ( map ( str , self . _task_output ) ) ) <EOL> if isinstance ( e , BuildFailure ) : <EOL> self . _print ( "<STR_LIT>" % <EOL> ( self . _task_in_progress , e ) ) <EOL> else : <EOL> self . _print ( traceback . format_exc ( ) ) <EOL> self . _task_in_progress = None <EOL> self . _task_output = None <EOL> self . _exit ( <NUM_LIT:1> ) <EOL> else : <EOL> return do_task ( ) <EOL> def get_tasks ( self ) : <EOL> if self . _all_tasks : <EOL> return self . _all_tasks <EOL> result = set ( ) <EOL> modules = set ( ) <EOL> def scan_module ( module ) : <EOL> modules . add ( module ) <EOL> for name in dir ( module ) : <EOL> try : <EOL> item = getattr ( module , name , None ) <EOL> except ImportError : <EOL> item = None <EOL> if isinstance ( item , Task ) : <EOL> result . add ( item ) <EOL> if isinstance ( item , types . ModuleType ) and item not in modules : <EOL> scan_module ( item ) <EOL> scan_module ( self . pavement ) <EOL> for finder in self . task_finders : <EOL> result . update ( finder . get_tasks ( ) ) <EOL> self . _all_tasks = result <EOL> return result <EOL> environment_stack = [ ] <EOL> environment = Environment ( ) <EOL> def _consume_nargs ( task , args ) : <EOL> """<STR_LIT>""" <EOL> if task . consume_args > <NUM_LIT:0> : <EOL> if ( args is None ) or ( task . consume_args != float ( '<STR_LIT>' ) and ( len ( args ) < task . consume_args ) ) : <EOL> args_consumed = "<STR_LIT>" <EOL> if task . consume_args == float ( '<STR_LIT>' ) : <EOL> args_consumed = "<STR_LIT>" <EOL> else : <EOL> args_consumed = "<STR_LIT>" % task . consume_args <EOL> args_consumed += "<STR_LIT:s>" if ( task . consume_args > <NUM_LIT:1> ) else "<STR_LIT>" <EOL> args_passed = "<STR_LIT:none>" if args is None else "<STR_LIT>" % len ( args ) <EOL> raise BuildFailure ( "<STR_LIT>" % ( task . name , args_consumed , args_passed ) ) <EOL> _args = args if task . consume_args == float ( '<STR_LIT>' ) else args [ : task . consume_args ] <EOL> try : <EOL> environment . options . args = _args <EOL> except AttributeError : <EOL> pass <EOL> environment . args = _args <EOL> return [ ] if task . consume_args == float ( '<STR_LIT>' ) else args [ task . consume_args : ] <EOL> def _import_task ( taskname ) : <EOL> """<STR_LIT>""" <EOL> parts = taskname . split ( '<STR_LIT:.>' ) <EOL> if len ( parts ) < <NUM_LIT:2> : <EOL> return None <EOL> func_name = parts [ - <NUM_LIT:1> ] <EOL> full_mod_name = "<STR_LIT:.>" . join ( parts [ : - <NUM_LIT:1> ] ) <EOL> mod_name = parts [ - <NUM_LIT:2> ] <EOL> try : <EOL> module = __import__ ( full_mod_name , globals ( ) , locals ( ) , [ mod_name ] ) <EOL> except ImportError : <EOL> return None <EOL> return getattr ( module , func_name , None ) <EOL> class Task ( object ) : <EOL> called = False <EOL> consume_args = <NUM_LIT:0> <EOL> no_auto = False <EOL> __doc__ = "<STR_LIT>" <EOL> def __init__ ( self , func ) : <EOL> super ( Task , self ) . __init__ ( ) <EOL> self . func = func <EOL> self . needs = [ ] <EOL> self . might_call = [ ] <EOL> self . __name__ = func . __name__ <EOL> self . shortname = func . __name__ <EOL> self . name = "<STR_LIT>" % ( func . __module__ , func . __name__ ) <EOL> self . option_names = set ( ) <EOL> self . user_options = [ ] <EOL> self . negative_opt = { } <EOL> self . share_options_with = [ ] <EOL> self . _parser = None <EOL> self . use_virtualenv = None <EOL> self . virtualenv_dir = None <EOL> try : <EOL> self . __doc__ = func . __doc__ <EOL> except AttributeError : <EOL> pass <EOL> def __call__ ( self , * args , ** kw ) : <EOL> if self . use_virtualenv and self . virtualenv_dir : <EOL> if platform . system ( ) == '<STR_LIT>' : <EOL> bin_dir = '<STR_LIT>' <EOL> else : <EOL> bin_dir = '<STR_LIT>' <EOL> activate_this = join ( self . virtualenv_dir , bin_dir , "<STR_LIT>" ) <EOL> with open ( activate_this ) as f : <EOL> s = f . read ( ) <EOL> code = compile ( s , activate_this , '<STR_LIT>' ) <EOL> exec ( code , dict ( __file__ = activate_this ) ) <EOL> retval = environment . _run_task ( self . name , self . needs , self . func ) <EOL> self . called = True <EOL> return retval <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" + self . __name__ <EOL> def _make_option_from_tuple ( self , option ) : <EOL> longname = option [ <NUM_LIT:0> ] <EOL> if longname and longname . endswith ( '<STR_LIT:=>' ) : <EOL> action = "<STR_LIT:store>" <EOL> longname = longname [ : - <NUM_LIT:1> ] <EOL> else : <EOL> action = "<STR_LIT:store_true>" <EOL> destination = longname . replace ( '<STR_LIT:->' , '<STR_LIT:_>' ) <EOL> opts = [ ] <EOL> if option [ <NUM_LIT:1> ] : <EOL> opts . append ( '<STR_LIT:->' + option [ <NUM_LIT:1> ] ) <EOL> if longname : <EOL> opts . append ( '<STR_LIT>' + longname ) <EOL> return optparse . make_option ( * opts , <EOL> ** dict ( action = action , dest = destination , help = option [ <NUM_LIT:2> ] ) ) <EOL> @ property <EOL> def parser ( self ) : <EOL> if getattr ( self , '<STR_LIT>' , None ) : <EOL> return self . _parser <EOL> self . _parser = parser = optparse . OptionParser ( add_help_option = False , <EOL> usage = "<STR_LIT>" % self . name ) <EOL> parser . disable_interspersed_args ( ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> needs_tasks = [ ( environment . get_task ( task ) , task ) for task in self . needs_closure ] <EOL> if getattr ( self , "<STR_LIT>" , None ) : <EOL> needs_tasks . extend ( ( environment . get_task ( task ) , task ) for task in self . might_call ) <EOL> shared_tasks = { } <EOL> parser . mirrored_options = { } <EOL> parser . options_to_hide_from_help = [ ] <EOL> for task , task_name in itertools . chain ( [ ( self , self . name ) ] , needs_tasks ) : <EOL> if not task : <EOL> raise PavementError ( "<STR_LIT>" <EOL> % ( task_name , self ) ) <EOL> for option in task . user_options : <EOL> add_options = True <EOL> try : <EOL> if not isinstance ( option , optparse . Option ) : <EOL> option = self . _make_option_from_tuple ( option ) <EOL> environment . debug ( "<STR_LIT>" % <EOL> ( self . name , str ( option ) ) ) <EOL> try : <EOL> longname = option . _long_opts [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> longname = None <EOL> try : <EOL> shortname = option . _short_opts [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> shortname = None <EOL> task_share_options_with = task . share_options_with or [ ] <EOL> task_shares = [ environment . get_task ( t ) . name for t in task_share_options_with if environment . get_task ( t ) ] <EOL> if self . share_options_with or task_shares : <EOL> options = ( shortname , longname ) <EOL> if ( <EOL> options in shared_tasks and ( shared_tasks [ options ] or self . share_options_with ) <EOL> ) or ( <EOL> self . name in [ environment . get_task ( t ) . name for t in task_share_options_with if environment . get_task ( t ) ] <EOL> ) : <EOL> environment . debug ( "<STR_LIT>" "<STR_LIT>" % <EOL> ( self . name , option ) ) <EOL> if option . dest not in parser . mirrored_options : <EOL> parser . mirrored_options [ option . dest ] = [ ] <EOL> parser . mirrored_options [ option . dest ] . append ( task_name ) <EOL> add_options = False <EOL> if options not in shared_tasks : <EOL> shared_tasks [ options ] = set ( ) <EOL> if task_share_options_with : <EOL> shared_tasks [ options ] |= set ( task_share_options_with ) <EOL> if add_options : <EOL> try : <EOL> parser . add_option ( option ) <EOL> except optparse . OptionConflictError : <EOL> raise PavementError ( """<STR_LIT>""" % ( self , option , task ) ) <EOL> self . option_names . add ( ( task . shortname , longname [ <NUM_LIT:2> : ] , option . dest ) ) <EOL> if getattr ( task , '<STR_LIT>' , False ) : <EOL> if shortname : <EOL> parser . options_to_hide_from_help . append ( shortname ) <EOL> elif longname : <EOL> parser . options_to_hide_from_help . append ( longname ) <EOL> except IndexError : <EOL> raise PavementError ( "<STR_LIT>" <EOL> % ( self , option ) ) <EOL> return parser <EOL> def display_help ( self , parser = None ) : <EOL> if not parser : <EOL> parser = self . parser <EOL> for opt_str in parser . options_to_hide_from_help : <EOL> try : <EOL> parser . remove_option ( opt_str ) <EOL> except ValueError : <EOL> environment . error ( "<STR_LIT>" % opt_str ) <EOL> name = self . name <EOL> print_ ( "<STR_LIT>" % name ) <EOL> print_ ( "<STR_LIT:->" * len ( name ) ) <EOL> parser . print_help ( ) <EOL> print_ ( ) <EOL> print_ ( self . __doc__ ) <EOL> print_ ( ) <EOL> def _set_value_to_task ( self , task_name , option_name , dist_option_name , value ) : <EOL> import paver . options <EOL> try : <EOL> optholder = environment . options [ task_name ] <EOL> except KeyError : <EOL> optholder = paver . options . Bunch ( ) <EOL> environment . options [ task_name ] = optholder <EOL> if value is not None : <EOL> if dist_option_name in getattr ( self , "<STR_LIT>" ) : <EOL> optholder [ self . negative_opt [ dist_option_name ] . replace ( '<STR_LIT:->' , '<STR_LIT:_>' ) ] = False <EOL> else : <EOL> optholder [ option_name ] = value <EOL> def parse_args ( self , args ) : <EOL> import paver . options <EOL> environment . debug ( "<STR_LIT>" % ( self . name , args ) ) <EOL> environment . options . setdefault ( self . shortname , paver . options . Bunch ( ) ) <EOL> parser = self . parser <EOL> options , args = parser . parse_args ( args ) <EOL> if options . help : <EOL> self . display_help ( parser ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> for task_name , option_name , option_dest in self . option_names : <EOL> if option_name != option_dest : <EOL> dist_option_name = copy . copy ( option_name ) <EOL> option_name = option_dest <EOL> else : <EOL> dist_option_name = option_name <EOL> option_name = option_name . replace ( '<STR_LIT:->' , '<STR_LIT:_>' ) <EOL> value = getattr ( options , option_name , getattr ( options , option_dest ) ) <EOL> self . _set_value_to_task ( task_name , option_name , dist_option_name , value ) <EOL> if option_name in parser . mirrored_options : <EOL> for task_name in parser . mirrored_options [ option_name ] : <EOL> self . _set_value_to_task ( task_name , option_name , dist_option_name , value ) <EOL> return args <EOL> @ property <EOL> def description ( self ) : <EOL> if self . __doc__ : <EOL> return re . split ( "<STR_LIT>" , self . __doc__ , maxsplit = <NUM_LIT:1> ) [ <NUM_LIT:0> ] . strip ( ) <EOL> else : <EOL> return "<STR_LIT>" <EOL> @ property <EOL> def needs_closure ( self ) : <EOL> stack = [ ] + self . needs <EOL> rv = [ ] <EOL> while stack : <EOL> top = stack . pop ( ) <EOL> if top not in rv : <EOL> rv . append ( top ) <EOL> needs = [ ] <EOL> if environment . get_task ( top ) : <EOL> deptask = environment . get_task ( top ) <EOL> if not isinstance ( deptask , Task ) : <EOL> raise BuildFailure ( "<STR_LIT>" % deptask ) <EOL> needs = deptask . needs <EOL> for t in needs : <EOL> stack . append ( t ) <EOL> return rv <EOL> def task ( func ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( func , Task ) : <EOL> return func <EOL> task = Task ( func ) <EOL> return task <EOL> def needs ( * args ) : <EOL> """<STR_LIT>""" <EOL> def entangle ( func ) : <EOL> req = args <EOL> func = task ( func ) <EOL> needs_list = func . needs <EOL> if len ( req ) == <NUM_LIT:1> : <EOL> req = req [ <NUM_LIT:0> ] <EOL> if isinstance ( req , six . string_types ) : <EOL> needs_list . append ( req ) <EOL> elif isinstance ( req , ( list , tuple ) ) : <EOL> needs_list . extend ( req ) <EOL> else : <EOL> raise PavementError ( "<STR_LIT>" <EOL> "<STR_LIT>" % req ) <EOL> return func <EOL> return entangle <EOL> def cmdopts ( options , share_with = None ) : <EOL> """<STR_LIT>""" <EOL> def entangle ( func ) : <EOL> func = task ( func ) <EOL> func . user_options = options <EOL> func . share_options_with = share_with <EOL> return func <EOL> return entangle <EOL> def might_call ( * args ) : <EOL> """<STR_LIT:U+0020>""" <EOL> def entangle ( func ) : <EOL> req = args <EOL> func = task ( func ) <EOL> might_call = func . might_call <EOL> if len ( req ) == <NUM_LIT:1> : <EOL> req = req [ <NUM_LIT:0> ] <EOL> if isinstance ( req , six . string_types ) : <EOL> might_call . append ( req ) <EOL> elif isinstance ( req , ( list , tuple ) ) : <EOL> might_call . extend ( req ) <EOL> else : <EOL> raise PavementError ( "<STR_LIT>" <EOL> "<STR_LIT>" % req ) <EOL> return func <EOL> return entangle <EOL> def consume_nargs ( nb_args = None ) : <EOL> """<STR_LIT>""" <EOL> def consume_args_wrapper ( func ) : <EOL> func = task ( func ) <EOL> func . consume_args = nb_args if nb_args is not None else float ( '<STR_LIT>' ) <EOL> return func <EOL> return consume_args_wrapper <EOL> def consume_args ( func ) : <EOL> """<STR_LIT>""" <EOL> return consume_nargs ( ) ( func ) <EOL> def no_auto ( func ) : <EOL> """<STR_LIT>""" <EOL> func = task ( func ) <EOL> func . no_auto = True <EOL> return func <EOL> def no_help ( func ) : <EOL> """<STR_LIT>""" <EOL> func = task ( func ) <EOL> func . no_help = True <EOL> return func <EOL> def _preparse ( args ) : <EOL> task = None <EOL> taskname = None <EOL> while args : <EOL> arg = args . pop ( <NUM_LIT:0> ) <EOL> if '<STR_LIT:=>' in arg : <EOL> key , value = arg . split ( "<STR_LIT:=>" ) <EOL> try : <EOL> environment . options . setdotted ( key , value ) <EOL> except AttributeError : <EOL> raise BuildFailure ( """<STR_LIT>""" % ( args ) ) <EOL> elif arg . startswith ( '<STR_LIT:->' ) : <EOL> args . insert ( <NUM_LIT:0> , arg ) <EOL> break <EOL> else : <EOL> taskname = arg <EOL> task = environment . get_task ( taskname ) <EOL> if task is None : <EOL> raise BuildFailure ( "<STR_LIT>" % taskname ) <EOL> break <EOL> return task , taskname , args <EOL> def _parse_global_options ( args ) : <EOL> parser = optparse . OptionParser ( usage = <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" , version = "<STR_LIT>" % ( VERSION ) , <EOL> add_help_option = False ) <EOL> environment . help_function = parser . print_help <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( '<STR_LIT>' , "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( '<STR_LIT>' , "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , action = "<STR_LIT:store>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . set_defaults ( file = environment . pavement_file ) <EOL> parser . disable_interspersed_args ( ) <EOL> options , args = parser . parse_args ( args ) <EOL> if options . help : <EOL> args . insert ( <NUM_LIT:0> , "<STR_LIT>" ) <EOL> for key , value in vars ( options ) . items ( ) : <EOL> setattr ( environment , key , value ) <EOL> return args <EOL> def _parse_command_line ( args ) : <EOL> task , taskname , args = _preparse ( args ) <EOL> if not task : <EOL> args = _parse_global_options ( args ) <EOL> if not args : <EOL> return None , [ ] <EOL> taskname = args . pop ( <NUM_LIT:0> ) <EOL> task = environment . get_task ( taskname ) <EOL> if not task : <EOL> raise BuildFailure ( "<STR_LIT>" % taskname ) <EOL> if not isinstance ( task , Task ) : <EOL> raise BuildFailure ( "<STR_LIT>" % taskname ) <EOL> if task . consume_args != float ( '<STR_LIT>' ) : <EOL> args = task . parse_args ( args ) <EOL> if task . consume_args > <NUM_LIT:0> : <EOL> args = _consume_nargs ( task , args ) <EOL> return task , args <EOL> def _cmp_task_names ( a , b ) : <EOL> a = a . name <EOL> b = b . name <EOL> a_in_pavement = a . startswith ( "<STR_LIT>" ) <EOL> b_in_pavement = b . startswith ( "<STR_LIT>" ) <EOL> if a_in_pavement and not b_in_pavement : <EOL> return <NUM_LIT:1> <EOL> if b_in_pavement and not a_in_pavement : <EOL> return - <NUM_LIT:1> <EOL> return ( a > b ) - ( b < a ) <EOL> if six . PY3 : <EOL> import functools <EOL> _task_names_key = functools . cmp_to_key ( _cmp_task_names ) <EOL> def _group_by_module ( items ) : <EOL> def key ( item ) : <EOL> dotpos = item . name . rfind ( '<STR_LIT:.>' ) <EOL> return item . name [ : dotpos ] <EOL> maxlen = max ( len ( item . shortname ) for item in items ) <EOL> groups = itertools . groupby ( sorted ( items , key = operator . attrgetter ( '<STR_LIT:name>' ) ) , key = key ) <EOL> return maxlen , groups <EOL> @ task <EOL> @ no_auto <EOL> @ consume_args <EOL> def help ( args , help_function ) : <EOL> """<STR_LIT>""" <EOL> if args : <EOL> task_name = args [ <NUM_LIT:0> ] <EOL> task = environment . get_task ( task_name ) <EOL> if not task : <EOL> print_ ( "<STR_LIT>" % ( task_name ) ) <EOL> return <EOL> task . display_help ( ) <EOL> return <EOL> help_function ( ) <EOL> task_list = environment . get_tasks ( ) <EOL> if six . PY3 : <EOL> task_list = sorted ( task_list , key = _task_names_key ) <EOL> else : <EOL> task_list = sorted ( task_list , cmp = _cmp_task_names ) <EOL> maxlen , task_list = _group_by_module ( task_list ) <EOL> fmt = "<STR_LIT>" + str ( maxlen ) + "<STR_LIT>" <EOL> for group_name , group in task_list : <EOL> print_ ( "<STR_LIT>" % ( group_name ) ) <EOL> for task in group : <EOL> if not getattr ( task , "<STR_LIT>" , False ) : <EOL> print_ ( fmt % ( task . shortname , task . description ) ) <EOL> def _process_commands ( args , auto_pending = False ) : <EOL> first_loop = True <EOL> while True : <EOL> task , args = _parse_command_line ( args ) <EOL> if auto_pending : <EOL> if task and not task . no_auto : <EOL> environment . call_task ( '<STR_LIT>' ) <EOL> auto_pending = False <EOL> if task is None : <EOL> if first_loop : <EOL> task = environment . get_task ( '<STR_LIT:default>' ) <EOL> if not task : <EOL> break <EOL> else : <EOL> break <EOL> task ( ) <EOL> first_loop = False <EOL> def call_pavement ( new_pavement , args ) : <EOL> if isinstance ( args , six . string_types ) : <EOL> args = args . split ( ) <EOL> global environment <EOL> environment_stack . append ( environment ) <EOL> environment = Environment ( ) <EOL> cwd = os . getcwd ( ) <EOL> dirname , basename = split ( new_pavement ) <EOL> environment . pavement_file = basename <EOL> try : <EOL> if dirname : <EOL> os . chdir ( dirname ) <EOL> _launch_pavement ( args ) <EOL> finally : <EOL> os . chdir ( cwd ) <EOL> environment = environment_stack . pop ( ) <EOL> def _launch_pavement ( args ) : <EOL> mod = types . ModuleType ( "<STR_LIT>" ) <EOL> environment . pavement = mod <EOL> if not exists ( environment . pavement_file ) : <EOL> environment . pavement_file = None <EOL> six . exec_ ( "<STR_LIT>" , mod . __dict__ ) <EOL> _process_commands ( args ) <EOL> return <EOL> mod . __file__ = environment . pavement_file <EOL> try : <EOL> pf = open ( environment . pavement_file ) <EOL> try : <EOL> source = pf . read ( ) <EOL> finally : <EOL> pf . close ( ) <EOL> exec ( compile ( source , environment . pavement_file , '<STR_LIT>' ) , mod . __dict__ ) <EOL> auto_task = getattr ( mod , '<STR_LIT>' , None ) <EOL> auto_pending = isinstance ( auto_task , Task ) <EOL> from paver . misctasks import generate_setup , minilib <EOL> resident_tasks = { <EOL> '<STR_LIT>' : help , <EOL> '<STR_LIT>' : generate_setup , <EOL> '<STR_LIT>' : minilib , <EOL> } <EOL> mod . __dict__ . update ( resident_tasks ) <EOL> _process_commands ( args , auto_pending = auto_pending ) <EOL> except PavementError : <EOL> e = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> if getattr ( environment . options , "<STR_LIT>" , False ) or '<STR_LIT>' in args : <EOL> raise <EOL> print_ ( "<STR_LIT>" % ( <EOL> abspath ( environment . pavement_file ) , e ) ) <EOL> def main ( args = None ) : <EOL> global environment <EOL> if args is None : <EOL> args = sys . argv [ <NUM_LIT:1> : ] <EOL> environment = Environment ( ) <EOL> try : <EOL> args = _parse_global_options ( args ) <EOL> _launch_pavement ( args ) <EOL> except BuildFailure : <EOL> e = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> environment . error ( "<STR_LIT>" , e ) <EOL> sys . exit ( <NUM_LIT:1> ) </s>
