Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: packager.py

Issue 11544056: Prepared buildtools for Safari (Closed)
Patch Set: Addressed comments Created Oct. 30, 2013, 5:22 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « imageConversion.py ('k') | packagerChrome.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus build tools, 3 # This file is part of the Adblock Plus build tools,
4 # Copyright (C) 2006-2013 Eyeo GmbH 4 # Copyright (C) 2006-2013 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 # Make sure the file is inside an included directory 106 # Make sure the file is inside an included directory
107 if '/' in target and not self.isIncluded(target): 107 if '/' in target and not self.isIncluded(target):
108 continue 108 continue
109 parts = source.split('/') 109 parts = source.split('/')
110 path = os.path.join(os.path.dirname(item.source), *parts) 110 path = os.path.join(os.path.dirname(item.source), *parts)
111 if os.path.exists(path): 111 if os.path.exists(path):
112 self.read(path, target) 112 self.read(path, target)
113 else: 113 else:
114 print >>sys.stderr, 'Warning: Mapped file %s doesn\'t exist' % source 114 print >>sys.stderr, 'Warning: Mapped file %s doesn\'t exist' % source
115 115
116 def preprocess(self, filenames, params={}):
117 import jinja2
118
119 env = jinja2.Environment(
120 # TODO: Make the first run page generated on all platforms and get
121 # rid of the HTML comment syntax, wrapped around the jinja syntax.
122 block_start_string='<!-- {%',
123 block_end_string='%} -->',
124 variable_start_string='<!-- {{',
125 variable_end_string='}} -->',
126 comment_start_string='<-- {#',
127 comment_end_string='#} -->'
128 )
129
130 for filename in filenames:
131 env.autoescape = os.path.splitext(filename) in ('.html', '.xml')
132 template = env.from_string(self[filename].decode('utf-8'))
133 self[filename] = template.render(params).encode('utf-8')
134
116 def zip(self, outFile, sortKey=None): 135 def zip(self, outFile, sortKey=None):
117 zip = zipfile.ZipFile(outFile, 'w', zipfile.ZIP_DEFLATED) 136 zip = zipfile.ZipFile(outFile, 'w', zipfile.ZIP_DEFLATED)
118 names = self.keys() 137 names = self.keys()
119 names.sort(key=sortKey) 138 names.sort(key=sortKey)
120 for name in names: 139 for name in names:
121 zip.writestr(name, self[name]) 140 zip.writestr(name, self[name])
122 zip.close() 141 zip.close()
123 142
124 def zipToString(self, sortKey=None): 143 def zipToString(self, sortKey=None):
125 buffer = StringIO() 144 buffer = StringIO()
126 self.zip(buffer, sortKey=sortKey) 145 self.zip(buffer, sortKey=sortKey)
127 return buffer.getvalue() 146 return buffer.getvalue()
OLDNEW
« no previous file with comments | « imageConversion.py ('k') | packagerChrome.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld