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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 = json.load(urllib2.urlopen( | 321 allowedLocales = json.load(urllib2.urlopen( |
322 'https://crowdin.com/languages/languages_list?callback=' | 322 'https://crowdin.com/languages/languages_list?callback=' |
323 )) | 323 )) |
324 for locale in allowedLocales: | 324 for locale in allowedLocales: |
325 allowed.add(locale["code"]) | 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) |
OLD | NEW |