# HG changeset patch # User Jeff Hammel # Date 1294699161 28800 # Node ID 3571417ef92e38b5c751ffaa789c1a15cc0b7337 # Parent 2c1310e94645422342ebd74129a43e4d3fcc862e interpolate file permissions diff -r 2c1310e94645 -r 3571417ef92e examples/doctest.txt --- a/examples/doctest.txt Mon Jan 10 12:39:26 2011 -0800 +++ b/examples/doctest.txt Mon Jan 10 14:39:21 2011 -0800 @@ -9,7 +9,7 @@ >>> import tempfile >>> from StringIO import StringIO -Basic functionality: +Basic functionality:: >>> example = os.path.join(here, 'example.txt') >>> template = makeitso.PolyTemplate([example], interactive=False) @@ -18,7 +18,7 @@ >>> template.substitute(name='foo') Hello foo -Substitute to a buffer: +Substitute to a buffer:: >>> buffer = StringIO() >>> template = makeitso.PolyTemplate([example], output=buffer, interactive=False) @@ -26,7 +26,7 @@ >>> buffer.getvalue().strip() 'Hello bar' -Substitute to a file: +Substitute to a file:: >>> buffer = tempfile.mktemp() >>> template = makeitso.PolyTemplate([example], output=buffer, interactive=False) @@ -91,3 +91,16 @@ >>> file(buffer).read().strip() 'Hello bar' >>> os.remove(buffer) + +Test to make sure permissions are preserved. This won't work on windows:: + + >>> buffer = tempfile.mktemp() + >>> f = file(buffer, 'w') + >>> print >> f, '#!/bin/bash\necho foo' + >>> f.close() + >>> os.chmod(buffer, 0755) + >>> uritemplate = makeitso.URITemplate(example, output=buffer, interactive=False) + >>> uritemplate.substitute(name='bar') + >>> ('%o' % os.stat(buffer).st_mode).endswith('755') + True + >>> os.remove(buffer) diff -r 2c1310e94645 -r 3571417ef92e makeitso/makeitso.py --- a/makeitso/makeitso.py Mon Jan 10 12:39:26 2011 -0800 +++ b/makeitso/makeitso.py Mon Jan 10 14:39:21 2011 -0800 @@ -216,18 +216,18 @@ f = self.output if isinstance(f, basestring): + path = f if os.path.isdir(f): - f = os.path.join(f, basename(self.name)) - f = file(f, 'w') + path = os.path.join(path, basename(self.name)) + f = file(path, 'w') print >> f, output f.close() + try: + os.chmod(f, os.stat(self.name).st_mode) + except: + pass else: print >> f, output - try: - os.chmod(self.output, os.stat(self.name).st_mode) - except: - pass - class DirectoryTemplate(ContentTemplate): """template for a directory structure"""