-
Notifications
You must be signed in to change notification settings - Fork 1
/
install_themes.py
146 lines (131 loc) · 5.01 KB
/
install_themes.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import os
import sys
from argparse import ArgumentParser
from glob import glob
from time import sleep
import shutil
import curses
def install_themes(scr, target, what, uninstall):
to_copy = what
action = 'deleting' if uninstall else 'copying'
last_action = 'deleted' if uninstall else 'copied'
scr.addstr(1, 0, 'Target folders: "{}"'.format(target), curses.color_pair(0))
scr.addstr(2, 0, 'Input folders:', curses.color_pair(0))
for a_dir_count, a_dir in enumerate(to_copy):
files = glob(os.path.join('themes', a_dir, '*.pyradio-theme'))
file_count = 0
for count in range(0, len(files)):
Y, X = scr.getmaxyx()
if not uninstall:
s_file = os.path.basename(files[count])
to_file = os.path.basename(files[count]).replace('.pyradio-theme', '') + '-' + a_dir + '.pyradio-theme'
to_file_path = os.path.join(target, to_file)
if uninstall:
try:
os.remove(to_file_path)
file_count += 1
except:
pass
else:
try:
shutil.copy(files[count], to_file_path)
file_count += 1
except:
pass
scr.addstr(a_dir_count + 3, 0, ' {0}: {1} file {2}/{3}'.format(a_dir, action, file_count, len(files)), curses.color_pair(0))
scr.clrtoeol()
if uninstall:
msg = ' {}'.format(to_file)[:X]
else:
msg = ' {0} -> {1}'.format(s_file, to_file)[:X]
scr.addstr(a_dir_count + 4, 0, msg, curses.color_pair(0))
try:
scr.clrtoeol()
except:
pass
scr.refresh()
sleep(0.01)
scr.addstr(a_dir_count + 3, 0, ' {0}: files {1}: {2}/{3}'.format(a_dir, last_action, file_count, len(files)), curses.color_pair(0))
scr.clrtoeol()
scr.addstr(a_dir_count + 4, 0, 'Press any key to exit curses...')
scr.clrtoeol()
scr.refresh()
scr.getch()
def make_target(uninstall):
if sys.platform.startswith('win'):
target = os.path.join(os.getenv('appdata'), 'pyradio', 'themes')
else:
target = os.path.join(os.getenv('HOME', '~'), '.config', 'pyradio', 'themes')
if not os.path.exists(target) and uninstall:
print('Nothing to uninstall...\n')
sys.exit(1)
if not os.path.exists(target):
os.makedirs(target)
if not os.path.exists(target):
print(1, 0, 'Error: Cannot create output folder: "{}"\n\n'.format(target))
sys.exit(1)
return target
parser = ArgumentParser(description='Install PyRadio Base16 themes')
parser.add_argument('-a', '--all', action='store_true',
help='install all themes')
parser.add_argument('-d', '--default', action='store_true',
help='install default themes only')
parser.add_argument('-l', '--default-alt', action='store_true',
help='install default alternative themes only')
parser.add_argument('-r', '--variation', action='store_true',
help='install variation themes only')
parser.add_argument('-t', '--variation-alt', action='store_true',
help='install variation alternative themes only')
parser.add_argument('-u', '--uninstall', action='store_true',
help='uninstall themes (to be used with one of the previous options)')
args = parser.parse_args()
directory_path = os.getcwd()
if not os.path.exists('themes'):
print('Cannot find the "themes" folder...\n')
sys.exit(1)
if args.all or args.default or \
args.default_alt or \
args.variation or \
args.variation_alt:
''' install themes '''
target = make_target(args.uninstall)
if args.uninstall:
print('PyRadio Base16 themes uninstalled!\n')
else:
print('PyRadio Base16 themes installed!\n')
''' start curses '''
scr = curses.initscr()
curses.start_color()
curses.use_default_colors()
try:
curses.curs_set(0)
except:
pass
scr.nodelay(0)
curses.noecho()
curses.cbreak()
if args.uninstall:
scr.addstr(0, 0, 'Uninstalling PyRadio Base16 themes', curses.color_pair(0))
else:
scr.addstr(0, 0, 'Installing PyRadio Base16 themes', curses.color_pair(0))
if args.all:
what = ['default', 'default-alt', 'variation', 'variation-alt']
else:
what = []
if args.default:
if 'default' not in what:
what.append('default')
if args.default_alt:
if 'default-alt' not in what:
what.append('default-alt')
if args.variation:
if 'variation' not in what:
what.append('variation')
if args.variation_alt:
if 'variation-alt' not in what:
what.append('variation-alt')
install_themes(scr, target, what, args.uninstall)
curses.endwin()
else:
''' print help '''
parser.print_help(sys.stdout)