<s> """<STR_LIT>""" <EOL> __author__ = ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , ) <EOL> import errno <EOL> import itertools <EOL> import os <EOL> import platform <EOL> import re <EOL> import sys <EOL> import time <EOL> import gflags as flags <EOL> from closure_linter import errorrecord <EOL> from closure_linter import runner <EOL> from closure_linter . common import erroraccumulator <EOL> from closure_linter . common import simplefileflags as fileflags <EOL> try : <EOL> import multiprocessing <EOL> except ImportError : <EOL> multiprocessing = None <EOL> FLAGS = flags . FLAGS <EOL> flags . DEFINE_boolean ( '<STR_LIT>' , False , <EOL> '<STR_LIT>' ) <EOL> flags . DEFINE_boolean ( '<STR_LIT>' , True , '<STR_LIT>' ) <EOL> flags . DEFINE_boolean ( '<STR_LIT:time>' , False , '<STR_LIT>' ) <EOL> flags . DEFINE_boolean ( '<STR_LIT>' , False , '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> flags . DEFINE_boolean ( '<STR_LIT>' , False , <EOL> '<STR_LIT>' ) <EOL> flags . DEFINE_boolean ( '<STR_LIT>' , False , <EOL> '<STR_LIT>' ) <EOL> flags . DEFINE_list ( '<STR_LIT>' , None , '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> flags . DEFINE_boolean ( '<STR_LIT>' , <EOL> platform . system ( ) is '<STR_LIT>' and bool ( multiprocessing ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> flags . ADOPT_module_key_flags ( fileflags ) <EOL> flags . ADOPT_module_key_flags ( runner ) <EOL> GJSLINT_ONLY_FLAGS = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def _MultiprocessCheckPaths ( paths ) : <EOL> """<STR_LIT>""" <EOL> pool = multiprocessing . Pool ( ) <EOL> path_results = pool . imap ( _CheckPath , paths ) <EOL> for results in path_results : <EOL> for result in results : <EOL> yield result <EOL> try : <EOL> pool . close ( ) <EOL> pool . join ( ) <EOL> del pool <EOL> except OSError as err : <EOL> if err . errno is not errno . EINTR : <EOL> raise err <EOL> def _CheckPaths ( paths ) : <EOL> """<STR_LIT>""" <EOL> for path in paths : <EOL> results = _CheckPath ( path ) <EOL> for record in results : <EOL> yield record <EOL> def _CheckPath ( path ) : <EOL> """<STR_LIT>""" <EOL> error_handler = erroraccumulator . ErrorAccumulator ( ) <EOL> runner . Run ( path , error_handler ) <EOL> make_error_record = lambda err : errorrecord . MakeErrorRecord ( path , err ) <EOL> return map ( make_error_record , error_handler . GetErrors ( ) ) <EOL> def _GetFilePaths ( argv ) : <EOL> suffixes = [ '<STR_LIT>' ] <EOL> if FLAGS . additional_extensions : <EOL> suffixes += [ '<STR_LIT>' % ext for ext in FLAGS . additional_extensions ] <EOL> if FLAGS . check_html : <EOL> suffixes += [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> return fileflags . GetFileList ( argv , '<STR_LIT>' , suffixes ) <EOL> def _PrintFileSummary ( paths , records ) : <EOL> """<STR_LIT>""" <EOL> paths = list ( paths ) <EOL> paths . sort ( ) <EOL> for path in paths : <EOL> path_errors = [ e for e in records if e . path == path ] <EOL> print '<STR_LIT>' % ( path , len ( path_errors ) ) <EOL> def _PrintFileSeparator ( path ) : <EOL> print '<STR_LIT>' % path <EOL> def _PrintSummary ( paths , error_records ) : <EOL> """<STR_LIT>""" <EOL> error_count = len ( error_records ) <EOL> all_paths = set ( paths ) <EOL> all_paths_count = len ( all_paths ) <EOL> if error_count is <NUM_LIT:0> : <EOL> print '<STR_LIT>' % all_paths_count <EOL> new_error_count = len ( [ e for e in error_records if e . new_error ] ) <EOL> error_paths = set ( [ e . path for e in error_records ] ) <EOL> error_paths_count = len ( error_paths ) <EOL> no_error_paths_count = all_paths_count - error_paths_count <EOL> if ( error_count or new_error_count ) and not FLAGS . quiet : <EOL> error_noun = '<STR_LIT:error>' if error_count == <NUM_LIT:1> else '<STR_LIT>' <EOL> new_error_noun = '<STR_LIT:error>' if new_error_count == <NUM_LIT:1> else '<STR_LIT>' <EOL> error_file_noun = '<STR_LIT:file>' if error_paths_count == <NUM_LIT:1> else '<STR_LIT>' <EOL> ok_file_noun = '<STR_LIT:file>' if no_error_paths_count == <NUM_LIT:1> else '<STR_LIT>' <EOL> print ( '<STR_LIT>' % <EOL> ( error_count , <EOL> error_noun , <EOL> new_error_count , <EOL> new_error_noun , <EOL> error_paths_count , <EOL> error_file_noun , <EOL> no_error_paths_count , <EOL> ok_file_noun ) ) <EOL> def _PrintErrorRecords ( error_records ) : <EOL> """<STR_LIT>""" <EOL> current_path = None <EOL> for record in error_records : <EOL> if current_path != record . path : <EOL> current_path = record . path <EOL> if not FLAGS . unix_mode : <EOL> _PrintFileSeparator ( current_path ) <EOL> print record . error_string <EOL> def _FormatTime ( t ) : <EOL> """<STR_LIT>""" <EOL> if t < <NUM_LIT:1> : <EOL> return '<STR_LIT>' % round ( t * <NUM_LIT:1000> ) <EOL> else : <EOL> return '<STR_LIT>' % t <EOL> def main ( argv = None ) : <EOL> """<STR_LIT>""" <EOL> if argv is None : <EOL> argv = flags . FLAGS ( sys . argv ) <EOL> if FLAGS . time : <EOL> start_time = time . time ( ) <EOL> if '<STR_LIT>' in os . environ : <EOL> FLAGS . unix_mode = True <EOL> suffixes = [ '<STR_LIT>' ] <EOL> if FLAGS . additional_extensions : <EOL> suffixes += [ '<STR_LIT>' % ext for ext in FLAGS . additional_extensions ] <EOL> if FLAGS . check_html : <EOL> suffixes += [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> paths = fileflags . GetFileList ( argv , '<STR_LIT>' , suffixes ) <EOL> if FLAGS . multiprocess : <EOL> records_iter = _MultiprocessCheckPaths ( paths ) <EOL> else : <EOL> records_iter = _CheckPaths ( paths ) <EOL> records_iter , records_iter_copy = itertools . tee ( records_iter , <NUM_LIT:2> ) <EOL> _PrintErrorRecords ( records_iter_copy ) <EOL> error_records = list ( records_iter ) <EOL> _PrintSummary ( paths , error_records ) <EOL> exit_code = <NUM_LIT:0> <EOL> if error_records : <EOL> exit_code += <NUM_LIT:1> <EOL> if [ r for r in error_records if r . new_error ] : <EOL> exit_code += <NUM_LIT:2> <EOL> if exit_code : <EOL> if FLAGS . summary : <EOL> _PrintFileSummary ( paths , error_records ) <EOL> if FLAGS . beep : <EOL> sys . stdout . write ( chr ( <NUM_LIT:7> ) ) <EOL> fix_args = [ ] <EOL> for flag in sys . argv [ <NUM_LIT:1> : ] : <EOL> for f in GJSLINT_ONLY_FLAGS : <EOL> if flag . startswith ( f ) : <EOL> break <EOL> else : <EOL> fix_args . append ( flag ) <EOL> if not FLAGS . quiet : <EOL> print """<STR_LIT>""" % '<STR_LIT:U+0020>' . join ( fix_args ) <EOL> if FLAGS . time : <EOL> print '<STR_LIT>' % _FormatTime ( time . time ( ) - start_time ) <EOL> sys . exit ( exit_code ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
