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

Side by Side Diff: localeTools.py

Issue 29560569: Issue 5815 - Fixed Crowdin upload with non-ASCII characters (Closed)
Patch Set: Put each argument on seperate line Created Oct. 1, 2017, 2:20 p.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 urlparse 10 import urlparse
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 params = urllib.urlencode([('languages[]', locale) for locale in locales]) 337 params = urllib.urlencode([('languages[]', locale) for locale in locales])
338 338
339 crowdin_request(projectName, 'edit-project', key, post_data=params) 339 crowdin_request(projectName, 'edit-project', key, post_data=params)
340 340
341 341
342 def crowdin_prepare_upload(files): 342 def crowdin_prepare_upload(files):
343 """Create a post body and matching headers, which Crowdin can handle.""" 343 """Create a post body and matching headers, which Crowdin can handle."""
344 boundary = '----------ThIs_Is_tHe_bouNdaRY_$' 344 boundary = '----------ThIs_Is_tHe_bouNdaRY_$'
345 body = '' 345 body = ''
346 for name, data in files: 346 for name, data in files:
347 mimetype = mimetypes.guess_type(name)[0]
348 body += ( 347 body += (
349 '--{boundary}\r\n' 348 '--{boundary}\r\n'
350 'Content-Disposition: form-data; name="files[{name}]"; ' 349 'Content-Disposition: form-data; name="files[{name}]"; '
351 'filename="{name}"\r\n' 350 'filename="{name}"\r\n'
352 'Content-Type: {mimetype}; charset=utf-8\r\n' 351 'Content-Type: {mimetype}; charset=utf-8\r\n'
353 'Content-Transfer-Encoding: binary\r\n' 352 'Content-Transfer-Encoding: binary\r\n'
354 '\r\n{data}\r\n' 353 '\r\n{data}\r\n'
355 '--{boundary}--\r\n' 354 '--{boundary}--\r\n'
356 ).format(boundary=boundary, name=name, data=data, mimetype=mimetype) 355 ).format(boundary=boundary,
356 name=name,
357 data=data.encode('utf-8'),
358 mimetype=mimetypes.guess_type(name)[0])
357 359
358 body = body.encode('utf-8')
359 return ( 360 return (
360 StringIO(body), 361 StringIO(body),
361 { 362 {
362 'Content-Type': ('multipart/form-data; boundary=' + boundary), 363 'Content-Type': ('multipart/form-data; boundary=' + boundary),
363 'Content-Length': len(body) 364 'Content-Length': len(body)
364 }, 365 },
365 ) 366 )
366 367
367 368
368 def updateTranslationMaster(localeConfig, metadata, dir, projectName, key): 369 def updateTranslationMaster(localeConfig, metadata, dir, projectName, key):
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 505
505 # Remove any extra files 506 # Remove any extra files
506 for dir, files in dirs.iteritems(): 507 for dir, files in dirs.iteritems():
507 baseDir = os.path.join(localeConfig['base_path'], dir) 508 baseDir = os.path.join(localeConfig['base_path'], dir)
508 if not os.path.exists(baseDir): 509 if not os.path.exists(baseDir):
509 continue 510 continue
510 for file in os.listdir(baseDir): 511 for file in os.listdir(baseDir):
511 path = os.path.join(baseDir, file) 512 path = os.path.join(baseDir, file)
512 if os.path.isfile(path) and (file.endswith('.json') or file.endswith ('.properties') or file.endswith('.dtd')) and not file in files: 513 if os.path.isfile(path) and (file.endswith('.json') or file.endswith ('.properties') or file.endswith('.dtd')) and not file in files:
513 os.remove(path) 514 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