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

Delta Between Two Patch Sets: translations.py

Issue 29549604: Issue 5729 - remove_redundant_translations fails due to the presence of system file (Closed)
Left Patch Set: Created Sept. 19, 2017, 10:04 a.m.
Right Patch Set: removed simicolons Created Sept. 26, 2017, 12:09 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
11 from lxml import etree 9 from lxml import etree
12 from StringIO import StringIO 10 from StringIO import StringIO
13 from zipfile import ZipFile 11 from zipfile import ZipFile
14 12
15 import buildtools.localeTools 13 import buildtools.localeTools
16 14
17 BASE_PATH = os.path.dirname(os.path.abspath(__file__)) 15 BASE_PATH = os.path.dirname(os.path.abspath(__file__))
18 LOCALES_PATH = os.path.join(BASE_PATH, "mobile", "android", "base", "locales", 16 LOCALES_PATH = os.path.join(BASE_PATH, "mobile", "android", "base", "locales",
19 "adblockbrowser") 17 "adblockbrowser")
20 PROJECT_URL = "http://api.crowdin.net/api/project/adblockbrowserandroid" 18 PROJECT_URL = "http://api.crowdin.net/api/project/adblockbrowserandroid"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 language.findtext('code'): language.findtext('translated_progress') 74 language.findtext('code'): language.findtext('translated_progress')
77 }) 75 })
78 return languages 76 return languages
79 77
80 def remove_redundant_translations(): 78 def remove_redundant_translations():
81 default_locale_path = os.path.join(LOCALES_PATH, DEFAULT_LOCALE) 79 default_locale_path = os.path.join(LOCALES_PATH, DEFAULT_LOCALE)
82 for locale in os.listdir(LOCALES_PATH): 80 for locale in os.listdir(LOCALES_PATH):
83 if locale == DEFAULT_LOCALE: 81 if locale == DEFAULT_LOCALE:
84 continue 82 continue
85 locale_path = os.path.join(LOCALES_PATH, locale) 83 locale_path = os.path.join(LOCALES_PATH, locale)
86 # ignore system files 84 # ignore 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): 85 if os.path.isfile(locale_path):
88 continue; 86 continue
89 # ignore hidden folders 87 # ignore hidden folders
90 if folder_is_hidden(locale_path): 88 if locale_path.startswith('.'):
91 continue; 89 continue
92 if not filecmp.dircmp(locale_path, default_locale_path).diff_files: 90 if not filecmp.dircmp(locale_path, default_locale_path).diff_files:
93 shutil.rmtree(locale_path) 91 shutil.rmtree(locale_path)
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 92
104 if __name__ == "__main__": 93 if __name__ == "__main__":
105 if len(sys.argv) < 3: 94 if len(sys.argv) < 3:
106 print_usage() 95 print_usage()
107 sys.exit(1) 96 sys.exit(1)
108 97
109 command, api_key = sys.argv[1:] 98 command, api_key = sys.argv[1:]
110 if command != "get": 99 if command != "get":
111 print_usage() 100 print_usage()
112 sys.exit(2) 101 sys.exit(2)
113 102
114 get_translations(api_key) 103 get_translations(api_key)
115 remove_redundant_translations() 104 remove_redundant_translations()
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld