Left: | ||
Right: |
OLD | NEW |
---|---|
1 # coding: utf-8 | 1 # coding: utf-8 |
2 | 2 |
3 # This Source Code Form is subject to the terms of the Mozilla Public | 3 # This Source Code Form is subject to the terms of the Mozilla Public |
4 # License, v. 2.0. If a copy of the MPL was not distributed with this | 4 # License, v. 2.0. If a copy of the MPL was not distributed with this |
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/. | 5 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
6 | 6 |
7 import os, sys, re, hashlib, base64, urllib, json | 7 import os |
8 import sys | |
9 import re | |
10 import hashlib | |
11 import base64 | |
12 import urllib | |
13 import json | |
14 import io | |
8 from ConfigParser import SafeConfigParser | 15 from ConfigParser import SafeConfigParser |
9 from StringIO import StringIO | 16 from StringIO import StringIO |
10 import xml.dom.minidom as minidom | 17 import xml.dom.minidom as minidom |
11 import buildtools.localeTools as localeTools | 18 import buildtools.localeTools as localeTools |
12 | 19 |
13 import packager | 20 import packager |
14 from packager import readMetadata, getMetadataPath, getDefaultFileName, getBuild Version, getTemplate, Files | 21 from packager import readMetadata, getMetadataPath, getDefaultFileName, getBuild Version, getTemplate, Files |
15 | 22 |
16 KNOWN_APPS = { | 23 KNOWN_APPS = { |
17 'conkeror': '{a79fe89b-6662-4ff4-8e88-09950ad4dfde}', | 24 'conkeror': '{a79fe89b-6662-4ff4-8e88-09950ad4dfde}', |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 | 56 |
50 baseDir = params['baseDir'] | 57 baseDir = params['baseDir'] |
51 for file in os.listdir(baseDir): | 58 for file in os.listdir(baseDir): |
52 if file.endswith('.js') or file.endswith('.xml'): | 59 if file.endswith('.js') or file.endswith('.xml'): |
53 result.add(file) | 60 result.add(file) |
54 return result | 61 return result |
55 | 62 |
56 def getIgnoredFiles(params): | 63 def getIgnoredFiles(params): |
57 return {'.incomplete', 'meta.properties'} | 64 return {'.incomplete', 'meta.properties'} |
58 | 65 |
66 def archive_path(path, baseDir): | |
67 return '/'.join(os.path.relpath(path, baseDir).split(os.sep)) | |
Sebastian Noack
2014/12/17 08:18:12
Nit: x.split(os.sep) -> os.path.split(x)
Wladimir Palant
2014/12/17 13:26:04
Done.
| |
68 | |
59 def isValidLocale(localesDir, dir, includeIncomplete=False): | 69 def isValidLocale(localesDir, dir, includeIncomplete=False): |
60 if re.search(r'[^\w\-]', dir): | 70 if re.search(r'[^\w\-]', dir): |
61 return False | 71 return False |
62 curLocaleDir = os.path.join(localesDir, dir) | 72 curLocaleDir = os.path.join(localesDir, dir) |
63 if not os.path.isdir(curLocaleDir): | 73 if not os.path.isdir(curLocaleDir): |
64 return False | 74 return False |
65 if len(os.listdir(curLocaleDir)) == 0: | 75 if len(os.listdir(curLocaleDir)) == 0: |
66 return False | 76 return False |
67 if not includeIncomplete and os.path.exists(os.path.join(localesDir, dir, '.in complete')): | 77 if not includeIncomplete and os.path.exists(os.path.join(localesDir, dir, '.in complete')): |
68 return False | 78 return False |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 def createManifest(params): | 146 def createManifest(params): |
137 global KNOWN_APPS, defaultLocale | 147 global KNOWN_APPS, defaultLocale |
138 template = getTemplate('install.rdf.tmpl', autoEscape=True) | 148 template = getTemplate('install.rdf.tmpl', autoEscape=True) |
139 templateData = dict(params) | 149 templateData = dict(params) |
140 templateData['localeMetadata'] = readLocaleMetadata(params['baseDir'], params[ 'locales']) | 150 templateData['localeMetadata'] = readLocaleMetadata(params['baseDir'], params[ 'locales']) |
141 initTranslators(templateData['localeMetadata']) | 151 initTranslators(templateData['localeMetadata']) |
142 templateData['KNOWN_APPS'] = KNOWN_APPS | 152 templateData['KNOWN_APPS'] = KNOWN_APPS |
143 templateData['defaultLocale'] = defaultLocale | 153 templateData['defaultLocale'] = defaultLocale |
144 return template.render(templateData).encode('utf-8') | 154 return template.render(templateData).encode('utf-8') |
145 | 155 |
156 def importLocales(params, files): | |
157 SECTION = 'import_locales' | |
158 if not params['metadata'].has_section(SECTION): | |
159 return | |
160 | |
161 import localeTools | |
162 | |
163 for locale in params['locales']: | |
164 for item in params['metadata'].items(SECTION): | |
165 path, keys = item | |
166 parts = [locale if p == '*' else p for p in path.split('/')] | |
167 source = os.path.join(os.path.dirname(item.source), *parts) | |
168 if not os.path.exists(source): | |
Sebastian Noack
2014/12/17 08:18:12
Nit: I'd prefer to catch the IOError when openenin
Wladimir Palant
2014/12/17 13:26:04
Sure, but that's not a scenario where race conditi
Sebastian Noack
2014/12/17 13:59:07
Theoretically, the contents of the file system can
| |
169 continue | |
170 | |
171 with io.open(source, 'r', encoding='utf-8') as handle: | |
172 data = json.load(handle) | |
173 | |
174 target_name = os.path.splitext(os.path.basename(source))[0] + '.properties ' | |
175 target = archive_path(os.path.join(getLocalesDir(params['baseDir']), local e, target_name), params['baseDir']) | |
176 | |
177 files[target] = '' | |
178 for key, value in sorted(data.items()): | |
179 message = value['message'] | |
180 files[target] += localeTools.generateStringEntry(key, message, target).e ncode('utf-8') | |
181 | |
146 def fixupLocales(params, files): | 182 def fixupLocales(params, files): |
147 global defaultLocale | 183 global defaultLocale |
148 | 184 |
149 # Read in default locale data, it might not be included in files | 185 # Read in default locale data, it might not be included in package files |
150 defaultLocaleDir = os.path.join(getLocalesDir(params['baseDir']), defaultLocal e) | 186 defaultLocaleDir = os.path.join(getLocalesDir(params['baseDir']), defaultLocal e) |
187 reference_files = Files(getPackageFiles(params), getIgnoredFiles(params)) | |
188 reference_files.read(defaultLocaleDir, archive_path(defaultLocaleDir, params[' baseDir'])) | |
189 reference_params = dict(params) | |
190 reference_params['locales'] = [defaultLocale] | |
191 importLocales(reference_params, reference_files) | |
192 | |
151 reference = {} | 193 reference = {} |
152 ignoredFiles = getIgnoredFiles(params) | 194 for path, data in reference_files.iteritems(): |
153 for file in os.listdir(defaultLocaleDir): | 195 filename = path.split('/')[-1] |
154 path = os.path.join(defaultLocaleDir, file) | 196 data = localeTools.parseString(data.decode('utf-8'), filename) |
155 if file in ignoredFiles or not os.path.isfile(path): | |
156 continue | |
157 data = localeTools.readFile(path) | |
158 if data: | 197 if data: |
159 reference[file] = data | 198 reference[filename] = data |
160 | 199 |
161 for locale in params['locales']: | 200 for locale in params['locales']: |
162 for file in reference.iterkeys(): | 201 for file in reference.iterkeys(): |
163 path = 'chrome/locale/%s/%s' % (locale, file) | 202 path = 'chrome/locale/%s/%s' % (locale, file) |
164 if path in files: | 203 if path in files: |
165 data = localeTools.parseString(files[path].decode('utf-8'), path) | 204 data = localeTools.parseString(files[path].decode('utf-8'), path) |
166 for key, value in reference[file].iteritems(): | 205 for key, value in reference[file].iteritems(): |
167 if not key in data: | 206 if not key in data: |
168 files[path] += localeTools.generateStringEntry(key, value, path).enc ode('utf-8') | 207 files[path] += localeTools.generateStringEntry(key, value, path).enc ode('utf-8') |
169 else: | 208 else: |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 | 340 |
302 files = Files(getPackageFiles(params), getIgnoredFiles(params), | 341 files = Files(getPackageFiles(params), getIgnoredFiles(params), |
303 process=lambda path, data: processFile(path, data, params)) | 342 process=lambda path, data: processFile(path, data, params)) |
304 files['install.rdf'] = createManifest(params) | 343 files['install.rdf'] = createManifest(params) |
305 if metadata.has_section('mapping'): | 344 if metadata.has_section('mapping'): |
306 files.readMappedFiles(metadata.items('mapping')) | 345 files.readMappedFiles(metadata.items('mapping')) |
307 files.read(baseDir, skip=('chrome')) | 346 files.read(baseDir, skip=('chrome')) |
308 for name, path in getChromeSubdirs(baseDir, params['locales']).iteritems(): | 347 for name, path in getChromeSubdirs(baseDir, params['locales']).iteritems(): |
309 if os.path.isdir(path): | 348 if os.path.isdir(path): |
310 files.read(path, 'chrome/%s' % name) | 349 files.read(path, 'chrome/%s' % name) |
350 importLocales(params, files) | |
311 fixupLocales(params, files) | 351 fixupLocales(params, files) |
312 if not 'bootstrap.js' in files: | 352 if not 'bootstrap.js' in files: |
313 addMissingFiles(params, files) | 353 addMissingFiles(params, files) |
314 if metadata.has_section('preprocess'): | 354 if metadata.has_section('preprocess'): |
315 files.preprocess([f for f, _ in metadata.items('preprocess')]) | 355 files.preprocess([f for f, _ in metadata.items('preprocess')]) |
316 if keyFile: | 356 if keyFile: |
317 signFiles(files, keyFile) | 357 signFiles(files, keyFile) |
318 files.zip(outFile, sortKey=lambda x: '!' if x == 'META-INF/zigbert.rsa' else x ) | 358 files.zip(outFile, sortKey=lambda x: '!' if x == 'META-INF/zigbert.rsa' else x ) |
319 | 359 |
320 def autoInstall(baseDir, type, host, port, multicompartment=False): | 360 def autoInstall(baseDir, type, host, port, multicompartment=False): |
321 fileBuffer = StringIO() | 361 fileBuffer = StringIO() |
322 createBuild(baseDir, type=type, outFile=fileBuffer, multicompartment=multicomp artment) | 362 createBuild(baseDir, type=type, outFile=fileBuffer, multicompartment=multicomp artment) |
323 urllib.urlopen('http://%s:%s/' % (host, port), data=fileBuffer.getvalue()) | 363 urllib.urlopen('http://%s:%s/' % (host, port), data=fileBuffer.getvalue()) |
OLD | NEW |