-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.py
114 lines (90 loc) · 2.82 KB
/
install.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
import os
import sys
import subprocess
from textwrap import dedent
def print_green(skk):
print("\033[92m {}\033[00m".format(skk))
def get_venv_path():
home_dir = os.path.expanduser("~")
venv_dir = os.path.join(home_dir, ".venvs")
if not os.path.exists(venv_dir):
os.makedirs(venv_dir)
return os.path.join(venv_dir, "wttrman_venv")
def create_venv(venv_path):
print("Creating the virtual environment...", end="")
sys.stdout.flush()
subprocess.run(
["python3", "-m", "venv", venv_path],
check=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
print_green("")
print("Ensuring pip is up to date...", end="")
sys.stdout.flush()
pip_path = os.path.join(venv_path, "bin", "pip")
subprocess.run(
[pip_path, "install", "--upgrade", "pip"],
check=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
print_green("")
def install_app(venv_path):
print("Installing Wttrman into the virtual environment...", end="")
sys.stdout.flush()
pip_path = os.path.join(venv_path, "bin", "pip")
subprocess.run(
[pip_path, "install", "wttrman"],
check=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
print_green("")
def get_icon(venv_path):
site_packages = os.path.join(venv_path, "lib")
for folder in os.listdir(site_packages):
if folder.startswith("python"):
site_packages = os.path.join(site_packages, folder, "site-packages")
break
icon_relative_path = "wttrman/resources/images/wttrman-128.png"
full_icon_path = os.path.join(site_packages, icon_relative_path)
return full_icon_path
def get_python_path(venv_path):
return os.path.join(venv_path, "bin", "python3")
def get_app_path(venv_path):
return os.path.join(venv_path, "bin", "wttrman")
def create_desktop_file(icon, version, python, app):
print("Creating the .desktop entry...", end="")
sys.stdout.flush()
desktop_content = dedent(f"""
[Desktop Entry]
Version={version}
Type=Application
Name=Wttrman
Comment=GUI front-end to https://wttr.in/.
Exec={python} {app}
Icon={icon}
Terminal=false
Categories=Utility;
""")
desktop_content = desktop_content.lstrip()
with open(
os.path.expanduser("~/.local/share/applications/wttrman.desktop"),
"w",
) as f:
f.write(desktop_content)
print_green("")
def install():
venv_path = get_venv_path()
create_venv(venv_path)
install_app(venv_path)
version = "1.2.2"
icon = get_icon(venv_path)
python = get_python_path(venv_path)
app = get_app_path(venv_path)
create_desktop_file(icon, version, python, app)
def main():
install()
if __name__ == "__main__":
main()