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

Side by Side Diff: packager.py

Issue 9158140: Packager refactoring, moved common packager code into separate module (Closed)
Patch Set: Created Jan. 10, 2013, 7:57 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
(Empty)
1 # coding: utf-8
2
3 # This file is part of the Adblock Plus build tools,
4 # Copyright (C) 2006-2012 Eyeo GmbH
5 #
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
8 # published by the Free Software Foundation.
9 #
10 # Adblock Plus is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
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/>.
17
18 # Note: These are the base functions common to all packagers, the actual
19 # packagers are implemented in packagerGecko and packagerChrome.
20
21 import os, re, codecs, subprocess, json, jinja2
22 import buildtools
23 from ConfigParser import SafeConfigParser
24
25 def getDefaultFileName(baseDir, metadata, version, ext):
26 return os.path.join(baseDir, '%s-%s.%s' % (metadata.get('general', 'basename') , version, ext))
27
28 def getMetadataPath(baseDir):
29 return os.path.join(baseDir, 'metadata')
30
31 def readMetadata(baseDir):
32 metadata = SafeConfigParser()
33 metadata.optionxform = str
34 file = codecs.open(getMetadataPath(baseDir), 'rb', encoding='utf-8')
35 metadata.readfp(file)
36 file.close()
37 return metadata
38
39 def getBuildNum(baseDir):
40 try:
41 (result, dummy) = subprocess.Popen(['hg', 'id', '-R', baseDir, '-n'], stdout =subprocess.PIPE).communicate()
42 return re.sub(r'\D', '', result)
43 except Exception:
44 return '0'
45
46 def getBuildVersion(baseDir, metadata, releaseBuild, buildNum=None):
47 version = metadata.get('general', 'version')
48 if not releaseBuild:
49 if buildNum == None:
50 buildNum = getBuildNum(baseDir)
51 if len(buildNum) > 0:
52 if re.search(r'(^|\.)\d+$', version):
53 # Numerical version number - need to fill up with zeros to have three
54 # version components.
55 while version.count('.') < 2:
56 version += '.0'
57 version += '.' + buildNum
58 return version
59
60 def getTemplate(template, autoEscape=False):
61 templatePath = buildtools.__path__[0]
62 if autoEscape:
63 env = jinja2.Environment(loader=jinja2.FileSystemLoader(templatePath), autoe scape=True, extensions=['jinja2.ext.autoescape'])
64 else:
65 env = jinja2.Environment(loader=jinja2.FileSystemLoader(templatePath))
66 env.filters.update({'json': json.dumps})
67 return env.get_template(template)
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