-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconkula.py
executable file
·159 lines (134 loc) · 4.62 KB
/
conkula.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env python3
import os
import time
import sys
import glob
from subprocess import run
possible_colors = {
'white': 'f8f8f2',
'red': 'ff5555',
'yellow': 'f1fa8c',
'cyan': '8be9fd',
'orange': 'ffb86c',
'purple': 'bd93f9',
'pink': 'ff79c6',
'lime': '50fa7b'
}
possible_fonts = {
'lato': 'Lato',
'roboto': 'Roboto',
'fira': 'Fira Code',
'mono': 'Mono'
}
env_file = f'/home/{os.getlogin()}/.config/conky/conkula/python/env'
def colors():
print(', '.join(list(possible_colors)))
def fonts():
print(', '.join(list(possible_fonts)))
def setup(*args):
if len(args) >= 5:
print('Error: too many arguments provided. \nTry `python3 conkula.py setup main_color accent_color city font`')
sys.exit(1)
try:
main_color = args[0]
accent_color = args[1]
city = args[2]
try:
font = args[3]
except IndexError:
font = 'Mono'
if main_color not in list(possible_colors) or accent_color not in list(possible_colors):
print('Error: invalid color selected. \nTry `python3 conkula.py colors` to see a list of possible colors')
sys.exit(1)
print(f'Main color: {main_color} | Accent color: {accent_color} | Font: {font} | City: {city}')
confirm = input('is your configuration correct? type `y` to proceed >>> ')
if confirm != 'y':
print('Error: you didn\'t confirm. \nAborting...')
sys.exit(1)
else:
run_setup(main_color, accent_color, city, font)
except IndexError:
print('Error: not enough arguments provided. \nTry `python3 conkula.py setup main_color accent_color city font`')
def run_setup(main_color, accent_color, city, font):
create_env(env_file)
set_font(font)
set_colors(main_color, accent_color)
set_city(city, env_file)
initial_run()
def set_colors(main_color, accent_color):
print('Setting colors...')
time.sleep(1)
print(f'Setting main color to {main_color}')
time.sleep(1)
print(f'Setting accent color to {accent_color}')
time.sleep(1)
files = glob.glob(f'/home/{os.getlogin()}/.config/conky/conkula/conky_config/conky_*')
for file in files:
with open(file, 'r') as f:
data = f.read()
data = data.replace('__MAIN_COLOR__', possible_colors[main_color])
data = data.replace('__ACCENT_COLOR__', possible_colors[accent_color])
with open(file, 'w') as f:
f.write(data)
print('Colors set!')
time.sleep(0.5)
def set_font(font):
match font.casefold():
case "mono":
print('Font not selected, defaulting to Mono')
case "roboto":
font = possible_fonts[font]
case "lato":
font = possible_fonts[font]
case "fira":
font = possible_fonts[font]
case _:
print('Unsupported font selected, aborting.')
sys.exit(1)
print(f'Setting the font to {font}')
time.sleep(1)
files = glob.glob(f'/home/{os.getlogin()}/.config/conky/conkula/conky_config/conky_*')
for file in files:
with open(file, 'r') as f:
data = f.read()
data = data.replace('__FONT__', font)
with open(file, 'w') as f:
f.write(data)
print('Font set!')
time.sleep(0.5)
def set_city(city, env_file):
print(f'Setting city to {city.replace("+", " ")}')
time.sleep(1)
with open(env_file, 'a') as file_object:
file_object.write("\nLOCATION = {}".format(city))
print('City set!')
time.sleep(0.5)
def create_env(file):
try:
# Clear old env file if exists
with open(file, 'w'): pass
# Append [vars] block
with open(file, 'a') as file_object:
file_object.write("[vars]")
except OSError as e:
print('Failed creating the env file.')
print(e)
sys.exit(1)
def initial_run():
first_run = input('Would you like to run conky now? \n(y/n) >>> ')
if first_run == 'y'.casefold():
print('Here we go!')
time.sleep(1)
command = 'sh ~/.config/conky/conkula/startup.sh'
print(f'Executing {command}')
run(f'{command}', shell=True, check=True, text=True)
else:
print('Skipping the startup')
print('Type `bash ~/.config/conky/conkula/startup.sh` to run conky if you change your mind!')
if __name__ == '__main__':
args = sys.argv
try:
globals()[args[1]](*args[2:])
except KeyError:
print('Error: invalid command\nHave you missed the `setup` keyword?')
print(f'Try: `python3 conkula.py setup main_color accent_color city font`')