Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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( | 321 allowedLocales = json.load(urllib2.urlopen( |
322 'https://crowdin.com/languages/languages_list?callback=foo' | 322 'https://crowdin.com/languages/languages_list?callback=' |
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() | 323 )) |
324 for match in re.finditer(r'"code"\s*:\s*"([\w\-]+)"', allowedLocales, re.S): | 324 for locale in allowedLocales: |
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
| |
325 allowed.add(match.group(1)) | 325 allowed.add(locale["code"]) |
326 if not allowed.issuperset(locales): | 326 if not allowed.issuperset(locales): |
327 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) |
328 | 328 |
329 locales = list(locales & allowed) | 329 locales = list(locales & allowed) |
330 locales.sort() | 330 locales.sort() |
331 params = urllib.urlencode([('languages[]', locale) for locale in locales]) | 331 params = urllib.urlencode([('languages[]', locale) for locale in locales]) |
332 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() |
333 if result.find('<success') < 0: | 333 if result.find('<success') < 0: |
334 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) |
335 | 335 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
484 | 484 |
485 # Remove any extra files | 485 # Remove any extra files |
486 for dir, files in dirs.iteritems(): | 486 for dir, files in dirs.iteritems(): |
487 baseDir = os.path.join(localeConfig['base_path'], dir) | 487 baseDir = os.path.join(localeConfig['base_path'], dir) |
488 if not os.path.exists(baseDir): | 488 if not os.path.exists(baseDir): |
489 continue | 489 continue |
490 for file in os.listdir(baseDir): | 490 for file in os.listdir(baseDir): |
491 path = os.path.join(baseDir, file) | 491 path = os.path.join(baseDir, file) |
492 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: |
493 os.remove(path) | 493 os.remove(path) |
LEFT | RIGHT |