summaryrefslogtreecommitdiffstats
path: root/2to3c
diff options
context:
space:
mode:
Diffstat (limited to '2to3c')
-rwxr-xr-x2to3c45
1 files changed, 45 insertions, 0 deletions
diff --git a/2to3c b/2to3c
new file mode 100755
index 0000000..c31d991
--- /dev/null
+++ b/2to3c
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+
+def get_fixers():
+ from typeobject import fixup_typeobject_initializers
+ return [fixup_typeobject_initializers]
+
+def fixup_content(content):
+ # Apply the various fixers, in turn:
+ for fixer in get_fixers():
+ content = fixer(content)
+ return content
+
+
+def fixup_file(filename, options):
+ from difflib import unified_diff
+
+ content = open(filename, 'r').read()
+ fixed_content = fixup_content(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__':
+ main()
+
+