Skip to content

Commit

Permalink
Check timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
bdarnell committed Feb 24, 2011
1 parent d32a0b8 commit f8538c4
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions auto2to3.py
Expand Up @@ -41,19 +41,19 @@ def find_module(self, fullname, path=None):
return None
if file and etc[2] == imp.PY_SOURCE:
if any(fullname.startswith(p) for p in PACKAGES):
filename = '<%r converted by 2to3>' % filename
try:
tree = rt.refactor_string(file.read(), filename)
except Exception as err:
raise ImportError("2to3 couldn't convert %r" % filename)
finally:
file.close()
filename = '/tmp/auto2to3-%s.py' % fullname
print('writing %s' % filename)
file = open(filename, 'wb')
file.write(str(tree).encode('utf8'))
file.seek(0)
outfile = '/tmp/auto2to3-%s.py' % fullname
if (not os.path.exists(outfile) or
os.stat(filename).st_mtime > os.stat(outfile).st_mtime):
try:
tree = rt.refactor_string(file.read(), filename)
except Exception as err:
raise ImportError("2to3 couldn't convert %r" % filename)
finally:
file.close()
file = open(outfile, 'wb')
file.write(str(tree).encode('utf8'))
file.close()
filename = outfile
file = open(filename, 'rb')
return ImpLoader(fullname, file, filename, etc)

Expand Down

0 comments on commit f8538c4

Please sign in to comment.