 Issue 29756692:
  Noissue - Adapt best practices for trailing commas (cms)  (Closed)
    
  
    Issue 29756692:
  Noissue - Adapt best practices for trailing commas (cms)  (Closed) 
  | Left: | ||
| Right: | 
| LEFT | RIGHT | 
|---|---|
| 1 # This file is part of the Adblock Plus web scripts, | 1 # This file is part of the Adblock Plus web scripts, | 
| 2 # Copyright (C) 2006-present eyeo GmbH | 2 # Copyright (C) 2006-present eyeo GmbH | 
| 3 # | 3 # | 
| 4 # Adblock Plus is free software: you can redistribute it and/or modify | 4 # Adblock Plus is free software: you can redistribute it and/or modify | 
| 5 # it under the terms of the GNU General Public License version 3 as | 5 # it under the terms of the GNU General Public License version 3 as | 
| 6 # published by the Free Software Foundation. | 6 # published by the Free Software Foundation. | 
| 7 # | 7 # | 
| 8 # Adblock Plus is distributed in the hope that it will be useful, | 8 # Adblock Plus is distributed in the hope that it will be useful, | 
| 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 self.connection = urllib3.connection_from_url('https://api.crowdin.com/' ) | 42 self.connection = urllib3.connection_from_url('https://api.crowdin.com/' ) | 
| 43 | 43 | 
| 44 def raw_request(self, request_method, api_endpoint, query_params=(), **kwarg s): | 44 def raw_request(self, request_method, api_endpoint, query_params=(), **kwarg s): | 
| 45 url = '/api/project/%s/%s?%s' % ( | 45 url = '/api/project/%s/%s?%s' % ( | 
| 46 urllib.quote(self.project_name), | 46 urllib.quote(self.project_name), | 
| 47 urllib.quote(api_endpoint), | 47 urllib.quote(api_endpoint), | 
| 48 urllib.urlencode((('key', self.api_key),) + query_params), | 48 urllib.urlencode((('key', self.api_key),) + query_params), | 
| 49 ) | 49 ) | 
| 50 try: | 50 try: | 
| 51 response = self.connection.request( | 51 response = self.connection.request( | 
| 52 request_method, str(url), **kwargs | 52 request_method, str(url), **kwargs | 
| 
Sebastian Noack
2018/04/19 13:51:19
Apparently flake8-commas insist on comma after var
 
Sebastian Noack
2018/04/19 14:23:34
It turned out we can just ignore C815 to avoid tha
 | |
| 53 ) | 53 ) | 
| 54 except urllib3.exceptions.HTTPError: | 54 except urllib3.exceptions.HTTPError: | 
| 55 logger.error('Connection to API endpoint %s failed', url) | 55 logger.error('Connection to API endpoint %s failed', url) | 
| 56 raise | 56 raise | 
| 57 if response.status < 200 or response.status >= 300: | 57 if response.status < 200 or response.status >= 300: | 
| 58 logger.error('API call to %s failed:\n%s', url, response.data) | 58 logger.error('API call to %s failed:\n%s', url, response.data) | 
| 59 raise urllib3.exceptions.HTTPError(response.status) | 59 raise urllib3.exceptions.HTTPError(response.status) | 
| 60 return response | 60 return response | 
| 61 | 61 | 
| 62 def request(self, request_method, api_endpoint, data=None, files=None): | 62 def request(self, request_method, api_endpoint, data=None, files=None): | 
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 os.remove(os.path.join(root, f)) | 264 os.remove(os.path.join(root, f)) | 
| 265 # Then extract the new ones in place | 265 # Then extract the new ones in place | 
| 266 for member in archive.namelist(): | 266 for member in archive.namelist(): | 
| 267 path, file_name = posixpath.split(member) | 267 path, file_name = posixpath.split(member) | 
| 268 ext = posixpath.splitext(file_name)[1] | 268 ext = posixpath.splitext(file_name)[1] | 
| 269 path_parts = path.split(posixpath.sep) | 269 path_parts = path.split(posixpath.sep) | 
| 270 locale, file_path = path_parts[0], path_parts[1:] | 270 locale, file_path = path_parts[0], path_parts[1:] | 
| 271 if ext.lower() == '.json' and locale in inverted_required_locales: | 271 if ext.lower() == '.json' and locale in inverted_required_locales: | 
| 272 output_path = os.path.join( | 272 output_path = os.path.join( | 
| 273 locale_path, inverted_required_locales[locale], | 273 locale_path, inverted_required_locales[locale], | 
| 274 *file_path + [file_name], | 274 *file_path + [file_name] | 
| 275 ) | 275 ) | 
| 276 with archive.open(member) as source_file: | 276 with archive.open(member) as source_file: | 
| 277 locale_file_contents = json.load(source_file) | 277 locale_file_contents = json.load(source_file) | 
| 278 if len(locale_file_contents): | 278 if len(locale_file_contents): | 
| 279 with codecs.open(output_path, 'wb', 'utf-8') as target_f ile: | 279 with codecs.open(output_path, 'wb', 'utf-8') as target_f ile: | 
| 280 json.dump(locale_file_contents, target_file, ensure_ ascii=False, | 280 json.dump(locale_file_contents, target_file, ensure_ ascii=False, | 
| 281 sort_keys=True, indent=2, separators=(',', ': ')) | 281 sort_keys=True, indent=2, separators=(',', ': ')) | 
| 282 | 282 | 
| 283 | 283 | 
| 284 def crowdin_sync(source_dir, crowdin_api_key): | 284 def crowdin_sync(source_dir, crowdin_api_key): | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 if __name__ == '__main__': | 329 if __name__ == '__main__': | 
| 330 if len(sys.argv) < 3: | 330 if len(sys.argv) < 3: | 
| 331 print >>sys.stderr, 'Usage: python -m cms.bin.translate www_directory cr owdin_project_api_key [logging_level]' | 331 print >>sys.stderr, 'Usage: python -m cms.bin.translate www_directory cr owdin_project_api_key [logging_level]' | 
| 332 sys.exit(1) | 332 sys.exit(1) | 
| 333 | 333 | 
| 334 logging.basicConfig() | 334 logging.basicConfig() | 
| 335 logger.setLevel(sys.argv[3] if len(sys.argv) > 3 else logging.INFO) | 335 logger.setLevel(sys.argv[3] if len(sys.argv) > 3 else logging.INFO) | 
| 336 | 336 | 
| 337 source_dir, crowdin_api_key = sys.argv[1:3] | 337 source_dir, crowdin_api_key = sys.argv[1:3] | 
| 338 crowdin_sync(source_dir, crowdin_api_key) | 338 crowdin_sync(source_dir, crowdin_api_key) | 
| LEFT | RIGHT |