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

Side by Side Diff: packager.py

Issue 9158185: Implemented mapping of files from subrepositories (Closed)
Patch Set: Created Jan. 14, 2013, 2:43 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 | « no previous file | 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-2012 Eyeo GmbH 4 # Copyright (C) 2006-2012 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,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details. 13 # GNU General Public License for more details.
14 # 14 #
15 # You should have received a copy of the GNU General Public License 15 # You should have received a copy of the GNU General Public License
16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
17 17
18 # Note: These are the base functions common to all packagers, the actual 18 # Note: These are the base functions common to all packagers, the actual
19 # packagers are implemented in packagerGecko and packagerChrome. 19 # packagers are implemented in packagerGecko and packagerChrome.
20 20
21 import os, re, codecs, subprocess, json, zipfile, jinja2 21 import sys, os, re, codecs, subprocess, json, zipfile, jinja2
22 from StringIO import StringIO 22 from StringIO import StringIO
23 from ConfigParser import SafeConfigParser 23 from ConfigParser import SafeConfigParser
24 24
25 import buildtools 25 import buildtools
26 26
27 def getDefaultFileName(baseDir, metadata, version, ext): 27 def getDefaultFileName(baseDir, metadata, version, ext):
28 return os.path.join(baseDir, '%s-%s.%s' % (metadata.get('general', 'basename') , version, ext)) 28 return os.path.join(baseDir, '%s-%s.%s' % (metadata.get('general', 'basename') , version, ext))
29 29
30 def getMetadataPath(baseDir): 30 def getMetadataPath(baseDir):
31 return os.path.join(baseDir, 'metadata') 31 return os.path.join(baseDir, 'metadata')
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 return True 84 return True
85 85
86 def read(self, path, relpath='', skip=None): 86 def read(self, path, relpath='', skip=None):
87 if os.path.isdir(path): 87 if os.path.isdir(path):
88 for file in os.listdir(path): 88 for file in os.listdir(path):
89 name = relpath + ('/' if relpath != '' else '') + file 89 name = relpath + ('/' if relpath != '' else '') + file
90 if (skip == None or file not in skip) and self.isIncluded(name): 90 if (skip == None or file not in skip) and self.isIncluded(name):
91 self.read(os.path.join(path, file), name) 91 self.read(os.path.join(path, file), name)
92 else: 92 else:
93 file = open(path, 'rb') 93 file = open(path, 'rb')
94 if relpath in self:
95 print >>sys.stderr, 'Warning: File %s defined multiple times' % relpath
94 self[relpath] = file.read() 96 self[relpath] = file.read()
95 file.close() 97 file.close()
96 98
99 def readMappedFiles(self, baseDir, mappings):
100 for target, source in mappings:
101 # Make sure the file is inside an included directory
102 if '/' in target and not self.isIncluded(target):
103 continue
104 parts = source.split('/')
105 path = os.path.join(baseDir, *parts)
106 if os.path.exists(path):
107 self.read(path, target)
108 else:
109 print >>sys.stderr, 'Warning: Mapped file %s doesn\'t exist' % source
110
97 def zip(self, outFile, sortKey=None): 111 def zip(self, outFile, sortKey=None):
98 zip = zipfile.ZipFile(outFile, 'w', zipfile.ZIP_DEFLATED) 112 zip = zipfile.ZipFile(outFile, 'w', zipfile.ZIP_DEFLATED)
99 names = self.keys() 113 names = self.keys()
100 names.sort(key=sortKey) 114 names.sort(key=sortKey)
101 for name in names: 115 for name in names:
102 data = self[name] 116 data = self[name]
103 if self.process: 117 if self.process:
104 data = self.process(name, data) 118 data = self.process(name, data)
105 zip.writestr(name, data) 119 zip.writestr(name, data)
106 zip.close() 120 zip.close()
107 121
108 def zipToString(self, sortKey=None): 122 def zipToString(self, sortKey=None):
109 buffer = StringIO() 123 buffer = StringIO()
110 self.zip(buffer, sortKey=sortKey) 124 self.zip(buffer, sortKey=sortKey)
111 return buffer.getvalue() 125 return buffer.getvalue()
OLDNEW
« no previous file with comments | « no previous file | packagerChrome.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld