forked from talha131/gruvbox-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.py
executable file
·50 lines (38 loc) · 1.21 KB
/
generate.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
import sys
import glob
import os.path
def hex_to_rgb(value):
value = value.lstrip('#')
lv = len(value)
return tuple(int(value[i:i + lv // 3], 16) for i in range(0, lv, lv // 3))
replace = {}
styles = []
with open('color.table') as f:
styles = f.readlines()
for style in styles:
split = style.split()
if len(split) < 2:
continue
colorTitle = split[0]
htmlHex = split[1]
val = split[-1] if split[-1][0] == '#' else split[1]
rgb = hex_to_rgb(val)
r = rgb[0] / 255
g = rgb[1] / 255
b = rgb[2] / 255
replacement = '{} {} {}'.format(r, g, b)
replace['$({})'.format(colorTitle)] = replacement
replace['$({}#red)'.format(colorTitle)] = r
replace['$({}#green)'.format(colorTitle)] = g
replace['$({}#blue)'.format(colorTitle)] = b
replace['#({})'.format(colorTitle)] = htmlHex
for fname in glob.glob('templates/*'):
final_content = ""
with open(fname) as f:
content = f.read()
for k,v in replace.items():
content = content.replace(k, '{}'.format(v));
final_content = content
with open(os.path.join('output', os.path.basename(fname)), 'w') as f:
f.write(final_content)