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

Unified Diff: packagerChrome.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 | « packager.py ('k') | packagerGecko.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packagerChrome.py
===================================================================
--- a/packagerChrome.py
+++ b/packagerChrome.py
@@ -10,61 +10,39 @@
# 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/>.
-import sys, os, subprocess, re, json, codecs, struct, jinja2, buildtools
-from ConfigParser import SafeConfigParser
+import sys, os, re, json, struct
from StringIO import StringIO
from zipfile import ZipFile, ZIP_DEFLATED
+from packager import getDefaultFileName, readMetadata, getBuildVersion, getTemplate
+
defaultLocale = 'en_US'
-def getDefaultFileName(baseDir, metadata, ext):
- return os.path.join(baseDir, '%s-%s.%s' % (metadata.get('general', 'basename'), metadata.get('general', 'version'), ext))
-
-def getMetadataPath(baseDir):
- return os.path.join(baseDir, 'metadata')
-
-def getBuildNum(baseDir):
- try:
- (result, dummy) = subprocess.Popen(['hg', 'id', '-n'], stdout=subprocess.PIPE).communicate()
- return re.sub(r'\D', '', result)
- except Exception:
- return '0'
-
def getIgnoredFiles(params):
return ['store.description']
-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 getPackageFiles(params):
baseDir = params['baseDir']
for file in ('_locales', 'icons', 'jquery-ui', 'lib', 'skin', 'ui'):
yield os.path.join(baseDir, file)
if params['devenv']:
yield os.path.join(baseDir, 'qunit')
for file in os.listdir(baseDir):
if file.endswith('.js') or file.endswith('.html') or file.endswith('.xml'):
yield os.path.join(baseDir, file)
def createManifest(params):
- env = jinja2.Environment(loader=jinja2.FileSystemLoader(buildtools.__path__[0]))
- env.filters.update({'json': json.dumps})
- template = env.get_template('manifest.json.tmpl')
+ template = getTemplate('manifest.json.tmpl')
templateData = dict(params)
baseDir = templateData['baseDir']
metadata = templateData['metadata']
if metadata.has_option('general', 'pageAction'):
icon, popup = re.split(r'\s+', metadata.get('general', 'pageAction'), 1)
templateData['pageAction'] = {'icon': icon, 'popup': popup}
@@ -116,19 +94,17 @@ def createManifest(params):
data = json.loads(re.sub(licenseComment, '', manifest, 1))
if '_dummy' in data:
del data['_dummy']
manifest = json.dumps(data, sort_keys=True, indent=2)
return manifest.encode('utf-8')
def createPoller(params):
- env = jinja2.Environment(loader=jinja2.FileSystemLoader(buildtools.__path__[0]))
- env.filters.update({'json': json.dumps})
- template = env.get_template('chromeDevenvPoller__.js.tmpl')
+ template = getTemplate('chromeDevenvPoller__.js.tmpl')
return template.render(params).encode('utf-8');
def readFile(params, files, path):
ignoredFiles = getIgnoredFiles(params)
if os.path.isdir(path):
for file in os.listdir(path):
if file in ignoredFiles:
continue
@@ -194,27 +170,20 @@ def writePackage(outputFile, pubkey, sig
if pubkey != None and signature != None:
file.write(struct.pack('<4sIII', 'Cr24', 2, len(pubkey), len(signature)))
file.write(pubkey)
file.write(signature)
file.write(zipdata)
def createBuild(baseDir, outFile=None, buildNum=None, releaseBuild=False, keyFile=None, experimentalAPI=False, devenv=False):
metadata = readMetadata(baseDir)
+ version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum)
+
if outFile == None:
- outFile = getDefaultFileName(baseDir, metadata, 'crx' if keyFile else 'zip')
-
- version = metadata.get('general', 'version')
- if not releaseBuild:
- if buildNum == None:
- buildNum = getBuildNum(baseDir)
- if len(buildNum) > 0:
- while version.count('.') < 2:
- version += '.0'
- version += '.' + buildNum
+ outFile = getDefaultFileName(baseDir, metadata, version, 'crx' if keyFile else 'zip')
params = {
'baseDir': baseDir,
'releaseBuild': releaseBuild,
'version': version,
'experimentalAPI': experimentalAPI,
'devenv': devenv,
'metadata': metadata,
« no previous file with comments | « packager.py ('k') | packagerGecko.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld