-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwal_g810.py
90 lines (77 loc) · 2.9 KB
/
wal_g810.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
import os.path
import json
import sys
import argparse
# wal_g810 details
VERSION = "0.0.2"
# Get path for g810 profiles
g810_file = "colors-wal-g810-led"
def setConfig():
# Get host OS
hostOS = getOS()
# Get user home directory
home_dir = os.getenv("HOME", os.getenv("USERPROFILE"))
# Set wal colors file
wal_colors = os.path.join(home_dir, ".cache", "wal", "colors.json")
# Confirm wal export exists
if not os.path.isfile(wal_colors):
# Print error and exit if not found
print("Wal colors could not be found. Try running `wal` again")
sys.exit(1)
# Set g810 directory by platform
if hostOS == "linux" or hostOS == "darwin":
g810_path = os.path.join(home_dir, ".cache", "wal")
g810_theme = os.path.join(g810_path, g810_file)
elif hostOS == "win32":
print("Windows platform not supported")
sys.exit(1)
else:
# Print error and exit if OS unsupported
print("Unsupported operating system")
sys.exit(1)
# Return file paths as strings for wal color file and g810 profile file
return wal_colors, g810_theme
def themeG810(wal_colors_path, g810_theme_path):
# Open colors.json and load
import_colors = json.load(open(wal_colors_path))
# Transfer wal colors to g810 profile scheme
#generic json file
color_string = import_colors['special']['foreground'].replace("#","")
wal_g810 = "# A wal_g810 profile\n"
wal_g810 += "a" + " " + color_string + "\n"
wal_g810 += "c"
# Write theme json to g810 themes directory
try:
with open(g810_theme_path, 'w') as f:
f.write(wal_g810)
if os.path.isfile(g810_theme_path):
print("The g810-led profile written successfully. Start g810-led with `g810-led -p $HOME/.cache/wal/colors-wal-g810` to view")
except:
print("Error writing g810 theme file")
finally:
sys.exit(1)
def getOS():
# system call for user platform
hostOS = sys.platform
# return os as string: linux, win32, darwin
return hostOS
def getArgs():
# get the arguments with argparse
description = "wal_g810"
arg = argparse.ArgumentParser(description=description)
arg.add_argument("-v", "--version", action="store_true",
help="Print wal_g810 version.")
return arg.parse_args()
def main():
# Parse arguments
arguments = getArgs()
# Print app version
if arguments.version:
print("wal_g810", VERSION)
sys.exit()
# Set file paths
wcp, vtp = setConfig()
# Translate and write theme
themeG810(wcp, vtp)
if __name__ == '__main__':
main()