OLD | NEW |
| (Empty) |
1 # -*- coding: utf-8 -*- | |
2 """ | |
3 jinja2._markupsafe._bundle | |
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
5 | |
6 This script pulls in markupsafe from a source folder and | |
7 bundles it with Jinja2. It does not pull in the speedups | |
8 module though. | |
9 | |
10 :copyright: Copyright 2010 by the Jinja team, see AUTHORS. | |
11 :license: BSD, see LICENSE for details. | |
12 """ | |
13 import sys | |
14 import os | |
15 import re | |
16 | |
17 | |
18 def rewrite_imports(lines): | |
19 for idx, line in enumerate(lines): | |
20 new_line = re.sub(r'(import|from)\s+markupsafe\b', | |
21 r'\1 jinja2._markupsafe', line) | |
22 if new_line != line: | |
23 lines[idx] = new_line | |
24 | |
25 | |
26 def main(): | |
27 if len(sys.argv) != 2: | |
28 print 'error: only argument is path to markupsafe' | |
29 sys.exit(1) | |
30 basedir = os.path.dirname(__file__) | |
31 markupdir = sys.argv[1] | |
32 for filename in os.listdir(markupdir): | |
33 if filename.endswith('.py'): | |
34 f = open(os.path.join(markupdir, filename)) | |
35 try: | |
36 lines = list(f) | |
37 finally: | |
38 f.close() | |
39 rewrite_imports(lines) | |
40 f = open(os.path.join(basedir, filename), 'w') | |
41 try: | |
42 for line in lines: | |
43 f.write(line) | |
44 finally: | |
45 f.close() | |
46 | |
47 | |
48 if __name__ == '__main__': | |
49 main() | |
OLD | NEW |