Mercurial > hg > MakeItSo
comparison examples/doctest.txt @ 87:3571417ef92e
interpolate file permissions
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 10 Jan 2011 14:39:21 -0800 |
parents | a0f7bfa98755 |
children | 712a6d358083 |
comparison
equal
deleted
inserted
replaced
86:2c1310e94645 | 87:3571417ef92e |
---|---|
7 >>> import os | 7 >>> import os |
8 >>> import shutil | 8 >>> import shutil |
9 >>> import tempfile | 9 >>> import tempfile |
10 >>> from StringIO import StringIO | 10 >>> from StringIO import StringIO |
11 | 11 |
12 Basic functionality: | 12 Basic functionality:: |
13 | 13 |
14 >>> example = os.path.join(here, 'example.txt') | 14 >>> example = os.path.join(here, 'example.txt') |
15 >>> template = makeitso.PolyTemplate([example], interactive=False) | 15 >>> template = makeitso.PolyTemplate([example], interactive=False) |
16 >>> template.missing() | 16 >>> template.missing() |
17 set(['name']) | 17 set(['name']) |
18 >>> template.substitute(name='foo') | 18 >>> template.substitute(name='foo') |
19 Hello foo | 19 Hello foo |
20 | 20 |
21 Substitute to a buffer: | 21 Substitute to a buffer:: |
22 | 22 |
23 >>> buffer = StringIO() | 23 >>> buffer = StringIO() |
24 >>> template = makeitso.PolyTemplate([example], output=buffer, interactive=False) | 24 >>> template = makeitso.PolyTemplate([example], output=buffer, interactive=False) |
25 >>> template.substitute(name='bar') | 25 >>> template.substitute(name='bar') |
26 >>> buffer.getvalue().strip() | 26 >>> buffer.getvalue().strip() |
27 'Hello bar' | 27 'Hello bar' |
28 | 28 |
29 Substitute to a file: | 29 Substitute to a file:: |
30 | 30 |
31 >>> buffer = tempfile.mktemp() | 31 >>> buffer = tempfile.mktemp() |
32 >>> template = makeitso.PolyTemplate([example], output=buffer, interactive=False) | 32 >>> template = makeitso.PolyTemplate([example], output=buffer, interactive=False) |
33 >>> template.substitute(name='fleem') | 33 >>> template.substitute(name='fleem') |
34 >>> file(buffer).read().strip() | 34 >>> file(buffer).read().strip() |
89 >>> apitemplate = MyTemplate(output=buffer) | 89 >>> apitemplate = MyTemplate(output=buffer) |
90 >>> apitemplate.substitute() | 90 >>> apitemplate.substitute() |
91 >>> file(buffer).read().strip() | 91 >>> file(buffer).read().strip() |
92 'Hello bar' | 92 'Hello bar' |
93 >>> os.remove(buffer) | 93 >>> os.remove(buffer) |
94 | |
95 Test to make sure permissions are preserved. This won't work on windows:: | |
96 | |
97 >>> buffer = tempfile.mktemp() | |
98 >>> f = file(buffer, 'w') | |
99 >>> print >> f, '#!/bin/bash\necho foo' | |
100 >>> f.close() | |
101 >>> os.chmod(buffer, 0755) | |
102 >>> uritemplate = makeitso.URITemplate(example, output=buffer, interactive=False) | |
103 >>> uritemplate.substitute(name='bar') | |
104 >>> ('%o' % os.stat(buffer).st_mode).endswith('755') | |
105 True | |
106 >>> os.remove(buffer) |