-
Notifications
You must be signed in to change notification settings - Fork 0
/
color_scheme.py
58 lines (47 loc) · 1.51 KB
/
color_scheme.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
50
51
52
53
54
55
56
57
58
import os.path
import os
from os.path import expanduser
import re
from shutil import copyfile
SAVED_FILE = './saved_id'
UNIX_FOLDER_PREFIX = '/.mozilla/firefox/'
UNIX_FOLDER_POSTFIX = '.default/'
WINDOWS_FOLDER_PREFIX = '%APPDATA%/Mozilla/Firefox/Profiles/'
WINDOWS_FOLDER_POSTFIX = '.default/'
def pre_exist():
if os.path.isfile(SAVED_FILE):
with open(SAVED_FILE, 'r') as f:
return f.read()
else:
return
def store_id(pid):
with open(SAVED_FILE, 'w') as f:
f.write(pid)
# Step 1: check if profile ID exists.
pid = pre_exist()
if pid:
pass
else:
print('Enter your firefox profile id:')
pid = input()
store_id(pid)
folder = expanduser('~')+UNIX_FOLDER_PREFIX+pid+UNIX_FOLDER_POSTFIX if os.name == 'posix' else \
WINDOWS_FOLDER_PREFIX+pid+WINDOWS_FOLDER_POSTFIX if os.name == 'nt' else None
# Step 2: choose color scheme
color_schemes = next(os.walk('.'))[1]
non_hidden_check = re.compile(r'^[^\.].*')
color_schemes = [x for x in color_schemes if non_hidden_check.match(x)]
print('Choose your scheme:')
for i, cs in enumerate(color_schemes):
print(i, cs)
i = int(input())
scheme_folder = color_schemes[i]
# Step 3: Copy and paste to the target folder
print('Chosen scheme: '+scheme_folder)
print('Copying to" '+folder)
# Create chrome folder
if not os.path.exists(folder+'chrome'):
os.makedirs(folder+'chrome')
copyfile('./'+scheme_folder+'/userContent.css', folder+'chrome/userContent.css')
copyfile('./'+scheme_folder+'/user.js', folder+'user.js')
print('Done')