[Pkg-mozext-commits] [adblock-plus] 264/464: Switched from getlocalization.com to crowdin.net as localization service

David Prévot taffit at moszumanska.debian.org
Tue Jul 22 20:44:23 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository adblock-plus.

commit f8705d20ba70aa8ed2e293895cb2570a1161ebd9
Author: Wladimir Palant <trev at adblockplus.org>
Date:   Thu Jul 5 11:35:50 2012 +0200

    Switched from getlocalization.com to crowdin.net as localization service
---
 build.py       | 13 +++++------
 localeTools.py | 73 ++++++++++++++++++++++++++++++++--------------------------
 2 files changed, 46 insertions(+), 40 deletions(-)

diff --git a/build.py b/build.py
index fd8e6c9..98075a1 100644
--- a/build.py
+++ b/build.py
@@ -193,20 +193,19 @@ def runAutoInstall(baseDir, scriptName, opts, args, type):
 
 
 def updateTranslationMaster(baseDir, scriptName, opts, args, type):
-  if len(args) < 2:
-    print 'User name and password are required to update translation master files.'
+  if len(args) < 1:
+    print 'Project key is required to update translation master files.'
     usage(scriptName, type, 'translate')
     return
 
-  user = args[0]
-  password = args[1]
+  key = args[0]
 
   import buildtools.packager as packager
   defaultLocaleDir = os.path.join(packager.getLocalesDir(baseDir), packager.defaultLocale)
   basename = packager.readMetadata(baseDir).get('general', 'baseName')
 
   import buildtools.localeTools as localeTools
-  localeTools.updateTranslationMaster(defaultLocaleDir, packager.defaultLocale, basename, user, password)
+  localeTools.updateTranslationMaster(defaultLocaleDir, packager.defaultLocale, basename, key)
 
 def showDescriptions(baseDir, scriptName, opts, args, type):
   locales = None
@@ -321,8 +320,8 @@ with addCommand(runAutoInstall, 'autoinstall') as command:
 
 with addCommand(updateTranslationMaster, 'translate') as command:
   command.shortDescription = 'Updates translation master files'
-  command.description = 'Updates the translation master files on getlocalization.com.'
-  command.params = '[options] user password'
+  command.description = 'Updates the translation master files on crowdin.net.'
+  command.params = '[options] project-key'
   command.supportedTypes = ('gecko')
 
 with addCommand(showDescriptions, 'showdesc') as command:
diff --git a/localeTools.py b/localeTools.py
index c23b5b3..95dd495 100644
--- a/localeTools.py
+++ b/localeTools.py
@@ -134,47 +134,54 @@ def toJSON(path):
   result = OrderedDict()
   for name, comment, value in it:
     obj = {'message': value}
-    if comment != None:
-      obj['description'] = comment
+    if comment == None:
+      obj['description'] = name
+    else:
+      obj['description'] = '%s: %s' % (name, comment)
     result[name] = obj
   return json.dumps(result, indent=2)
 
-def updateTranslationMaster(dir, locale, projectName, user, password):
-  def encode_multipart_formdata(filename, data):
-    boundary = '----------ThIs_Is_tHe_bouNdaRY_$'
-    body =  '--%s\r\n' % boundary
-    body += 'Content-Disposition: form-data; name="%s"; filename="%s"\r\n' % ('file', filename)
-    body += 'Content-Type: application/octet-stream\r\n'
-    body += '\r\n' + data + '\r\n'
-    body += '--%s--\r\n' % boundary
-    content_type = 'multipart/form-data; boundary=%s' % boundary
-    return content_type, body
-
-  locale = re.sub(r'-.*', '', locale)
-  passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
-  passman.add_password(None, 'https://api.getlocalization.com/', user, password)
-  opener = urllib2.build_opener(urllib2.HTTPBasicAuthHandler(passman))
-  result = json.load(opener.open('https://api.getlocalization.com/%s/api/list-master/json/' % projectName))
-  if not result.get('success', 0):
-    raise Exception('Server indicated the retrieving the list of masters failed')
-
-  existing = set(result['master_files'])
+def updateTranslationMaster(dir, locale, projectName, key):
+  result = json.load(urllib2.urlopen('http://api.crowdin.net/api/project/%s/info?key=%s&json=1' % (projectName, key)))
+
+  existing = set(map(lambda f: f['name'], result['files']))
+  add = []
+  update = []
   for file in os.listdir(dir):
     path = os.path.join(dir, file)
     if os.path.isfile(path):
       data = toJSON(path)
       if data:
-        if file in existing:
-          url = 'https://api.getlocalization.com/%s/api/update-master/' % projectName
-          existing.remove(file)
+        newName = file + '.json'
+        if newName in existing:
+          update.append((newName, data))
+          existing.remove(newName)
         else:
-          url = 'https://api.getlocalization.com/%s/api/create-master/json/%s/' % (projectName, locale)
-
-        content_type, body = encode_multipart_formdata(file, data.encode('utf-8'))
-        request = urllib2.Request(url, body)
-        request.add_header('Content-Type', content_type)
-        request.add_header('Content-Length', len(body))
-        opener.open(request).read()
+          add.append((newName, data))
 
+  def postFiles(files, url):
+    boundary = '----------ThIs_Is_tHe_bouNdaRY_$'
+    body = ''
+    for file, data in files:
+      body +=  '--%s\r\n' % boundary
+      body += 'Content-Disposition: form-data; name="files[%s]"; filename="%s"\r\n' % (file, file)
+      body += 'Content-Type: application/octet-stream\r\n'
+      body += '\r\n' + data.encode('utf-8') + '\r\n'
+      body += '--%s--\r\n' % boundary
+
+    request = urllib2.Request(url, body)
+    request.add_header('Content-Type', 'multipart/form-data; boundary=%s' % boundary)
+    request.add_header('Content-Length', len(body))
+    result = urllib2.urlopen(request).read()
+    if result.find('<success') < 0:
+      raise Exception('Server indicated that the operation was not successful\n' + result)
+
+  if len(add):
+    postFiles(add, 'http://api.crowdin.net/api/project/%s/add-file?key=%s&type=chrome' % (projectName, key))
+  if len(update):
+    postFiles(update, 'http://api.crowdin.net/api/project/%s/update-file?key=%s' % (projectName, key))
   for file in existing:
-    print 'Warning: master file %s needs to be removed' % file
+    result = urllib2.urlopen('http://api.crowdin.net/api/project/%s/delete-file?key=%s&file=%s' % (projectName, key, file)).read()
+    if result.find('<success') < 0:
+      raise Exception('Server indicated that the operation was not successful\n' + result)
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git



More information about the Pkg-mozext-commits mailing list