<s> from __future__ import print_function <EOL> from __future__ import unicode_literals <EOL> import argparse <EOL> import os <EOL> import sys <EOL> def fix_file ( file_obj ) : <EOL> try : <EOL> file_obj . seek ( - <NUM_LIT:1> , os . SEEK_END ) <EOL> except IOError : <EOL> return <NUM_LIT:0> <EOL> last_character = file_obj . read ( <NUM_LIT:1> ) <EOL> if last_character != b'<STR_LIT:\n>' and last_character != b'<STR_LIT>' : <EOL> file_obj . seek ( <NUM_LIT:0> , os . SEEK_END ) <EOL> file_obj . write ( b'<STR_LIT:\n>' ) <EOL> return <NUM_LIT:1> <EOL> while last_character == b'<STR_LIT:\n>' : <EOL> if file_obj . tell ( ) == <NUM_LIT:1> : <EOL> file_obj . seek ( <NUM_LIT:0> ) <EOL> file_obj . truncate ( ) <EOL> return <NUM_LIT:1> <EOL> file_obj . seek ( - <NUM_LIT:2> , os . SEEK_CUR ) <EOL> last_character = file_obj . read ( <NUM_LIT:1> ) <EOL> if len ( file_obj . read ( <NUM_LIT:2> ) ) == <NUM_LIT:2> : <EOL> file_obj . seek ( - <NUM_LIT:1> , os . SEEK_CUR ) <EOL> file_obj . truncate ( ) <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> def end_of_file_fixer ( argv = None ) : <EOL> parser = argparse . ArgumentParser ( ) <EOL> parser . add_argument ( '<STR_LIT>' , nargs = '<STR_LIT:*>' , help = '<STR_LIT>' ) <EOL> args = parser . parse_args ( argv ) <EOL> retv = <NUM_LIT:0> <EOL> for filename in args . filenames : <EOL> with open ( filename , '<STR_LIT>' ) as file_obj : <EOL> ret_for_file = fix_file ( file_obj ) <EOL> if ret_for_file : <EOL> print ( '<STR_LIT>' . format ( filename ) ) <EOL> retv |= ret_for_file <EOL> return retv <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> sys . exit ( end_of_file_fixer ( ) ) </s>
