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

Side by Side Diff: packager.py

Issue 6562202978877440: Issue 1778 - Generate proper build numbers when working with Git repositories (Closed)
Patch Set: Created Jan. 12, 2015, 6: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 | no next file » | 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 Source Code Form is subject to the terms of the Mozilla Public 3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this 4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 6
7 # Note: These are the base functions common to all packagers, the actual 7 # Note: These are the base functions common to all packagers, the actual
8 # packagers are implemented in packagerGecko and packagerChrome. 8 # packagers are implemented in packagerGecko and packagerChrome.
9 9
10 import sys, os, re, codecs, subprocess, json, zipfile 10 import sys, os, re, codecs, subprocess, json, zipfile
11 from StringIO import StringIO 11 from StringIO import StringIO
12 from chainedconfigparser import ChainedConfigParser 12 from chainedconfigparser import ChainedConfigParser
13 13
14 import buildtools 14 import buildtools
15 15
16 def getDefaultFileName(baseDir, metadata, version, ext): 16 def getDefaultFileName(baseDir, metadata, version, ext):
17 return os.path.join(baseDir, '%s-%s.%s' % (metadata.get('general', 'basename') , version, ext)) 17 return os.path.join(baseDir, '%s-%s.%s' % (metadata.get('general', 'basename') , version, ext))
18 18
19 def getMetadataPath(baseDir, type): 19 def getMetadataPath(baseDir, type):
20 return os.path.join(baseDir, 'metadata.%s' % type) 20 return os.path.join(baseDir, 'metadata.%s' % type)
21 21
22 def readMetadata(baseDir, type): 22 def readMetadata(baseDir, type):
23 return ChainedConfigParser(getMetadataPath(baseDir, type)) 23 return ChainedConfigParser(getMetadataPath(baseDir, type))
24 24
25 def getBuildNum(baseDir): 25 def getBuildNum(baseDir):
26 try: 26 try:
27 result = subprocess.check_output(['hg', 'id', '-R', baseDir, '-n']) 27 from buildtools.ensure_dependencies import Mercurial, Git
Sebastian Noack 2015/01/13 09:12:25 It seems that you only need Git.istype() and Mercu
Wladimir Palant 2015/01/13 12:56:53 As the OP explained in the pull request, these are
28 return re.sub(r'\D', '', result) 28 if Mercurial().istype(baseDir):
29 except: 29 result = subprocess.check_output(['hg', 'id', '-R', baseDir, '-n'])
30 return '0' 30 return re.sub(r'\D', '', result)
31 elif Git().istype(baseDir):
32 result = subprocess.check_output(['git', 'rev-list', 'HEAD'], cwd=baseDir)
33 return len(result.splitlines())
34 except subprocess.CalledProcessError:
35 pass
36
37 return '0'
31 38
32 def getBuildVersion(baseDir, metadata, releaseBuild, buildNum=None): 39 def getBuildVersion(baseDir, metadata, releaseBuild, buildNum=None):
33 version = metadata.get('general', 'version') 40 version = metadata.get('general', 'version')
34 if not releaseBuild: 41 if not releaseBuild:
35 if buildNum == None: 42 if buildNum == None:
36 buildNum = getBuildNum(baseDir) 43 buildNum = getBuildNum(baseDir)
37 buildNum = str(buildNum) 44 buildNum = str(buildNum)
38 if len(buildNum) > 0: 45 if len(buildNum) > 0:
39 if re.search(r'(^|\.)\d+$', version): 46 if re.search(r'(^|\.)\d+$', version):
40 # Numerical version number - need to fill up with zeros to have three 47 # Numerical version number - need to fill up with zeros to have three
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 names = self.keys() 123 names = self.keys()
117 names.sort(key=sortKey) 124 names.sort(key=sortKey)
118 for name in names: 125 for name in names:
119 zip.writestr(name, self[name]) 126 zip.writestr(name, self[name])
120 zip.close() 127 zip.close()
121 128
122 def zipToString(self, sortKey=None): 129 def zipToString(self, sortKey=None):
123 buffer = StringIO() 130 buffer = StringIO()
124 self.zip(buffer, sortKey=sortKey) 131 self.zip(buffer, sortKey=sortKey)
125 return buffer.getvalue() 132 return buffer.getvalue()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld