Skip to content

Commit 6ad5032

Browse files
authored
formatted
1 parent a340086 commit 6ad5032

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

chromium/utils/remove-json-keys.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,49 @@
1111
json_folder = '_locales'
1212

1313
# UI initializations
14-
os.system('color') ; print('\033[0;92m') # set font to bright green
14+
os.system('color')
15+
print('\033[0;92m') # set font to bright green
1516
terminal_width = os.get_terminal_size()[0]
16-
def print_trunc(msg) : print(msg if len(msg) < terminal_width else msg[0:terminal_width-4] + '...')
17+
18+
def print_trunc(msg):
19+
print(msg if len(msg) < terminal_width else msg[0 : terminal_width - 4] + '...')
1720

1821
print('')
1922

2023
# Prompt user for keys to remove
2124
keys_to_remove = []
2225
while True:
2326
key = input("Enter key to remove (or ENTER if done): ")
24-
if not key : break
27+
if not key:
28+
break
2529
keys_to_remove.append(key)
2630

2731
# Determine closest JSON dir
2832
print_trunc(f'Searching for { json_folder }...')
2933
script_dir = os.path.abspath(os.path.dirname(__file__))
30-
for root, dirs, files in os.walk(script_dir): # search script dir recursively
34+
for root, dirs, files in os.walk(script_dir): # search script dir recursively
3135
if json_folder in dirs:
32-
json_dir = os.path.join(root, json_folder) ; break
33-
else: # search script parent dirs recursively
36+
json_dir = os.path.join(root, json_folder)
37+
break
38+
else: # search script parent dirs recursively
3439
parent_dir = os.path.dirname(script_dir)
3540
while parent_dir and parent_dir != script_dir:
3641
for root, dirs, files in os.walk(parent_dir):
3742
if json_folder in dirs:
38-
json_dir = os.path.join(root, json_folder) ; break
39-
if json_dir : break
43+
json_dir = os.path.join(root, json_folder)
44+
break
45+
if json_dir:
46+
break
4047
parent_dir = os.path.dirname(parent_dir)
41-
else : json_dir = None
48+
else:
49+
json_dir = None
4250

4351
# Print result
44-
if json_dir : print_trunc(f'JSON directory found!\n\n>> { json_dir }\n')
45-
else : print_trunc(f'Unable to locate a { json_folder } directory.') ; exit()
52+
if json_dir:
53+
print_trunc(f'JSON directory found!\n\n>> { json_dir }\n')
54+
else:
55+
print_trunc(f'Unable to locate a { json_folder } directory.')
56+
exit()
4657

4758
# Process JSON files and remove specified keys
4859
keys_removed, keys_skipped, processed_count = [], [], 0
@@ -52,7 +63,8 @@ def print_trunc(msg) : print(msg if len(msg) < terminal_width else msg[0:termina
5263

5364
# Open found JSON file
5465
file_path = os.path.join(root, filename)
55-
with open(file_path, 'r', encoding='utf-8') as f : data = f.read()
66+
with open(file_path, 'r', encoding='utf-8') as f:
67+
data = f.read()
5668

5769
# Remove keys
5870
modified = False
@@ -62,9 +74,11 @@ def print_trunc(msg) : print(msg if len(msg) < terminal_width else msg[0:termina
6274
if count > 0:
6375
keys_removed.append((key, os.path.relpath(file_path, json_dir)))
6476
modified = True
65-
else : keys_skipped.append((key, os.path.relpath(file_path, json_dir)))
77+
else:
78+
keys_skipped.append((key, os.path.relpath(file_path, json_dir)))
6679
if modified:
67-
with open(file_path, 'w', encoding='utf-8') as f : f.write(data)
80+
with open(file_path, 'w', encoding='utf-8') as f:
81+
f.write(data)
6882
processed_count += 1
6983

7084
# Print file summaries

0 commit comments

Comments
 (0)