[asterisk-commits] dlee: branch dlee/ari-event-remodel2 r392402 - /team/dlee/ari-event-remodel2/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jun 21 00:34:38 CDT 2013


Author: dlee
Date: Fri Jun 21 00:34:36 2013
New Revision: 392402

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392402
Log:
make ari-stubs: only overwrite files when they change.

This helps a tiny bit with useless rebuilds, but also helps make the build
a bit less noisy when you're just changing one file.

Modified:
    team/dlee/ari-event-remodel2/rest-api-templates/transform.py

Modified: team/dlee/ari-event-remodel2/rest-api-templates/transform.py
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/rest-api-templates/transform.py?view=diff&rev=392402&r1=392401&r2=392402
==============================================================================
--- team/dlee/ari-event-remodel2/rest-api-templates/transform.py (original)
+++ team/dlee/ari-event-remodel2/rest-api-templates/transform.py Fri Jun 21 00:34:36 2013
@@ -18,7 +18,9 @@
 
 import os.path
 import pystache
-
+import tempfile
+import filecmp
+import shutil
 
 class Transform(object):
     """Transformation for template to code.
@@ -46,8 +48,14 @@
         """
         dest_file = pystache.render(self.dest_file_template, model)
         dest_file = os.path.join(dest_dir, dest_file)
-        if os.path.exists(dest_file) and not self.overwrite:
+        dest_exists = os.path.exists(dest_file)
+        if dest_exists and not self.overwrite:
             return
-        print "Rendering %s" % dest_file
-        with open(dest_file, "w") as out:
+        tmp_file = tempfile.mkstemp()
+        with tempfile.NamedTemporaryFile() as out:
             out.write(renderer.render(self.template, model))
+            out.flush()
+
+            if not dest_exists or not filecmp.cmp(out.name, dest_file):
+                print "Writing %s" % dest_file
+                shutil.copyfile(out.name, dest_file)




More information about the asterisk-commits mailing list