Left: | ||
Right: |
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 urllib | 10 import urllib |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
311 for match in re.finditer(r'&lang=([\w\-]+)"', firefoxLocales): | 311 for match in re.finditer(r'&lang=([\w\-]+)"', firefoxLocales): |
312 locales.add(mapLocale('BCP-47', match.group(1))) | 312 locales.add(mapLocale('BCP-47', match.group(1))) |
313 langPacks = urllib2.urlopen('https://addons.mozilla.org/en-US/firefox/la nguage-tools/').read() | 313 langPacks = urllib2.urlopen('https://addons.mozilla.org/en-US/firefox/la nguage-tools/').read() |
314 for match in re.finditer(r'<tr>.*?</tr>', langPacks, re.S): | 314 for match in re.finditer(r'<tr>.*?</tr>', langPacks, re.S): |
315 if match.group(0).find('Install Language Pack') >= 0: | 315 if match.group(0).find('Install Language Pack') >= 0: |
316 match2 = re.search(r'lang="([\w\-]+)"', match.group(0)) | 316 match2 = re.search(r'lang="([\w\-]+)"', match.group(0)) |
317 if match2: | 317 if match2: |
318 locales.add(mapLocale('BCP-47', match2.group(1))) | 318 locales.add(mapLocale('BCP-47', match2.group(1))) |
319 | 319 |
320 allowed = set() | 320 allowed = set() |
321 allowedLocales = urllib2.urlopen('http://crowdin.net/page/language-codes').r ead() | 321 allowedLocales = urllib2.urlopen( |
322 for match in re.finditer(r'<tr>\s*<td\b[^<>]*>([\w\-]+)</td>', allowedLocale s, re.S): | 322 'https://crowdin.com/languages/languages_list?callback=foo' |
Wladimir Palant
2017/01/24 11:36:23
Please use https://crowdin.com/languages/languages
kzar
2017/01/25 03:45:04
Ah cool, didn't think to try that. Done.
| |
323 ).read() | |
324 for match in re.finditer(r'"code"\s*:\s*"([\w\-]+)"', allowedLocales, re.S): | |
Wladimir Palant
2017/01/24 11:36:23
Please don't use regular expressions to parse JSON
kzar
2017/01/25 03:45:04
(I would have already if I had figured out the way
| |
323 allowed.add(match.group(1)) | 325 allowed.add(match.group(1)) |
324 if not allowed.issuperset(locales): | 326 if not allowed.issuperset(locales): |
325 print "Warning, following locales aren't allowed by server: " + ', '.joi n(locales - allowed) | 327 print "Warning, following locales aren't allowed by server: " + ', '.joi n(locales - allowed) |
326 | 328 |
327 locales = list(locales & allowed) | 329 locales = list(locales & allowed) |
328 locales.sort() | 330 locales.sort() |
329 params = urllib.urlencode([('languages[]', locale) for locale in locales]) | 331 params = urllib.urlencode([('languages[]', locale) for locale in locales]) |
330 result = urllib2.urlopen('http://api.crowdin.net/api/project/%s/edit-project ?key=%s' % (projectName, key), params).read() | 332 result = urllib2.urlopen('http://api.crowdin.net/api/project/%s/edit-project ?key=%s' % (projectName, key), params).read() |
331 if result.find('<success') < 0: | 333 if result.find('<success') < 0: |
332 raise Exception('Server indicated that the operation was not successful\ n' + result) | 334 raise Exception('Server indicated that the operation was not successful\ n' + result) |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
482 | 484 |
483 # Remove any extra files | 485 # Remove any extra files |
484 for dir, files in dirs.iteritems(): | 486 for dir, files in dirs.iteritems(): |
485 baseDir = os.path.join(localeConfig['base_path'], dir) | 487 baseDir = os.path.join(localeConfig['base_path'], dir) |
486 if not os.path.exists(baseDir): | 488 if not os.path.exists(baseDir): |
487 continue | 489 continue |
488 for file in os.listdir(baseDir): | 490 for file in os.listdir(baseDir): |
489 path = os.path.join(baseDir, file) | 491 path = os.path.join(baseDir, file) |
490 if os.path.isfile(path) and (file.endswith('.json') or file.endswith ('.properties') or file.endswith('.dtd')) and not file in files: | 492 if os.path.isfile(path) and (file.endswith('.json') or file.endswith ('.properties') or file.endswith('.dtd')) and not file in files: |
491 os.remove(path) | 493 os.remove(path) |
OLD | NEW |