<s> import time <EOL> import traceback <EOL> from contextlib import contextmanager <EOL> import click <EOL> from click import style <EOL> from werkzeug . local import LocalProxy , LocalStack <EOL> from lektor . _compat import text_type <EOL> _reporter_stack = LocalStack ( ) <EOL> _build_buffer_stack = LocalStack ( ) <EOL> def describe_build_func ( func ) : <EOL> self = getattr ( func , '<STR_LIT>' , None ) <EOL> if self is not None and any ( x . __name__ == '<STR_LIT>' <EOL> for x in self . __class__ . __mro__ ) : <EOL> return self . __class__ . __module__ + '<STR_LIT:.>' + self . __class__ . __name__ <EOL> return func . __module__ + '<STR_LIT:.>' + func . __name__ <EOL> class Reporter ( object ) : <EOL> def __init__ ( self , env , verbosity = <NUM_LIT:0> ) : <EOL> self . env = env <EOL> self . verbosity = verbosity <EOL> self . builder_stack = [ ] <EOL> self . artifact_stack = [ ] <EOL> self . source_stack = [ ] <EOL> def push ( self ) : <EOL> _reporter_stack . push ( self ) <EOL> def pop ( self ) : <EOL> _reporter_stack . pop ( ) <EOL> def __enter__ ( self ) : <EOL> self . push ( ) <EOL> return self <EOL> def __exit__ ( self , exc_type , exc_value , tb ) : <EOL> self . pop ( ) <EOL> @ property <EOL> def builder ( self ) : <EOL> if self . builder_stack : <EOL> return self . builder_stack [ - <NUM_LIT:1> ] <EOL> @ property <EOL> def current_artifact ( self ) : <EOL> if self . artifact_stack : <EOL> return self . artifact_stack [ - <NUM_LIT:1> ] <EOL> @ property <EOL> def current_source ( self ) : <EOL> if self . source_stack : <EOL> return self . source_stack [ - <NUM_LIT:1> ] <EOL> @ property <EOL> def show_build_info ( self ) : <EOL> return self . verbosity >= <NUM_LIT:1> <EOL> @ property <EOL> def show_tracebacks ( self ) : <EOL> return self . verbosity >= <NUM_LIT:1> <EOL> @ property <EOL> def show_current_artifacts ( self ) : <EOL> return self . verbosity >= <NUM_LIT:2> <EOL> @ property <EOL> def show_artifact_internals ( self ) : <EOL> return self . verbosity >= <NUM_LIT:3> <EOL> @ property <EOL> def show_source_internals ( self ) : <EOL> return self . verbosity >= <NUM_LIT:3> <EOL> @ property <EOL> def show_debug_info ( self ) : <EOL> return self . verbosity >= <NUM_LIT:4> <EOL> @ contextmanager <EOL> def build ( self , activity , builder ) : <EOL> now = time . time ( ) <EOL> self . builder_stack . append ( builder ) <EOL> self . start_build ( activity ) <EOL> try : <EOL> yield <EOL> finally : <EOL> self . builder_stack . pop ( ) <EOL> self . finish_build ( activity , now ) <EOL> def start_build ( self , activity ) : <EOL> pass <EOL> def finish_build ( self , activity , start_time ) : <EOL> pass <EOL> @ contextmanager <EOL> def build_artifact ( self , artifact , build_func , is_current ) : <EOL> now = time . time ( ) <EOL> self . artifact_stack . append ( artifact ) <EOL> self . start_artifact_build ( is_current ) <EOL> self . report_build_func ( build_func ) <EOL> try : <EOL> yield <EOL> finally : <EOL> self . finish_artifact_build ( now ) <EOL> self . artifact_stack . pop ( ) <EOL> def start_artifact_build ( self , is_current ) : <EOL> pass <EOL> def finish_artifact_build ( self , start_time ) : <EOL> pass <EOL> def report_failure ( self , artifact , exc_info ) : <EOL> pass <EOL> def report_build_all_failure ( self , failures ) : <EOL> pass <EOL> def report_dependencies ( self , dependencies ) : <EOL> for dep in dependencies : <EOL> self . report_debug_info ( '<STR_LIT>' , dep [ <NUM_LIT:1> ] ) <EOL> def report_dirty_flag ( self , value ) : <EOL> pass <EOL> def report_write_source_info ( self , info ) : <EOL> pass <EOL> def report_prune_source_info ( self , source ) : <EOL> pass <EOL> def report_sub_artifact ( self , artifact ) : <EOL> pass <EOL> def report_build_func ( self , build_func ) : <EOL> pass <EOL> def report_debug_info ( self , key , value ) : <EOL> pass <EOL> def report_generic ( self , message ) : <EOL> pass <EOL> def report_pruned_artifact ( self , artifact_name ) : <EOL> pass <EOL> @ contextmanager <EOL> def process_source ( self , source ) : <EOL> now = time . time ( ) <EOL> self . source_stack . append ( source ) <EOL> self . enter_source ( ) <EOL> try : <EOL> yield <EOL> finally : <EOL> self . leave_source ( now ) <EOL> self . source_stack . pop ( ) <EOL> def enter_source ( self ) : <EOL> pass <EOL> def leave_source ( self , start_time ) : <EOL> pass <EOL> class NullReporter ( Reporter ) : <EOL> pass <EOL> class BufferReporter ( Reporter ) : <EOL> def __init__ ( self , env , verbosity = <NUM_LIT:0> ) : <EOL> Reporter . __init__ ( self , env , verbosity ) <EOL> self . buffer = [ ] <EOL> def clear ( self ) : <EOL> self . buffer = [ ] <EOL> def get_recorded_dependencies ( self ) : <EOL> rv = set ( ) <EOL> for event , data in self . buffer : <EOL> if event == '<STR_LIT>' and data [ '<STR_LIT:key>' ] == '<STR_LIT>' : <EOL> rv . add ( data [ '<STR_LIT:value>' ] ) <EOL> return sorted ( rv ) <EOL> def get_major_events ( self ) : <EOL> rv = [ ] <EOL> for event , data in self . buffer : <EOL> if event not in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> rv . append ( ( event , data ) ) <EOL> return rv <EOL> def get_failures ( self ) : <EOL> rv = [ ] <EOL> for event , data in self . buffer : <EOL> if event == '<STR_LIT>' : <EOL> rv . append ( data ) <EOL> return rv <EOL> def _emit ( self , _event , ** extra ) : <EOL> self . buffer . append ( ( _event , extra ) ) <EOL> def start_build ( self , activity ) : <EOL> self . _emit ( '<STR_LIT>' , activity = activity ) <EOL> def finish_build ( self , activity , start_time ) : <EOL> self . _emit ( '<STR_LIT>' , activity = activity ) <EOL> def start_artifact_build ( self , is_current ) : <EOL> self . _emit ( '<STR_LIT>' , artifact = self . current_artifact , <EOL> is_current = is_current ) <EOL> def finish_artifact_build ( self , start_time ) : <EOL> self . _emit ( '<STR_LIT>' , artifact = self . current_artifact ) <EOL> def report_build_all_failure ( self , failures ) : <EOL> self . _emit ( '<STR_LIT>' , failures = failures ) <EOL> def report_failure ( self , artifact , exc_info ) : <EOL> self . _emit ( '<STR_LIT>' , artifact = artifact , exc_info = exc_info ) <EOL> def report_dirty_flag ( self , value ) : <EOL> self . _emit ( '<STR_LIT>' , artifact = self . current_artifact , <EOL> value = value ) <EOL> def report_write_source_info ( self , info ) : <EOL> self . _emit ( '<STR_LIT>' , info = info , <EOL> artifact = self . current_artifact ) <EOL> def report_prune_source_info ( self , source ) : <EOL> self . _emit ( '<STR_LIT>' , source = source ) <EOL> def report_build_func ( self , build_func ) : <EOL> self . _emit ( '<STR_LIT>' , func = describe_build_func ( build_func ) ) <EOL> def report_sub_artifact ( self , artifact ) : <EOL> self . _emit ( '<STR_LIT>' , artifact = artifact ) <EOL> def report_debug_info ( self , key , value ) : <EOL> self . _emit ( '<STR_LIT>' , key = key , value = value ) <EOL> def report_generic ( self , message ) : <EOL> self . _emit ( '<STR_LIT>' , message = message ) <EOL> def enter_source ( self ) : <EOL> self . _emit ( '<STR_LIT>' , source = self . current_source ) <EOL> def leave_source ( self , start_time ) : <EOL> self . _emit ( '<STR_LIT>' , source = self . current_source ) <EOL> def report_pruned_artifact ( self , artifact_name ) : <EOL> self . _emit ( '<STR_LIT>' , artifact_name = artifact_name ) <EOL> class CliReporter ( Reporter ) : <EOL> def __init__ ( self , env , verbosity = <NUM_LIT:0> ) : <EOL> Reporter . __init__ ( self , env , verbosity ) <EOL> self . indentation = <NUM_LIT:0> <EOL> def indent ( self ) : <EOL> self . indentation += <NUM_LIT:1> <EOL> def outdent ( self ) : <EOL> self . indentation -= <NUM_LIT:1> <EOL> def _write_line ( self , text ) : <EOL> click . echo ( '<STR_LIT:U+0020>' * ( self . indentation * <NUM_LIT:2> ) + text ) <EOL> def _write_kv_info ( self , key , value ) : <EOL> self . _write_line ( '<STR_LIT>' % ( key , style ( text_type ( value ) , fg = '<STR_LIT>' ) ) ) <EOL> def start_build ( self , activity ) : <EOL> self . _write_line ( style ( '<STR_LIT>' % activity , fg = '<STR_LIT>' ) ) <EOL> if not self . show_build_info : <EOL> return <EOL> self . _write_line ( style ( '<STR_LIT>' % self . env . root_path , fg = '<STR_LIT>' ) ) <EOL> self . _write_line ( style ( '<STR_LIT>' % <EOL> self . builder . destination_path , fg = '<STR_LIT>' ) ) <EOL> def finish_build ( self , activity , start_time ) : <EOL> self . _write_line ( style ( '<STR_LIT>' % ( <EOL> activity , time . time ( ) - start_time ) , fg = '<STR_LIT>' ) ) <EOL> def start_artifact_build ( self , is_current ) : <EOL> artifact = self . current_artifact <EOL> if is_current : <EOL> if not self . show_current_artifacts : <EOL> return <EOL> sign = click . style ( '<STR_LIT:X>' , fg = '<STR_LIT>' ) <EOL> else : <EOL> sign = click . style ( '<STR_LIT>' , fg = '<STR_LIT>' ) <EOL> self . _write_line ( '<STR_LIT>' % ( sign , artifact . artifact_name ) ) <EOL> self . indent ( ) <EOL> def finish_artifact_build ( self , start_time ) : <EOL> self . outdent ( ) <EOL> def report_build_all_failure ( self , failures ) : <EOL> self . _write_line ( click . style ( <EOL> '<STR_LIT>' % ( <EOL> failures , failures != <NUM_LIT:1> and '<STR_LIT:s>' or '<STR_LIT>' ) , fg = '<STR_LIT>' ) ) <EOL> def report_failure ( self , artifact , exc_info ) : <EOL> sign = click . style ( '<STR_LIT:E>' , fg = '<STR_LIT>' ) <EOL> err = '<STR_LIT:U+0020>' . join ( '<STR_LIT>' . join ( traceback . format_exception_only ( <EOL> * exc_info [ : <NUM_LIT:2> ] ) ) . splitlines ( ) ) . strip ( ) <EOL> self . _write_line ( '<STR_LIT>' % ( <EOL> sign , artifact . artifact_name , err ) ) <EOL> if not self . show_tracebacks : <EOL> return <EOL> tb = traceback . format_exception ( * exc_info ) <EOL> for line in '<STR_LIT>' . join ( tb ) . splitlines ( ) : <EOL> if line . startswith ( '<STR_LIT>' ) : <EOL> line = click . style ( line , fg = '<STR_LIT>' ) <EOL> elif line . startswith ( '<STR_LIT>' ) : <EOL> line = click . style ( line , fg = '<STR_LIT>' ) <EOL> elif not line . startswith ( '<STR_LIT:U+0020>' ) : <EOL> line = click . style ( line , fg = '<STR_LIT>' ) <EOL> self . _write_line ( '<STR_LIT:U+0020>' + line ) <EOL> def report_dirty_flag ( self , value ) : <EOL> if self . show_artifact_internals and ( value or self . show_debug_info ) : <EOL> self . _write_kv_info ( '<STR_LIT>' , value ) <EOL> def report_write_source_info ( self , info ) : <EOL> if self . show_artifact_internals and self . show_debug_info : <EOL> self . _write_kv_info ( '<STR_LIT>' , '<STR_LIT>' % ( <EOL> info . title_i18n [ '<STR_LIT>' ] , info . type ) ) <EOL> def report_prune_source_info ( self , source ) : <EOL> if self . show_artifact_internals and self . show_debug_info : <EOL> self . _write_kv_info ( '<STR_LIT>' , source ) <EOL> def report_build_func ( self , build_func ) : <EOL> if self . show_artifact_internals : <EOL> self . _write_kv_info ( '<STR_LIT>' , <EOL> describe_build_func ( build_func ) ) <EOL> def report_sub_artifact ( self , artifact ) : <EOL> if self . show_artifact_internals : <EOL> self . _write_kv_info ( '<STR_LIT>' , artifact . artifact_name ) <EOL> def report_debug_info ( self , key , value ) : <EOL> if self . show_debug_info : <EOL> self . _write_kv_info ( key , value ) <EOL> def report_generic ( self , message ) : <EOL> self . _write_line ( style ( text_type ( message ) , fg = '<STR_LIT>' ) ) <EOL> def enter_source ( self ) : <EOL> if not self . show_source_internals : <EOL> return <EOL> self . _write_line ( '<STR_LIT>' % style ( repr ( <EOL> self . current_source ) , fg = '<STR_LIT>' ) ) <EOL> self . indent ( ) <EOL> def leave_source ( self , start_time ) : <EOL> if self . show_source_internals : <EOL> self . outdent ( ) <EOL> def report_pruned_artifact ( self , artifact_name ) : <EOL> self . _write_line ( '<STR_LIT>' % ( style ( '<STR_LIT:D>' , fg = '<STR_LIT>' ) , artifact_name ) ) <EOL> null_reporter = NullReporter ( None ) <EOL> @ LocalProxy <EOL> def reporter ( ) : <EOL> rv = _reporter_stack . top <EOL> if rv is None : <EOL> rv = null_reporter <EOL> return rv </s>
