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

Unified Diff: packagerChrome.py

Issue 9199007: Unified in-memory file processing between Gecko and Chrome (Closed)
Patch Set: Created Jan. 14, 2013, 11:14 a.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
@@ -12,34 +12,35 @@
# 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, re, json, struct
from StringIO import StringIO
-from zipfile import ZipFile, ZIP_DEFLATED
-from packager import getDefaultFileName, readMetadata, getBuildVersion, getTemplate
+from packager import getDefaultFileName, readMetadata, getBuildVersion, getTemplate, Files
defaultLocale = 'en_US'
def getIgnoredFiles(params):
- return ['store.description']
+ return set(('store.description',))
def getPackageFiles(params):
+ result = set(('_locales', 'icons', 'jquery-ui', 'lib', 'skin', 'ui',))
+
+ if params['devenv']:
+ result.add('qunit')
+
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)
+ result.add(file)
+ return result
def createManifest(params):
template = getTemplate('manifest.json.tmpl')
templateData = dict(params)
baseDir = templateData['baseDir']
metadata = templateData['metadata']
@@ -97,63 +98,37 @@ def createManifest(params):
manifest = json.dumps(data, sort_keys=True, indent=2)
return manifest.encode('utf-8')
def createPoller(params):
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
- readFile(params, files, os.path.join(path, file))
- else:
- file = open(path, 'rb')
- data = file.read()
- file.close()
-
- name = os.path.relpath(path, params['baseDir']).replace('\\', '/')
- files[name] = data
-
def convertJS(params, files):
from jshydra.abp_rewrite import doRewrite
baseDir = params['baseDir']
for file, sources in params['metadata'].items('convert_js'):
- dirsep = file.find('/')
- if dirsep >= 0:
- # Not a top-level file, make sure it is inside an included directory
- dirname = file[0:dirsep]
- if os.path.join(baseDir, dirname) not in getPackageFiles(params):
- continue
+ # Make sure the file is inside an included directory
+ if '/' in file and not files.isIncluded(file):
+ continue
sourceFiles = re.split(r'\s+', sources)
args = []
try:
argsStart = sourceFiles.index('--arg')
args = sourceFiles[argsStart + 1:]
sourceFiles = sourceFiles[0:argsStart]
except ValueError:
pass
sourceFiles = map(lambda f: os.path.abspath(os.path.join(baseDir, f)), sourceFiles)
files[file] = doRewrite(sourceFiles, args)
-def packFiles(files):
- buffer = StringIO()
- zip = ZipFile(buffer, 'w', ZIP_DEFLATED)
- for file, data in files.iteritems():
- zip.writestr(file, data)
- zip.close()
- return buffer.getvalue()
-
def signBinary(zipdata, keyFile):
import M2Crypto
if not os.path.exists(keyFile):
M2Crypto.RSA.gen_key(1024, 65537, callback=lambda x: None).save_key(keyFile, cipher=None)
key = M2Crypto.EVP.load_key(keyFile)
key.sign_init()
key.sign_update(zipdata)
return key.final()
@@ -184,39 +159,39 @@ def createBuild(baseDir, outFile=None, b
'baseDir': baseDir,
'releaseBuild': releaseBuild,
'version': version,
'experimentalAPI': experimentalAPI,
'devenv': devenv,
'metadata': metadata,
}
- files = {}
+ files = Files(getPackageFiles(params), getIgnoredFiles(params))
files['manifest.json'] = createManifest(params)
- for path in getPackageFiles(params):
- if os.path.exists(path):
- readFile(params, files, path)
+ files.read(baseDir)
if metadata.has_section('convert_js'):
convertJS(params, files)
if devenv:
files['devenvPoller__.js'] = createPoller(params)
- zipdata = packFiles(files)
+ zipdata = files.zipToString()
signature = None
pubkey = None
if keyFile != None:
signature = signBinary(zipdata, keyFile)
pubkey = getPublicKey(keyFile)
writePackage(outFile, pubkey, signature, zipdata)
def createDevEnv(baseDir):
fileBuffer = StringIO()
createBuild(baseDir, outFile=fileBuffer, devenv=True, releaseBuild=True)
+
+ from zipfile import ZipFile
zip = ZipFile(StringIO(fileBuffer.getvalue()), 'r')
zip.extractall(os.path.join(baseDir, 'devenv'))
zip.close()
print 'Development environment created, waiting for connections from active extensions...'
metadata = readMetadata(baseDir)
connections = [0]
« no previous file with comments | « packager.py ('k') | packagerGecko.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld