-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate.py
115 lines (96 loc) · 3.92 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
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
import sys
import os
import re
import zipfile
import json
import urllib.request as request
def main(argv):
getFileFromServer()
foo = getFileList()
filepath = "cache/extract/base16-shell-master/scripts"
colorInfo = []
for fileName in getFileList():
with open(filepath + "/" + fileName) as f:
content = f.readlines()
dic = dict()
dic["name"] = fileName[:-3]
dic.update(getColorInfo(content))
colorInfo.append(dic)
jsonString = json.dumps(colorInfo, indent=4, separators=(',', ':'))
schemesFile = open("schemes.json", "w")
schemesFile.write(jsonString)
schemesFile.close()
print("🎉 Compelete!")
def getFileFromServer(force=False, url="https://github.com/chriskempson/base16-shell/archive/master.zip"):
if not os.path.exists("cache"):
os.mkdir("cache")
if not os.path.exists("cache/master.zip") or force:
print("🚀 Downloading implementation from remote server...")
request.urlretrieve(url, "cache/master.zip")
print("🎉 Download compeleted.")
unZipFile()
def unZipFile():
zipFile = zipfile.ZipFile("cache/master.zip")
if os.path.isdir("cache/extract"):
pass
else:
os.mkdir("cache/extract")
print("🤐 Unzipping implementation...")
for names in zipFile.namelist():
zipFile.extract(names, "cache/extract")
zipFile.close()
print("🎉 Unzip compeleted.")
def getFileList():
return os.listdir("cache/extract/base16-shell-master/scripts")
def getColorInfo(l: list):
# Oh my shit code!!!
dirtyColorInfo = list(filter(lambda x: re.match(r"color.*=", x), l))
dirtyColorInfo = dict(map(lambda x: x.split("="), dirtyColorInfo))
colorNamePrefix = "color"
for i in range(16):
if i < 10:
getColorHex(dirtyColorInfo, colorNamePrefix + "0" + str(i))
else:
getColorHex(dirtyColorInfo, colorNamePrefix + str(i))
getColorHex(dirtyColorInfo, "color_foreground")
getColorHex(dirtyColorInfo, "color_background")
for i in range(16):
if i < 10:
getColorRef(dirtyColorInfo, colorNamePrefix + "0" + str(i))
else:
getColorRef(dirtyColorInfo, colorNamePrefix + str(i))
getColorRef(dirtyColorInfo, "color_foreground")
getColorRef(dirtyColorInfo, "color_background")
cleanColorInfo = dict()
cleanColorInfo["black"] = dirtyColorInfo["color00"]
cleanColorInfo["red"] = dirtyColorInfo["color01"]
cleanColorInfo["green"] = dirtyColorInfo["color02"]
cleanColorInfo["yellow"] = dirtyColorInfo["color03"]
cleanColorInfo["blue"] = dirtyColorInfo["color04"]
cleanColorInfo["purple"] = dirtyColorInfo["color05"]
cleanColorInfo["cyan"] = dirtyColorInfo["color06"]
cleanColorInfo["white"] = dirtyColorInfo["color07"]
cleanColorInfo["brightBlack"] = dirtyColorInfo["color08"]
cleanColorInfo["brightRed"] = dirtyColorInfo["color09"]
cleanColorInfo["brightGreen"] = dirtyColorInfo["color10"]
cleanColorInfo["brightYellow"] = dirtyColorInfo["color11"]
cleanColorInfo["brightBlue"] = dirtyColorInfo["color12"]
cleanColorInfo["brightPurple"] = dirtyColorInfo["color13"]
cleanColorInfo["brightCyan"] = dirtyColorInfo["color14"]
cleanColorInfo["brightWhite"] = dirtyColorInfo["color15"]
cleanColorInfo["background"] = dirtyColorInfo["color_background"]
cleanColorInfo["foreground"] = dirtyColorInfo["color_foreground"]
cleanColorInfo["selectionBackground"] = dirtyColorInfo["color_foreground"]
cleanColorInfo["cursorColor"] = dirtyColorInfo["color_foreground"]
return cleanColorInfo
def getColorHex(dic, name):
if re.match(r"\$.*", dic[name]):
pass
else:
hex = dic[name].split("\"")[1].split("/")
dic[name] = "#" + hex[0] + hex[1] + hex[2]
def getColorRef(dic, name):
if re.match(r"\$.*", dic[name]):
dic[name] = dic[dic[name][1:8]]
if __name__ == "__main__":
main(sys.argv)