author | Alberto Bertogli
<albertito@blitiri.com.ar> 2011-03-28 21:34:40 UTC |
committer | Alberto Bertogli
<albertito@blitiri.com.ar> 2011-03-28 21:34:40 UTC |
parent | 36bac7080908765e3368597e644e58992ab894da |
pygen | +13 | -11 |
diff --git a/pygen b/pygen index 1c90238..af70d77 100755 --- a/pygen +++ b/pygen @@ -11,13 +11,16 @@ def printd(*args): print >> sys.stderr, i, print >> sys.stderr -def is_newer_than(new, old): - """Determine if "new" is newer than "old".""" - if not os.path.exists(new): +def is_newer_than(src, dst): + """Determine if "src" is newer than "dst".""" + if not os.path.exists(dst): return False - if os.path.getmtime(new) >= os.path.getmtime(old): - return True - return False + # We have to use the integer part because copystat() is not accurate + # and loses precision when copying mtimes, causing the mtimes to be + # different and sometimes the new file has an older mtime than the old + # one. Since we do not expect to need sub-second precision when + # regenerating, this should be safe. + return int(os.path.getmtime(src)) > int(os.path.getmtime(dst)) def gen_from(src, dst, environ = None, incpath = None): @@ -52,7 +55,6 @@ def gen_from(src, dst, environ = None, incpath = None): in_python_code = '' for line in src: - # state parsing if in_python and not line.startswith('#endpy'): in_python_code += line @@ -155,14 +157,14 @@ def autogen(src, dst): t = os.path.splitext(diff)[0] t = os.path.normpath(dst + '/' + t) - if is_newer_than(t, fullf): + if not is_newer_than(fullf, t): print 'skipped', diff continue print diff, '->', t gen_from(fullf, t) else: t = os.path.normpath(dst + '/' + diff) - if is_newer_than(t, fullf): + if not is_newer_than(fullf, t): print 'skipped', diff continue if os.path.islink(fullf): @@ -177,8 +179,8 @@ def autogen(src, dst): # second pass to preserve directories' modification time for s, d in to_update_stat: - print 'copystat', d - shutil.copystat(s, d) + print 'copystat', d + shutil.copystat(s, d) if __name__ == '__main__':