<s> """<STR_LIT>""" <EOL> from __future__ import division , print_function , unicode_literals <EOL> import optparse <EOL> import os <EOL> import sys <EOL> old_license = """<STR_LIT>""" <EOL> new_license = """<STR_LIT>""" <EOL> change_files = False <EOL> report_match = False <EOL> reported = [ ] <EOL> target_license = None <EOL> headers = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> exclude = set ( [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] ) <EOL> def process_file ( filename ) : <EOL> '''<STR_LIT>''' <EOL> global target_license , new_license , change_files , report_match , reported <EOL> f = open ( filename , '<STR_LIT>' ) <EOL> text = f . read ( ) <EOL> f . close ( ) <EOL> match = text . startswith ( target_license ) <EOL> if change_files and match : <EOL> text = new_license + text [ len ( target_license ) : ] <EOL> f = open ( filename , '<STR_LIT:w>' ) <EOL> f . write ( text ) <EOL> f . close ( ) <EOL> if report_match == match : <EOL> reported . append ( filename ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> usage = """<STR_LIT>""" <EOL> op = optparse . OptionParser ( usage = usage ) <EOL> op . add_option ( '<STR_LIT>' , dest = '<STR_LIT>' , default = '<STR_LIT>' , <EOL> choices = [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] , <EOL> ) <EOL> options , args = op . parse_args ( ) <EOL> if len ( args ) < <NUM_LIT:1> : <EOL> op . print_usage ( ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> mode = options . mode <EOL> print ( '<STR_LIT>' , mode ) <EOL> assert mode in headers <EOL> print ( headers [ mode ] ) <EOL> change_files = ( mode == '<STR_LIT>' ) <EOL> if change_files : <EOL> mode = '<STR_LIT>' <EOL> if mode . endswith ( '<STR_LIT>' ) : <EOL> target_license = old_license <EOL> else : <EOL> target_license = new_license <EOL> report_match = not ( '<STR_LIT>' in mode ) <EOL> for path in args : <EOL> print ( '<STR_LIT>' , args ) <EOL> if os . path . isdir ( path ) : <EOL> for root , dirnames , filenames in os . walk ( path ) : <EOL> for dirname in dirnames : <EOL> if dirname in exclude : <EOL> dirnames . remove ( dirname ) <EOL> for filename in filenames : <EOL> if ( filename . endswith ( '<STR_LIT>' ) and <EOL> filename not in exclude ) : <EOL> try : <EOL> process_file ( os . path . join ( root , filename ) ) <EOL> except Exception as ex : <EOL> print ( "<STR_LIT>" % os . path . join ( root , filename ) ) <EOL> print ( ex ) <EOL> else : <EOL> if ( path . endswith ( '<STR_LIT>' ) and <EOL> path not in exclude ) : <EOL> process_file ( path ) <EOL> for name in reported : <EOL> print ( name ) </s>
