diff options
author | David Malcolm <dmalcolm@redhat.com> | 2009-11-19 16:01:46 -0500 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2009-11-19 16:01:46 -0500 |
commit | a04ea828bd6b01d38b263a5515cb32c383887744 (patch) | |
tree | 4c3271243170e66a810d4dad460aa550c26382be | |
parent | ee3130deb4312fd541a89eb6f885375ec6935cd3 (diff) | |
download | 2to3c-a04ea828bd6b01d38b263a5515cb32c383887744.tar.gz 2to3c-a04ea828bd6b01d38b263a5515cb32c383887744.tar.xz 2to3c-a04ea828bd6b01d38b263a5515cb32c383887744.zip |
Introduce option parsing, with a --write option to write changes back to the input files; add filename to diff output
-rw-r--r-- | typeobject.py | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/typeobject.py b/typeobject.py index 8e4da1f..9967022 100644 --- a/typeobject.py +++ b/typeobject.py @@ -47,12 +47,36 @@ PyTypeObject DBusPyIntBase_Type = { ''' ) + +def fixup_file(filename, options): + content = open(filename, 'r').read() + fixed_content = fixup_typeobject_initializers(content) + if content != fixed_content: + for line in unified_diff(content.splitlines(), + fixed_content.splitlines(), + fromfile = filename+'.orig', + tofile = filename, + lineterm=''): + print line + + if options.write: + open(filename, 'w').write(fixed_content) + +def main(): + from optparse import OptionParser + usage = "usage: %prog [options] filenames..." + parser = OptionParser(usage=usage) + parser.add_option('-w', '--write', + action="store_true", dest="write", default=False, + help="Write back modified files") + (options, args) = parser.parse_args() + # print (options, args) + for filename in args: + fixup_file(filename, options) + if __name__ == '__main__': if len(sys.argv) == 1: unittest.main() else: - for filename in sys.argv[1:]: - content = open(filename, 'r').read() - fixed_content = fixup_typeobject_initializers(content) - for line in unified_diff(content.splitlines(), fixed_content.splitlines(), lineterm=''): - print line + main() + |