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

Side by Side Diff: packager.py

Issue 9257092: More build tools improvements (Closed)
Patch Set: Added some more changes required to build Firefox and Chrome extensions from the same repository (s… Created Jan. 25, 2013, 1:47 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 | « manifest.json.tmpl ('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-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,
(...skipping 27 matching lines...) Expand all
38 (result, dummy) = subprocess.Popen(['hg', 'id', '-R', baseDir, '-n'], stdout =subprocess.PIPE).communicate() 38 (result, dummy) = subprocess.Popen(['hg', 'id', '-R', baseDir, '-n'], stdout =subprocess.PIPE).communicate()
39 return re.sub(r'\D', '', result) 39 return re.sub(r'\D', '', result)
40 except Exception: 40 except Exception:
41 return '0' 41 return '0'
42 42
43 def getBuildVersion(baseDir, metadata, releaseBuild, buildNum=None): 43 def getBuildVersion(baseDir, metadata, releaseBuild, buildNum=None):
44 version = metadata.get('general', 'version') 44 version = metadata.get('general', 'version')
45 if not releaseBuild: 45 if not releaseBuild:
46 if buildNum == None: 46 if buildNum == None:
47 buildNum = getBuildNum(baseDir) 47 buildNum = getBuildNum(baseDir)
48 buildNum = str(buildNum)
48 if len(buildNum) > 0: 49 if len(buildNum) > 0:
49 if re.search(r'(^|\.)\d+$', version): 50 if re.search(r'(^|\.)\d+$', version):
50 # Numerical version number - need to fill up with zeros to have three 51 # Numerical version number - need to fill up with zeros to have three
51 # version components. 52 # version components.
52 while version.count('.') < 2: 53 while version.count('.') < 2:
53 version += '.0' 54 version += '.0'
54 version += '.' + buildNum 55 version += '.' + buildNum
55 return version 56 return version
56 57
57 def getTemplate(template, autoEscape=False): 58 def getTemplate(template, autoEscape=False):
(...skipping 26 matching lines...) Expand all
84 name = relpath + ('/' if relpath != '' else '') + file 85 name = relpath + ('/' if relpath != '' else '') + file
85 if (skip == None or file not in skip) and self.isIncluded(name): 86 if (skip == None or file not in skip) and self.isIncluded(name):
86 self.read(os.path.join(path, file), name) 87 self.read(os.path.join(path, file), name)
87 else: 88 else:
88 file = open(path, 'rb') 89 file = open(path, 'rb')
89 if relpath in self: 90 if relpath in self:
90 print >>sys.stderr, 'Warning: File %s defined multiple times' % relpath 91 print >>sys.stderr, 'Warning: File %s defined multiple times' % relpath
91 self[relpath] = file.read() 92 self[relpath] = file.read()
92 file.close() 93 file.close()
93 94
94 def readMappedFiles(self, baseDir, mappings): 95 def readMappedFiles(self, mappings):
95 for target, source in mappings: 96 for item in mappings:
97 target, source = item
98
96 # Make sure the file is inside an included directory 99 # Make sure the file is inside an included directory
97 if '/' in target and not self.isIncluded(target): 100 if '/' in target and not self.isIncluded(target):
98 continue 101 continue
99 parts = source.split('/') 102 parts = source.split('/')
100 path = os.path.join(baseDir, *parts) 103 path = os.path.join(os.path.dirname(item.source), *parts)
101 if os.path.exists(path): 104 if os.path.exists(path):
102 self.read(path, target) 105 self.read(path, target)
103 else: 106 else:
104 print >>sys.stderr, 'Warning: Mapped file %s doesn\'t exist' % source 107 print >>sys.stderr, 'Warning: Mapped file %s doesn\'t exist' % source
105 108
106 def zip(self, outFile, sortKey=None): 109 def zip(self, outFile, sortKey=None):
107 zip = zipfile.ZipFile(outFile, 'w', zipfile.ZIP_DEFLATED) 110 zip = zipfile.ZipFile(outFile, 'w', zipfile.ZIP_DEFLATED)
108 names = self.keys() 111 names = self.keys()
109 names.sort(key=sortKey) 112 names.sort(key=sortKey)
110 for name in names: 113 for name in names:
111 data = self[name] 114 data = self[name]
112 if self.process: 115 if self.process:
113 data = self.process(name, data) 116 data = self.process(name, data)
114 zip.writestr(name, data) 117 zip.writestr(name, data)
115 zip.close() 118 zip.close()
116 119
117 def zipToString(self, sortKey=None): 120 def zipToString(self, sortKey=None):
118 buffer = StringIO() 121 buffer = StringIO()
119 self.zip(buffer, sortKey=sortKey) 122 self.zip(buffer, sortKey=sortKey)
120 return buffer.getvalue() 123 return buffer.getvalue()
OLDNEW
« no previous file with comments | « manifest.json.tmpl ('k') | packagerChrome.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld