Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: localeTools.py

Issue 29372826: Issue 4836 - Have the setuptrans command use the current Crowdin API (Closed)
Patch Set: Receive and parse locales as JSON Created Jan. 25, 2017, 3:42 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 = json.load(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='
323 allowed.add(match.group(1)) 323 ))
324 for locale in allowedLocales:
325 allowed.add(locale["code"])
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)
333 335
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
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)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld