Annotation of br/multifox/build.py, revision 1.5

1.1       hultmann    1: #!/usr/bin/python
                      2: # -*- coding: utf-8 -*-
                      3: 
                      4: # ***** BEGIN LICENSE BLOCK *****
                      5: # Version: MPL 1.1/GPL 2.0/LGPL 2.1
                      6: #
                      7: # The contents of this file are subject to the Mozilla Public License Version
                      8: # 1.1 (the "License"); you may not use this file except in compliance with
                      9: # the License. You may obtain a copy of the License at
                     10: # http://www.mozilla.org/MPL/
                     11: #
                     12: # Software distributed under the License is distributed on an "AS IS" basis,
                     13: # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
                     14: # for the specific language governing rights and limitations under the
                     15: # License.
                     16: #
                     17: # The Original Code is Multifox.
                     18: #
                     19: # The Initial Developer of the Original Code is
                     20: # Jeferson Hultmann <hultmann@gmail.com>
                     21: # Portions created by the Initial Developer are Copyright (C) 2009
                     22: # the Initial Developer. All Rights Reserved.
                     23: #
                     24: # Contributor(s):
                     25: #
                     26: # Alternatively, the contents of this file may be used under the terms of
                     27: # either the GNU General Public License Version 2 or later (the "GPL"), or
                     28: # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
                     29: # in which case the provisions of the GPL or the LGPL are applicable instead
                     30: # of those above. If you wish to allow use of your version of this file only
                     31: # under the terms of either the GPL or the LGPL, and not to allow others to
                     32: # use your version of this file under the terms of the MPL, indicate your
                     33: # decision by deleting the provisions above and replace them with the notice
                     34: # and other provisions required by the GPL or the LGPL. If you do not delete
                     35: # the provisions above, a recipient may use your version of this file under
                     36: # the terms of any one of the MPL, the GPL or the LGPL.
                     37: #
                     38: # ***** END LICENSE BLOCK *****
                     39: 
                     40: import os
                     41: from os.path import join
                     42: import string
                     43: import datetime
                     44: import shutil
                     45: from zipfile import ZipFile, ZIP_STORED, ZIP_DEFLATED
                     46: import hashlib
                     47: 
                     48: 
                     49: def createDirStructure(unpackedDir):
                     50:   os.mkdir(unpackedDir)
                     51:   for myDir in ['modules',
                     52:                 'content',
                     53:                 'components',
                     54:                 'defaults',
                     55:                 'defaults/preferences',
                     56:                 'locale',
                     57:                 'locale/en-US',
1.3       hultmann   58:                 'locale/es-ES',
1.1       hultmann   59:                 'locale/pt-BR']:
                     60: 
                     61:     os.mkdir(unpackedDir + '/' + myDir)
                     62:     #os.makedirs
                     63: 
                     64: 
                     65: def copyBinaryFiles(sourceDir, unpackedDir):
                     66:   files = [
                     67:     '/content/logo-about.png',
                     68:     '/content/logo-popup.png',
                     69:     '/content/logo-icon.png',
1.4       hultmann   70:     '/content/icon.png',
                     71:     '/content/icon-linux.png',
                     72:     '/content/icon-osx.png'
1.1       hultmann   73:   ];
                     74: 
                     75:   for myFile in files:
                     76:     shutil.copy(sourceDir + myFile, unpackedDir + myFile)
                     77: 
                     78: 
                     79: def copyTextFiles(sourceDir, unpackedDir, dic):
                     80:   files = [
                     81:     '/install.rdf',
                     82:     '/chrome.manifest',
                     83: 
1.4       hultmann   84:     '/content/content-injection.js',
1.1       hultmann   85:     '/content/browser.xul',
                     86:     '/content/places.xul',
                     87:     '/content/about.xul',
                     88:     '/content/about-multifox.html',
                     89: 
                     90:     '/components/protocol.js',
                     91: 
                     92:     '/modules/new-window.js',
                     93:     '/modules/menus.js',
                     94:     '/modules/error.js',
1.4       hultmann   95:     '/modules/popup.js',
1.1       hultmann   96: 
                     97:     '/defaults/preferences/prefs.js',
                     98: 
                     99:     '/locale/en-US/about.html',
1.4       hultmann  100:     '/locale/es-ES/about.html',
1.1       hultmann  101:     '/locale/pt-BR/about.html',
1.4       hultmann  102:     '/locale/en-US/general.properties',
1.3       hultmann  103:     '/locale/es-ES/general.properties',
1.1       hultmann  104:     '/locale/pt-BR/general.properties'
                    105:   ]
                    106: 
                    107:   for myFile in files:
                    108:     parseTextFile(sourceDir + myFile, unpackedDir + myFile, dic);
                    109: 
                    110: 
                    111: def buildModule(sourceDir, unpackedDir, dic):
                    112:   buf = ''
                    113:   files = [
                    114:     '/modules/main.main.js',
                    115:     '/modules/main.window.js',
                    116:     '/modules/main.icon.js',
1.4       hultmann  117:     '/modules/main.script-injection.js',
1.1       hultmann  118:     '/modules/main.network.js',
1.4       hultmann  119:     '/modules/main.windowproperties.js',
1.1       hultmann  120:     '/modules/main.cookies.js',
1.4       hultmann  121:     '/modules/main.storage.js',
                    122:     '/modules/main.util.js'
1.1       hultmann  123:   ]
                    124: 
                    125:   for myFile in files:
                    126:     f = open(sourceDir + myFile, 'r')
                    127:     buf += string.Template(f.read()).safe_substitute(dic)
                    128:     f.close()
                    129: 
                    130:   m = open(unpackedDir + '/modules/main.js', 'w')
                    131:   m.write(buf)
                    132:   m.close()
                    133: 
                    134: 
                    135: def parseTextFile(inputPath, outputPath, dic):
                    136:   f = open(inputPath, 'r')
                    137:   buf = string.Template(f.read()).safe_substitute(dic)
                    138:   f.close()
                    139: 
                    140:   f = open(outputPath, 'w')
                    141:   f.write(buf)
                    142:   f.close()
                    143: 
                    144: 
                    145: def createUnpacked(sourceDir, unpackedDir, dic):
                    146:   if os.path.exists(unpackedDir):
                    147:     shutil.rmtree(unpackedDir)
                    148:   createDirStructure(unpackedDir)
                    149:   copyBinaryFiles(sourceDir, unpackedDir)
                    150:   copyTextFiles(sourceDir, unpackedDir, dic)
                    151:   buildModule(sourceDir, unpackedDir, dic)   #main.js
                    152: 
                    153: 
                    154: def createXpi(unpackedDir, xpi_file):
                    155:   zip = ZipFile('build/xpi/' + xpi_file, 'w', ZIP_DEFLATED)
                    156:   for root, dirs, files in os.walk(unpackedDir):
                    157:     for name in files:
                    158:       t = join(root, name)
                    159:       zip.write(t, t.replace(unpackedDir + '\\', ''))
                    160:   zip.close()
                    161: 
                    162: 
                    163: def getHash(path):
                    164:   f = open(path, 'rb')
                    165:   h = hashlib.sha512()
                    166:   while True:
                    167:     data = f.read(8192)
                    168:     if data:
                    169:       h.update(data)
                    170:     else:
                    171:       break
                    172:   f.close()
                    173:   return 'sha512:' + h.hexdigest()
                    174: 
                    175: 
                    176: 
                    177: unpackedDir = 'build/unpacked'
                    178: packageName = 'multifox'
                    179: jsModule = 'multifox-modules'
