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

Unified Diff: localeTools.py

Issue 29556601: Issue 5777 - Update crowdin interface (Closed)
Patch Set: Belatedly addressed Sebastian's comments Created Sept. 28, 2017, 9:29 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: localeTools.py
diff --git a/localeTools.py b/localeTools.py
index 92d7a87bf793d39c1868c3cc696a952f1ee7a904..6062eaef544b3827eb4406b034cab8e814cd8f8f 100644
--- a/localeTools.py
+++ b/localeTools.py
@@ -93,23 +93,15 @@ chromeLocales = [
'zh-TW',
]
-CROWDIN_AP_URL = 'https://api.crowdin.com/api/project/{}/{}'
+CROWDIN_AP_URL = 'https://api.crowdin.com/api/project'
def crowdin_url(project_name, action, key, get={}):
"""Create a valid url for a crowdin endpoint."""
- url = CROWDIN_AP_URL.format(project_name, action)
- get['key'] = key
- get['json'] = 1
-
- scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
-
- query = urlparse.parse_qs(query)
- query.update(get)
-
- return urlparse.urlunparse((
- scheme, netloc, path, params, urllib.urlencode(query), fragment
- ))
+ return '{}/{}/{}?{}'.format(CROWDIN_AP_URL,
tlucas 2017/09/28 21:33:58 as discussed: simpler building of the desired url
Sebastian Noack 2017/09/28 22:18:37 Is this even worth a separate function now? I woul
tlucas 2017/09/29 09:09:37 I agree, no extra function necessary - Done.
+ urllib.quote(project_name),
+ urllib.quote(action),
+ urllib.urlencode(dict(get, key=key, json=1)))
def crowdin_request(project_name, action, key, get={}, post_data=None,
@@ -355,22 +347,23 @@ def crowdin_prepare_upload(files):
"""Create a post body and matching headers, which Crowdin can handle."""
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 += 'Content-Transfer-Encoding: binary\r\n'
- body += '\r\n' + data + '\r\n'
- body += '--%s--\r\n' % boundary
+ for name, data in files:
+ body += ('--{boundary}\r\n'
+ 'Content-Disposition: form-data; name="files[{name}]"; '
+ 'filename="{name}"\r\n'
Sebastian Noack 2017/09/28 22:18:37 Nit: You can avoid wrapping before the end of line
tlucas 2017/09/29 09:09:37 Done.
+ 'Content-Type: application/octet-stream; charset=utf-8\r\n'
tlucas 2017/09/28 21:33:58 as discussed: charset in each file's individual Co
Sebastian Noack 2017/09/28 22:18:37 This should be "application/json", I guess?
Sebastian Noack 2017/09/28 22:51:55 Or even better, you could dynamically detect the t
tlucas 2017/09/29 09:09:37 Good point - Done.
+ 'Content-Transfer-Encoding: binary\r\n'
+ '\r\n{data}\r\n'
+ '--{boundary}--\r\n').format(boundary=boundary, name=name,
+ data=data)
body = body.encode('utf-8')
return (
StringIO(body),
{
- 'Content-Type': ('multipart/form-data; ; charset=utf-8; '
- 'boundary=' + boundary),
+ 'Content-Type': ('multipart/form-data; boundary=' + boundary),
'Content-Length': len(body)
- }
+ },
)
@@ -403,11 +396,11 @@ def updateTranslationMaster(localeConfig, metadata, dir, projectName, key):
add.append((newName, data))
if len(add):
- data = {'titles[{}]'.format(name): re.sub(r'\.json', '', name)
- for name, data in add}
- data['type'] = 'chrome'
+ query = {'titles[{}]'.format(name): os.path.splitext(name)[0]
tlucas 2017/09/28 21:33:58 os.path.splitext as discussed
+ for name, _ in add}
+ query['type'] = 'chrome'
data, headers = crowdin_prepare_upload(add)
- crowdin_request(projectName, 'add-file', key, post_data=data,
+ crowdin_request(projectName, 'add-file', key, query, post_data=data,
tlucas 2017/09/28 21:33:58 Hasn't benn noticed before: the query was overwrit
headers=headers)
if len(update):
data, headers = crowdin_prepare_upload(update)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld