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

Side by Side Diff: translations.py

Issue 29549604: Issue 5729 - remove_redundant_translations fails due to the presence of system file (Closed)
Patch Set: Created Sept. 19, 2017, 10:04 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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 import filecmp 3 import filecmp
4 import os 4 import os
5 import re 5 import re
6 import shutil 6 import shutil
7 import sys 7 import sys
8 import urllib2 8 import urllib2
9 if os.name == 'nt':
10 import win32api, win32con
9 from lxml import etree 11 from lxml import etree
10 from StringIO import StringIO 12 from StringIO import StringIO
11 from zipfile import ZipFile 13 from zipfile import ZipFile
12 14
13 import buildtools.localeTools 15 import buildtools.localeTools
14 16
15 BASE_PATH = os.path.dirname(os.path.abspath(__file__)) 17 BASE_PATH = os.path.dirname(os.path.abspath(__file__))
16 LOCALES_PATH = os.path.join(BASE_PATH, "mobile", "android", "base", "locales", 18 LOCALES_PATH = os.path.join(BASE_PATH, "mobile", "android", "base", "locales",
17 "adblockbrowser") 19 "adblockbrowser")
18 PROJECT_URL = "http://api.crowdin.net/api/project/adblockbrowserandroid" 20 PROJECT_URL = "http://api.crowdin.net/api/project/adblockbrowserandroid"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 language.findtext('code'): language.findtext('translated_progress') 76 language.findtext('code'): language.findtext('translated_progress')
75 }) 77 })
76 return languages 78 return languages
77 79
78 def remove_redundant_translations(): 80 def remove_redundant_translations():
79 default_locale_path = os.path.join(LOCALES_PATH, DEFAULT_LOCALE) 81 default_locale_path = os.path.join(LOCALES_PATH, DEFAULT_LOCALE)
80 for locale in os.listdir(LOCALES_PATH): 82 for locale in os.listdir(LOCALES_PATH):
81 if locale == DEFAULT_LOCALE: 83 if locale == DEFAULT_LOCALE:
82 continue 84 continue
83 locale_path = os.path.join(LOCALES_PATH, locale) 85 locale_path = os.path.join(LOCALES_PATH, locale)
86 # ignore system files
diegocarloslima 2017/09/19 20:03:54 I think you can change the comment to just 'ignore
jens 2017/09/20 08:38:12 Acknowledged.
87 if os.path.isfile(locale_path):
88 continue;
89 # ignore hidden folders
90 if folder_is_hidden(locale_path):
91 continue;
84 if not filecmp.dircmp(locale_path, default_locale_path).diff_files: 92 if not filecmp.dircmp(locale_path, default_locale_path).diff_files:
85 shutil.rmtree(locale_path) 93 shutil.rmtree(locale_path)
86 94
95 def folder_is_hidden(p):
96 if os.name == 'nt':
97 # windows
98 attribute = win32api.GetFileAttributes(p)
99 return attribute & (win32con.FILE_ATTRIBUTE_HIDDEN | win32con.FILE_ATTRI BUTE_SYSTEM)
Vasily Kuznetsov 2017/09/19 21:48:04 Our Python style guide limits lines to 79 characte
jens 2017/09/20 08:38:12 Acknowledged.
100 else:
101 # linux and osx
102 return p.startswith('.')
103
87 if __name__ == "__main__": 104 if __name__ == "__main__":
88 if len(sys.argv) < 3: 105 if len(sys.argv) < 3:
89 print_usage() 106 print_usage()
90 sys.exit(1) 107 sys.exit(1)
91 108
92 command, api_key = sys.argv[1:] 109 command, api_key = sys.argv[1:]
93 if command != "get": 110 if command != "get":
94 print_usage() 111 print_usage()
95 sys.exit(2) 112 sys.exit(2)
96 113
97 get_translations(api_key) 114 get_translations(api_key)
98 remove_redundant_translations() 115 remove_redundant_translations()
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