<s> """<STR_LIT>""" <EOL> import datetime <EOL> import optparse <EOL> import sys <EOL> import traceback <EOL> import re <EOL> from pybuilder import __version__ <EOL> from pybuilder . core import Logger <EOL> from pybuilder . errors import PyBuilderException <EOL> from pybuilder . execution import ExecutionManager <EOL> from pybuilder . reactor import Reactor <EOL> from pybuilder . scaffolding import start_project , update_project <EOL> from pybuilder . terminal import ( BOLD , BROWN , RED , GREEN , bold , styled_text , <EOL> fg , italic , print_text , print_text_line , <EOL> print_error , print_error_line , draw_line ) <EOL> from pybuilder . utils import format_timestamp , get_dist_version_string <EOL> PROPERTY_OVERRIDE_PATTERN = re . compile ( r'<STR_LIT>' ) <EOL> class CommandLineUsageException ( PyBuilderException ) : <EOL> def __init__ ( self , usage , message ) : <EOL> super ( CommandLineUsageException , self ) . __init__ ( message ) <EOL> self . usage = usage <EOL> class StdOutLogger ( Logger ) : <EOL> def _level_to_string ( self , level ) : <EOL> if Logger . DEBUG == level : <EOL> return "<STR_LIT>" <EOL> if Logger . INFO == level : <EOL> return "<STR_LIT>" <EOL> if Logger . WARN == level : <EOL> return "<STR_LIT>" <EOL> return "<STR_LIT>" <EOL> def _do_log ( self , level , message , * arguments ) : <EOL> formatted_message = self . _format_message ( message , * arguments ) <EOL> log_level = self . _level_to_string ( level ) <EOL> print_text_line ( "<STR_LIT>" . format ( log_level , formatted_message ) ) <EOL> class ColoredStdOutLogger ( StdOutLogger ) : <EOL> def _level_to_string ( self , level ) : <EOL> if Logger . DEBUG == level : <EOL> return italic ( "<STR_LIT>" ) <EOL> if Logger . INFO == level : <EOL> return bold ( "<STR_LIT>" ) <EOL> if Logger . WARN == level : <EOL> return styled_text ( "<STR_LIT>" , BOLD , fg ( BROWN ) ) <EOL> return styled_text ( "<STR_LIT>" , BOLD , fg ( RED ) ) <EOL> def parse_options ( args ) : <EOL> parser = optparse . OptionParser ( usage = "<STR_LIT>" , <EOL> version = "<STR_LIT>" + __version__ ) <EOL> def error ( msg ) : <EOL> raise CommandLineUsageException ( <EOL> parser . get_usage ( ) + parser . format_option_help ( ) , msg ) <EOL> parser . error = error <EOL> list_tasks_option = parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> dest = "<STR_LIT>" , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> list_plan_tasks_option = parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> dest = "<STR_LIT>" , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> start_project_option = parser . add_option ( "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> dest = "<STR_LIT>" , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> update_project_option = parser . add_option ( "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> dest = "<STR_LIT>" , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> dest = "<STR_LIT>" , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> project_group = optparse . OptionGroup ( <EOL> parser , "<STR_LIT>" , "<STR_LIT>" ) <EOL> project_group . add_option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" , <EOL> metavar = "<STR_LIT>" , <EOL> default = "<STR_LIT:.>" ) <EOL> project_group . add_option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" , <EOL> metavar = "<STR_LIT>" , <EOL> action = "<STR_LIT>" , <EOL> default = [ ] ) <EOL> project_group . add_option ( "<STR_LIT>" , <EOL> action = "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , <EOL> default = [ ] , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> project_group . add_option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> action = "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , <EOL> default = [ ] , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> project_group . add_option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> dest = "<STR_LIT>" , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> project_group . add_option ( "<STR_LIT>" , <EOL> action = "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , <EOL> default = [ ] , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser . add_option_group ( project_group ) <EOL> output_group = optparse . OptionGroup ( <EOL> parser , "<STR_LIT>" , "<STR_LIT>" ) <EOL> output_group . add_option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> dest = "<STR_LIT>" , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> output_group . add_option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> dest = "<STR_LIT>" , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> output_group . add_option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> dest = "<STR_LIT>" , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> output_group . add_option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> dest = "<STR_LIT>" , <EOL> default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option_group ( output_group ) <EOL> options , arguments = parser . parse_args ( args = list ( args ) ) <EOL> if options . list_tasks and options . list_plan_tasks : <EOL> parser . error ( "<STR_LIT>" % ( list_tasks_option , list_plan_tasks_option ) ) <EOL> if options . start_project and options . update_project : <EOL> parser . error ( "<STR_LIT>" % ( start_project_option , update_project_option ) ) <EOL> property_overrides = { } <EOL> for pair in options . property_overrides : <EOL> if not PROPERTY_OVERRIDE_PATTERN . match ( pair ) : <EOL> parser . error ( "<STR_LIT>" % pair ) <EOL> key , val = pair . split ( "<STR_LIT:=>" ) <EOL> property_overrides [ key ] = val <EOL> options . property_overrides = property_overrides <EOL> if options . very_quiet : <EOL> options . quiet = True <EOL> return options , arguments <EOL> def init_reactor ( logger ) : <EOL> execution_manager = ExecutionManager ( logger ) <EOL> reactor = Reactor ( logger , execution_manager ) <EOL> return reactor <EOL> def should_colorize ( options ) : <EOL> return sys . stdout . isatty ( ) and not options . no_color <EOL> def init_logger ( options ) : <EOL> threshold = Logger . INFO <EOL> if options . debug : <EOL> threshold = Logger . DEBUG <EOL> elif options . quiet : <EOL> threshold = Logger . WARN <EOL> if not should_colorize ( options ) : <EOL> logger = StdOutLogger ( threshold ) <EOL> else : <EOL> logger = ColoredStdOutLogger ( threshold ) <EOL> return logger <EOL> def print_build_summary ( options , summary ) : <EOL> print_text_line ( "<STR_LIT>" ) <EOL> print_text_line ( "<STR_LIT>" % ( "<STR_LIT>" , summary . project . name ) ) <EOL> print_text_line ( "<STR_LIT>" % ( "<STR_LIT>" , summary . project . version , get_dist_version_string ( summary . project ) ) ) <EOL> print_text_line ( "<STR_LIT>" % ( "<STR_LIT>" , summary . project . basedir ) ) <EOL> print_text_line ( "<STR_LIT>" % <EOL> ( "<STR_LIT>" , "<STR_LIT:U+002CU+0020>" . join ( options . environments ) ) ) <EOL> task_summary = "<STR_LIT>" <EOL> for task in summary . task_summaries : <EOL> task_summary += "<STR_LIT>" % ( task . task , task . execution_time ) <EOL> print_text_line ( "<STR_LIT>" % ( "<STR_LIT>" , task_summary ) ) <EOL> def print_styled_text ( text , options , * style_attributes ) : <EOL> if should_colorize ( options ) : <EOL> text = styled_text ( text , * style_attributes ) <EOL> print_text ( text ) <EOL> def print_styled_text_line ( text , options , * style_attributes ) : <EOL> print_styled_text ( text + "<STR_LIT:\n>" , options , * style_attributes ) <EOL> def print_build_status ( failure_message , options , successful ) : <EOL> draw_line ( ) <EOL> if successful : <EOL> print_styled_text_line ( "<STR_LIT>" , options , BOLD , fg ( GREEN ) ) <EOL> else : <EOL> print_styled_text_line ( <EOL> "<STR_LIT>" . format ( failure_message ) , options , BOLD , fg ( RED ) ) <EOL> draw_line ( ) <EOL> def print_elapsed_time_summary ( start , end ) : <EOL> time_needed = end - start <EOL> millis = ( ( time_needed . days * <NUM_LIT> * <NUM_LIT> * <NUM_LIT> ) + time_needed . seconds ) * <NUM_LIT:1000> + time_needed . microseconds / <NUM_LIT:1000> <EOL> print_text_line ( "<STR_LIT>" % format_timestamp ( end ) ) <EOL> print_text_line ( "<STR_LIT>" % <EOL> ( time_needed . seconds , millis ) ) <EOL> def print_summary ( successful , summary , start , end , options , failure_message ) : <EOL> print_build_status ( failure_message , options , successful ) <EOL> if successful and summary : <EOL> print_build_summary ( options , summary ) <EOL> print_elapsed_time_summary ( start , end ) <EOL> def length_of_longest_string ( list_of_strings ) : <EOL> if len ( list_of_strings ) == <NUM_LIT:0> : <EOL> return <NUM_LIT:0> <EOL> result = <NUM_LIT:0> <EOL> for string in list_of_strings : <EOL> length_of_string = len ( string ) <EOL> if length_of_string > result : <EOL> result = length_of_string <EOL> return result <EOL> def task_description ( task ) : <EOL> return "<STR_LIT:U+0020>" . join ( task . description ) or "<STR_LIT>" <EOL> def print_task_list ( tasks , quiet = False ) : <EOL> if quiet : <EOL> print_text_line ( "<STR_LIT:\n>" . join ( [ task . name + "<STR_LIT::>" + task_description ( task ) <EOL> for task in tasks ] ) ) <EOL> return <EOL> column_length = length_of_longest_string ( <EOL> list ( map ( lambda task : task . name , tasks ) ) ) <EOL> column_length += <NUM_LIT:4> <EOL> for task in tasks : <EOL> task_name = task . name . rjust ( column_length ) <EOL> print_text_line ( "<STR_LIT>" . format ( task_name , task_description ( task ) ) ) <EOL> if task . dependencies : <EOL> whitespace = ( column_length + <NUM_LIT:3> ) * "<STR_LIT:U+0020>" <EOL> depends_on_message = "<STR_LIT>" % "<STR_LIT:U+0020>" . join ( <EOL> [ str ( dependency ) for dependency in task . dependencies ] ) <EOL> print_text_line ( whitespace + depends_on_message ) <EOL> def print_list_of_tasks ( reactor , quiet = False ) : <EOL> tasks = reactor . get_tasks ( ) <EOL> sorted_tasks = sorted ( tasks ) <EOL> if not quiet : <EOL> print_text_line ( '<STR_LIT>' % reactor . project . name ) <EOL> print_task_list ( sorted_tasks , quiet ) <EOL> def print_plan_list_of_tasks ( options , arguments , reactor , quiet = False ) : <EOL> execution_plan = reactor . create_execution_plan ( arguments , options . environments ) <EOL> if not quiet : <EOL> print_text_line ( '<STR_LIT>' % reactor . project . name ) <EOL> print_task_list ( execution_plan , quiet ) <EOL> def main ( * args ) : <EOL> if not args : <EOL> args = sys . argv [ <NUM_LIT:1> : ] <EOL> try : <EOL> options , arguments = parse_options ( args ) <EOL> except CommandLineUsageException as e : <EOL> print_error_line ( "<STR_LIT>" % e ) <EOL> print_error ( e . usage ) <EOL> return <NUM_LIT:1> <EOL> start = datetime . datetime . now ( ) <EOL> logger = init_logger ( options ) <EOL> reactor = init_reactor ( logger ) <EOL> if options . start_project : <EOL> return start_project ( ) <EOL> if options . update_project : <EOL> return update_project ( ) <EOL> if options . list_tasks or options . list_plan_tasks : <EOL> try : <EOL> reactor . prepare_build ( property_overrides = options . property_overrides , <EOL> project_directory = options . project_directory , <EOL> exclude_optional_tasks = options . exclude_optional_tasks , <EOL> exclude_tasks = options . exclude_tasks , <EOL> exclude_all_optional = options . exclude_all_optional <EOL> ) <EOL> if options . list_tasks : <EOL> print_list_of_tasks ( reactor , quiet = options . very_quiet ) <EOL> if options . list_plan_tasks : <EOL> print_plan_list_of_tasks ( options , arguments , reactor , quiet = options . very_quiet ) <EOL> return <NUM_LIT:0> <EOL> except PyBuilderException as e : <EOL> print_build_status ( str ( e ) , options , successful = False ) <EOL> return <NUM_LIT:1> <EOL> if not options . very_quiet : <EOL> print_styled_text_line ( <EOL> "<STR_LIT>" . format ( __version__ ) , options , BOLD ) <EOL> print_text_line ( "<STR_LIT>" % format_timestamp ( start ) ) <EOL> draw_line ( ) <EOL> successful = True <EOL> failure_message = None <EOL> summary = None <EOL> try : <EOL> try : <EOL> reactor . prepare_build ( property_overrides = options . property_overrides , <EOL> project_directory = options . project_directory , <EOL> exclude_optional_tasks = options . exclude_optional_tasks , <EOL> exclude_tasks = options . exclude_tasks , <EOL> exclude_all_optional = options . exclude_all_optional <EOL> ) <EOL> if options . verbose or options . debug : <EOL> logger . debug ( "<STR_LIT>" ) <EOL> reactor . project . set_property ( "<STR_LIT>" , True ) <EOL> summary = reactor . build ( <EOL> environments = options . environments , tasks = arguments ) <EOL> except KeyboardInterrupt : <EOL> raise PyBuilderException ( "<STR_LIT>" ) <EOL> except ( Exception , SystemExit ) as e : <EOL> failure_message = str ( e ) <EOL> if options . debug : <EOL> traceback . print_exc ( file = sys . stderr ) <EOL> successful = False <EOL> finally : <EOL> end = datetime . datetime . now ( ) <EOL> if not options . very_quiet : <EOL> print_summary ( <EOL> successful , summary , start , end , options , failure_message ) <EOL> if not successful : <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> </s>