1.4       hultmann  180: version = '1.2.0'
1.1       hultmann  181: 
                    182: srcVars = {
                    183:             'PACKAGENAME':      packageName,
                    184:             'URI_PACKAGENAME':  'chrome://' + packageName,
                    185:             'JS_MODULE':        jsModule,
                    186:             'URI_JS_MODULE':    'resource://' + jsModule,
                    187:             'BASE_DOM_ID':      'multifox-dom',
                    188: 
1.5     ! hultmann  189:             'APP_MIN_VERSION':  '3.6.3',
        !           190:             'APP_MAX_VERSION':  '3.6.*',
        !           191: 
1.1       hultmann  192:             'EXT_ID':           'multifox@hultmann',
                    193:             'EXT_NAME':         'Multifox',
                    194:             'EXT_VERSION':      version,
                    195:             'EXT_SITE':         'http://br.mozdev.org/multifox/',
                    196: 
                    197:             'XPI_HASH':         '[TBD]',
                    198:             'XPI_NAME':         'multifox-' + version + '.xpi'
                    199:           }
                    200: 
                    201: 
                    202: createUnpacked('src', unpackedDir, srcVars)
                    203: 
                    204: createXpi(unpackedDir, srcVars['XPI_NAME'])
                    205: 
                    206: srcVars['XPI_HASH'] = getHash('build/xpi/' + srcVars['XPI_NAME'])
                    207: 
                    208: parseTextFile('src/update.rdf', 'build/update.rdf', srcVars)

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>