git » pygen » commit 03dd278

Preserve generated files' mtime.

author Alberto Bertogli
2006-03-07 17:56:01 UTC
committer Alberto Bertogli
2006-03-07 17:56:01 UTC
parent 96ab53a688ad20abae38eb7e8c818c8e1ba91d06

Preserve generated files' mtime.

pygen +9 -0

diff --git a/pygen b/pygen
index 3ba06ab..52beb5e 100644
--- a/pygen
+++ b/pygen
@@ -24,10 +24,13 @@ def gen_from(src, dst, environ = None, incpath = None):
 	"Process src and generate dst."
 
 	# open files if necessary
+	opened_src = opened_dst = False
 	if not isinstance(src, file):
 		src = open(src)
+		opened_src = True
 	if not isinstance(dst, file):
 		dst = open(dst, 'w')
+		opened_dst = True
 
 	# set up the environment for execution
 	preout = sys.stdout
@@ -97,6 +100,12 @@ def gen_from(src, dst, environ = None, incpath = None):
 	# restore environment
 	sys.stdout = preout
 
+	if opened_src: src.close()
+	if opened_dst: dst.close()
+
+	# preserve mtime
+	shutil.copystat(src.name, dst.name)
+
 
 def autogen(src, dst):
 	"Generate automatically by walking src and storing results in dst."