-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall_uninstall.py
185 lines (118 loc) · 6.48 KB
/
install_uninstall.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# -*- coding: utf-8 -*-
import os, sys, platform
USER_SYSTEM = platform.system()
VAR_HOME = os.getenv('HOME')
################## NEW -- LINUX BASED ########################
linux_default_appbase_instalation_path = VAR_HOME + '/.local/share/HayukiApps/scrcpy_pyqtgui/'
linux_default_assets_folder = linux_default_appbase_instalation_path + '/assets/'
linux_default_shell_script = VAR_HOME + '/.local/bin/scrcpy_pyqtgui'
linux_default_desktop_path = VAR_HOME + '/.local/share/applications/'
linux_default_desktop_filename = 'scrcpy_pyqtgui'
################################################################
# GLB => GLOBAL --- abbreviated global variables
glb_ldai = linux_default_appbase_instalation_path
glb_laf = linux_default_assets_folder
glb_ldsc = linux_default_shell_script
glb_ddp = linux_default_desktop_path
a_files = ['error_window.ui', 'main.ui', 'reload_btn.png', 'configure.png', 'user-home-symbolic.png']
def infoAlert(info: str, error=False):
if error == False:
print('[INFO] ' + info)
elif error == True:
print('[ERROR] ' + info)
try:
if type(error) != bool:
if error.lower() == "alert":
print(f"< {error.lower()} > " + info)
except Exception as e:
infoAlert(str(e), error=True)
class ManageInstaller():
def __init__(self, operational_system_base='linux'):
self.osb = operational_system_base;
if self.osb.lower() == 'linux':
self.installerMain = LinuxInstaller()
else:
infoAlert(info="Non Linux-based system detected; Unfortunately this program don't have a installer for this system (not yet).\n\n Try to contact me on social networks:\n\n-Twitter: https://twitter.com/hayukimori\n-Discord: hayukimori#0599\nGitHub: https://github.com/hayukimori", error="alert")
class LinuxInstaller():
def __init__(self):
if self.verifyExistingInstallation() != True:
self.startInstaller()
else:
self.uninstall(quest=True)
def startInstaller(self):
if self.verifyLocalFiles() == False:
infoAlert(f"Some files couldn't be found, please verify files and try again;\nRequired files: {a_files}", error=True)
else:
try:
# => Informing about package
package_info = f"\n=============================================\nApp: Scrcpy PtQtGui\nApp: scrcpy_pyqtgui,\nFont: github\nCreator: hayukimori\n\nInstallation Path: {linux_default_appbase_instalation_path}\nStatus: installing\n=============================================\n"
infoAlert(package_info, error=False)
# => Creating Directories (HayukiApps, assets)
infoAlert(f"Creating directiories:\n {linux_default_appbase_instalation_path}\n{linux_default_assets_folder}", error=False)
os.system('mkdir -p ' + linux_default_appbase_instalation_path)
os.system('mkdir -p ' + linux_default_assets_folder)
# => Moving files to paths
infoAlert("Moving files (assets)", error=False)
for file in a_files:
print(file)
os.system(f"cp assets/{file} " + linux_default_assets_folder)
infoAlert("Moving main files", error=False)
for file in ['main.py', 'install_uninstall.py']:
os.system(f'cp {file} ' + linux_default_appbase_instalation_path)
# => Making Shell Script
# Checks if ".local/bin/" is in $PATH
if self.localbin_in_SystemPath() == False:
infoAlert(f"'{VAR_HOME}/.local/bin' isn't in PATH. To start this application using terminal, you'll need to add in $PATH. See README.md to see how to make it", error=False)
infoAlert("Creating shell script", error=False)
self.makeShellScript()
# => Creating desktop file
infoAlert("Creating desktop file", error=False)
dfileText = f'''[Desktop Entry]\nVersion=1.0\nType=Application\nName=Scrcpy Gui\nComment=Scrcpy PyQt5 gui\nIcon=smartphone\nExec=python main.py\nPath={linux_default_appbase_instalation_path}\nTerminal=false\nStartupNotify=true\nCategories=AudioVideo;nUtility;'''
with open(linux_default_desktop_path + linux_default_desktop_filename + '.desktop', 'w') as df:
df.write(dfileText)
df.close()
except Exception as e:
infoAlert(str(e) + '\n', error=True)
def verifyLocalFiles(self):
results = []
for a in a_files:
if os.path.exists("./assets/" + a) == True:
results.append(True)
if all_true(results):
return True
else:
return False
def verifyExistingInstallation(self):
# for newer version Only
if os.path.exists(linux_default_appbase_instalation_path) == True:
return True
else:
return False
def uninstall(self, quest=True):
print("=====================SCRCPY PYQT GUI FOUND IN SYSTEM ==========================")
print(f"Installation found in {VAR_HOME}/.local/share/HayukiApps/")
uinput = input("Uninstall current version or Update (UPdate / UNinstall)\n((default: Update)): ")
print("===============================================================================")
uinput_no_spaces = uinput.replace(" ", '')
if uinput_no_spaces.lower().startswith('un'):
os.system(f'rm -rf ' + linux_default_appbase_instalation_path)
os.system(f'rm -rf ' + linux_default_desktop_path + linux_default_desktop_filename)
else:
os.system(f'rm -rf ' + linux_default_appbase_instalation_path)
self.startInstaller()
def makeShellScript(self):
script_text = f'''#!/bin/bash\ncd {linux_default_appbase_instalation_path}/\npython main.py'''
with open(linux_default_shell_script, 'w') as ss:
ss.write(script_text)
ss.close()
os.system(f"chmod +x {linux_default_shell_script}")
def localbin_in_SystemPath(self):
path_linux_var = os.getenv('PATH')
if '/.local/bin' in path_linux_var:
return True
else:
return False
def all_true(items):
return all(x == True for x in items)
if __name__ == "__main__":
Installer = ManageInstaller(operational_system_base=USER_SYSTEM)