<s> import os <EOL> import shutil <EOL> import sys <EOL> from optparse import OptionParser <EOL> encode_table = { "<STR_LIT:\\>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:\n>" : "<STR_LIT>" } <EOL> decode_table = dict ( zip ( encode_table . values ( ) , encode_table . keys ( ) ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> usage = "<STR_LIT>" <EOL> desc = "<STR_LIT>" <EOL> optParser = OptionParser ( usage = usage , description = desc ) ; <EOL> optParser . add_option ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> action = "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" , <EOL> default = True ) ; <EOL> ( options , args ) = optParser . parse_args ( ) ; <EOL> if len ( args ) != <NUM_LIT:1> : <EOL> optParser . print_help ( ) <EOL> exit ( <NUM_LIT:1> ) <EOL> project_filename = args [ <NUM_LIT:0> ] <EOL> this_script_path = os . path . dirname ( os . path . realpath ( __file__ ) ) <EOL> build_script_path = os . path . join ( this_script_path , "<STR_LIT>" , "<STR_LIT:src>" , "<STR_LIT>" ) <EOL> with open ( build_script_path , "<STR_LIT:r>" ) as f : <EOL> build_script = "<STR_LIT>" . join ( encode_table . get ( c , c ) for c in f . read ( ) ) <EOL> script_tag = "<STR_LIT>" <EOL> with open ( project_filename , "<STR_LIT:r>" ) as f : <EOL> project_lines = f . readlines ( ) <EOL> script_indices = [ ] <EOL> for index , item in enumerate ( project_lines ) : <EOL> if script_tag in item : <EOL> script_indices . append ( index ) <EOL> if len ( script_indices ) == <NUM_LIT:0> : <EOL> print "<STR_LIT>" % ( script_tag , project_filename ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> for script_index in script_indices : <EOL> shellpath_index = script_index - <NUM_LIT:1> <EOL> if "<STR_LIT>" not in project_lines [ shellpath_index ] : <EOL> print "<STR_LIT>" % project_filename <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> project_lines [ shellpath_index ] = "<STR_LIT>" <EOL> project_lines [ script_index ] = "<STR_LIT>" + build_script + "<STR_LIT>" <EOL> if options . make_backup : <EOL> shutil . move ( project_filename , project_filename + "<STR_LIT>" ) <EOL> with open ( project_filename , "<STR_LIT:w>" ) as f : <EOL> f . writelines ( project_lines ) </s>
