OLD | NEW |
1 # This Source Code Form is subject to the terms of the Mozilla Public | 1 # This Source Code Form is subject to the terms of the Mozilla Public |
2 # License, v. 2.0. If a copy of the MPL was not distributed with this | 2 # License, v. 2.0. If a copy of the MPL was not distributed with this |
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. | 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
4 | 4 |
5 import re | 5 import re |
6 import os | 6 import os |
7 import sys | 7 import sys |
8 import codecs | 8 import codecs |
9 import json | 9 import json |
10 import urlparse | 10 import urlparse |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 import buildtools.packagerChrome as packager | 46 import buildtools.packagerChrome as packager |
47 localeDir = os.path.join(baseDir, '_locales') | 47 localeDir = os.path.join(baseDir, '_locales') |
48 localeConfig = { | 48 localeConfig = { |
49 'default_locale': packager.defaultLocale, | 49 'default_locale': packager.defaultLocale, |
50 } | 50 } |
51 else: | 51 else: |
52 localeDir = os.path.join( | 52 localeDir = os.path.join( |
53 baseDir, *metadata.get('locales', 'base_path').split('/') | 53 baseDir, *metadata.get('locales', 'base_path').split('/') |
54 ) | 54 ) |
55 localeConfig = { | 55 localeConfig = { |
56 'default_locale': metadata.get('locales', 'default_locale') | 56 'default_locale': metadata.get('locales', 'default_locale'), |
57 } | 57 } |
58 | 58 |
59 localeConfig['base_path'] = localeDir | 59 localeConfig['base_path'] = localeDir |
60 | 60 |
61 locales = [(locale.replace('_', '-'), os.path.join(localeDir, locale)) | 61 locales = [(locale.replace('_', '-'), os.path.join(localeDir, locale)) |
62 for locale in os.listdir(localeDir)] | 62 for locale in os.listdir(localeDir)] |
63 localeConfig['locales'] = dict(locales) | 63 localeConfig['locales'] = dict(locales) |
64 | 64 |
65 return localeConfig | 65 return localeConfig |
66 | 66 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 '--{boundary}--\r\n' | 186 '--{boundary}--\r\n' |
187 ).format(boundary=boundary, | 187 ).format(boundary=boundary, |
188 name=name, | 188 name=name, |
189 data=data.encode('utf-8'), | 189 data=data.encode('utf-8'), |
190 mimetype=mimetypes.guess_type(name)[0]) | 190 mimetype=mimetypes.guess_type(name)[0]) |
191 | 191 |
192 return ( | 192 return ( |
193 StringIO(body), | 193 StringIO(body), |
194 { | 194 { |
195 'Content-Type': 'multipart/form-data; boundary=' + boundary, | 195 'Content-Type': 'multipart/form-data; boundary=' + boundary, |
196 'Content-Length': len(body) | 196 'Content-Length': len(body), |
197 }, | 197 }, |
198 ) | 198 ) |
199 | 199 |
200 | 200 |
201 def updateTranslationMaster(localeConfig, metadata, dir, projectName, key): | 201 def updateTranslationMaster(localeConfig, metadata, dir, projectName, key): |
202 result = crowdin_request(projectName, 'info', key) | 202 result = crowdin_request(projectName, 'info', key) |
203 | 203 |
204 existing = set(map(lambda f: f['name'], result['files'])) | 204 existing = set(map(lambda f: f['name'], result['files'])) |
205 add = [] | 205 add = [] |
206 update = [] | 206 update = [] |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 # Remove any extra files | 318 # Remove any extra files |
319 for dir, files in dirs.iteritems(): | 319 for dir, files in dirs.iteritems(): |
320 baseDir = os.path.join(localeConfig['base_path'], dir) | 320 baseDir = os.path.join(localeConfig['base_path'], dir) |
321 if not os.path.exists(baseDir): | 321 if not os.path.exists(baseDir): |
322 continue | 322 continue |
323 for file in os.listdir(baseDir): | 323 for file in os.listdir(baseDir): |
324 path = os.path.join(baseDir, file) | 324 path = os.path.join(baseDir, file) |
325 valid_extension = file.endswith('.json') | 325 valid_extension = file.endswith('.json') |
326 if os.path.isfile(path) and valid_extension and not file in files: | 326 if os.path.isfile(path) and valid_extension and not file in files: |
327 os.remove(path) | 327 os.remove(path) |
OLD | NEW |