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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | packagerChrome.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packager.py
===================================================================
new file mode 100644
--- /dev/null
+++ b/packager.py
@@ -0,0 +1,67 @@
+# coding: utf-8
+
+# This file is part of the Adblock Plus build tools,
+# Copyright (C) 2006-2012 Eyeo GmbH
+#
+# Adblock Plus is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3 as
+# published by the Free Software Foundation.
+#
+# Adblock Plus is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+
+# Note: These are the base functions common to all packagers, the actual
+# packagers are implemented in packagerGecko and packagerChrome.
+
+import os, re, codecs, subprocess, json, jinja2
+import buildtools
+from ConfigParser import SafeConfigParser
+
+def getDefaultFileName(baseDir, metadata, version, ext):
+ return os.path.join(baseDir, '%s-%s.%s' % (metadata.get('general', 'basename'), version, ext))
+
+def getMetadataPath(baseDir):
+ return os.path.join(baseDir, 'metadata')
+
+def readMetadata(baseDir):
+ metadata = SafeConfigParser()
+ metadata.optionxform = str
+ file = codecs.open(getMetadataPath(baseDir), 'rb', encoding='utf-8')
+ metadata.readfp(file)
+ file.close()
+ return metadata
+
+def getBuildNum(baseDir):
+ try:
+ (result, dummy) = subprocess.Popen(['hg', 'id', '-R', baseDir, '-n'], stdout=subprocess.PIPE).communicate()
+ return re.sub(r'\D', '', result)
+ except Exception:
+ return '0'
+
+def getBuildVersion(baseDir, metadata, releaseBuild, buildNum=None):
+ version = metadata.get('general', 'version')
+ if not releaseBuild:
+ if buildNum == None:
+ buildNum = getBuildNum(baseDir)
+ if len(buildNum) > 0:
+ if re.search(r'(^|\.)\d+$', version):
+ # Numerical version number - need to fill up with zeros to have three
+ # version components.
+ while version.count('.') < 2:
+ version += '.0'
+ version += '.' + buildNum
+ return version
+
+def getTemplate(template, autoEscape=False):
+ templatePath = buildtools.__path__[0]
+ if autoEscape:
+ env = jinja2.Environment(loader=jinja2.FileSystemLoader(templatePath), autoescape=True, extensions=['jinja2.ext.autoescape'])
+ else:
+ env = jinja2.Environment(loader=jinja2.FileSystemLoader(templatePath))
+ env.filters.update({'json': json.dumps})
+ return env.get_template(template)
« no previous file with comments | « no previous file | packagerChrome.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld