-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautocorrect.py
31 lines (27 loc) · 928 Bytes
/
autocorrect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import config
import utils
import os
from glob import glob
def erase_keys_from_localizables(keys_to_remove):
files_by_lang = utils.get_localizable_files()
for lang, file in files_by_lang.iteritems():
print ">> Autocorrecting : {}".format(file)
lines = utils.get_file_lines(file)
#Create a tmp file to write the correct version of the localizable.string
with open("tmp","w+") as f:
for line in lines:
line = line.content
localizable_key = utils.extract_localizable_key_definition(line)
if localizable_key != None:
if not is_localizable_key_to_remove(localizable_key, keys_to_remove):
f.write(line)
else:
f.write(line) #write in file, because it s probably a commentary
os.rename('tmp', file) #Replace old file
return 0
def is_localizable_key_to_remove(key, keys_to_erase):
if len(key) == 0: #manage error
return True
if key in keys_to_erase:
return True
return False