-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathunlink_profiles.py
executable file
·49 lines (36 loc) · 1.04 KB
/
unlink_profiles.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
from pathlib import Path
import json
import os
import traceback
import sys
def migrate_profile(profile: Path):
prefs_file = profile / 'Preferences'
with prefs_file.open() as fp:
prefs = json.load(fp)
modified = False
KEYS_TO_REMOVE = ['account_info', 'google']
for key in KEYS_TO_REMOVE:
if key in prefs:
del prefs[key]
modified = True
if modified:
print('Update profile:', profile.name)
tmp = prefs_file.with_suffix('.tmp')
with open(tmp, 'w') as fp:
json.dump(prefs, fp)
tmp.rename(prefs_file)
def main():
data_dir = Path(os.environ['XDG_CONFIG_HOME']) / 'chromium'
profiles = [data_dir / 'Default']
profiles.extend(data_dir.glob('Profile *'))
succeeded = True
for profile in profiles:
try:
migrate_profile(profile)
except Exception:
traceback.print_exc()
succeeded = False
sys.exit(0 if succeeded else 1)
if __name__ == '__main__':
main()