forked from gbasilveira/telly-spelly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuninstall.py
274 lines (239 loc) · 10.8 KB
/
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#!/usr/bin/env python3
import shutil
import subprocess
import os
from pathlib import Path
import sys
def cleanup_faster_whisper():
"""Clean up Faster Whisper specific files"""
# Faster Whisper uses the same cache directory as original Whisper
# No additional cleanup needed for model files
print("Cleaning up Faster Whisper...")
# Remove any Faster Whisper specific settings
try:
from blaze.settings import Settings
settings = Settings()
# Remove Faster Whisper specific settings
faster_whisper_settings = [
'compute_type',
'device',
'beam_size',
'vad_filter',
'word_timestamps'
]
for setting in faster_whisper_settings:
if setting in settings.settings:
del settings.settings[setting]
settings.save()
print("Faster Whisper settings removed.")
except Exception as e:
print(f"Error cleaning up Faster Whisper settings: {e}")
def uninstall_application():
home = Path.home()
current_dir = Path.cwd()
print("Uninstalling Syllablaze...")
# Clean up Faster Whisper settings
cleanup_faster_whisper()
# Remove pipx installation if it exists
print("Checking for pipx installation and related files...")
# Directly check for pipx venv directory
pipx_venv_dir = home / ".local/share/pipx/venvs/syllablaze"
if pipx_venv_dir.exists():
print(f"Removing pipx venv directory: {pipx_venv_dir}")
try:
shutil.rmtree(pipx_venv_dir)
except Exception as e:
print(f"Error removing pipx venv directory: {e}")
else:
print(f"Pipx venv directory not found: {pipx_venv_dir}")
print(f"Pipx venv directory not found: {pipx_venv_dir}")
# Check for pipx bin symlinks
pipx_bin_dir = home / ".local/share/pipx/bin"
if pipx_bin_dir.exists():
print(f"Checking pipx bin directory: {pipx_bin_dir}")
for item in pipx_bin_dir.iterdir():
if "syllablaze" in item.name:
print(f"Removing pipx bin symlink: {item}")
try:
item.unlink()
except Exception as e:
print(f"Error removing pipx bin symlink: {e}")
else:
print(f"Pipx bin directory not found: {pipx_bin_dir}")
# Check for pipx cache files
pipx_cache_dir = home / ".cache/pipx"
if pipx_cache_dir.exists():
print(f"Checking pipx cache directory: {pipx_cache_dir}")
# Find all syllablaze-related files in the pipx cache
for root, dirs, files in os.walk(pipx_cache_dir):
for item in files + dirs:
if "syllablaze" in item.lower():
item_path = Path(root) / item
print(f"Removing pipx cache item: {item_path}")
try:
if item_path.is_dir():
shutil.rmtree(item_path)
else:
item_path.unlink()
except Exception as e:
print(f"Error removing pipx cache item: {e}")
# Try using pipx command if available
try:
print("Trying pipx command...")
result = subprocess.run(["pipx", "list"], capture_output=True, text=True)
if "syllablaze" in result.stdout:
print("Removing syllablaze with pipx uninstall...")
subprocess.run(["pipx", "uninstall", "syllablaze"], check=False)
except Exception as e:
print(f"Warning: Could not use pipx command: {e}")
# Remove application files
app_dir = home / ".local/share/syllablaze"
if app_dir.exists():
print(f"Removing application directory: {app_dir}")
shutil.rmtree(app_dir)
# Remove launcher
launcher = home / ".local/bin/syllablaze"
if launcher.exists():
print(f"Removing launcher: {launcher}")
launcher.unlink()
# Remove run script and its symbolic link
print("Checking for run scripts and symlinks...")
run_script = current_dir / "run-syllablaze.sh"
if run_script.exists():
print(f"Removing run script: {run_script}")
try:
run_script.unlink()
except Exception as e:
print(f"Error removing run script: {e}")
else:
print(f"Run script not found: {run_script}")
# Check for run script link in .local/bin
run_script_link = home / ".local/bin/run-syllablaze.sh"
if run_script_link.exists():
print(f"Removing run script link: {run_script_link}")
try:
# Try to use unlink first
run_script_link.unlink()
except Exception as e:
print(f"Error removing run script link with unlink: {e}")
try:
# If unlink fails, try using os.remove
os.remove(run_script_link)
print("Successfully removed run script link with os.remove")
except Exception as e2:
print(f"Error removing run script link with os.remove: {e2}")
try:
# If os.remove fails, try using rm command
subprocess.run(["rm", "-f", str(run_script_link)], check=True)
print("Successfully removed run script link with rm command")
except Exception as e3:
print(f"Error removing run script link with rm command: {e3}")
print(f"WARNING: Could not remove {run_script_link}. You may need to remove it manually.")
else:
print(f"Run script link not found: {run_script_link}")
# Also check for syllablaze launcher in .local/bin
syllablaze_link = home / ".local/bin/syllablaze"
if syllablaze_link.exists():
print(f"Removing syllablaze launcher: {syllablaze_link}")
try:
# Try to use unlink first
syllablaze_link.unlink()
except Exception as e:
print(f"Error removing syllablaze launcher with unlink: {e}")
try:
# If unlink fails, try using os.remove
os.remove(syllablaze_link)
print("Successfully removed syllablaze launcher with os.remove")
except Exception as e2:
print(f"Error removing syllablaze launcher with os.remove: {e2}")
try:
# If os.remove fails, try using rm command
subprocess.run(["rm", "-f", str(syllablaze_link)], check=True)
print("Successfully removed syllablaze launcher with rm command")
except Exception as e3:
print(f"Error removing syllablaze launcher with rm command: {e3}")
print(f"WARNING: Could not remove {syllablaze_link}. You may need to remove it manually.")
else:
print(f"Syllablaze launcher not found: {syllablaze_link}")
# Remove desktop file
desktop_file = home / ".local/share/applications/org.kde.syllablaze.desktop"
if desktop_file.exists():
print(f"Removing desktop file: {desktop_file}")
desktop_file.unlink()
# Remove icon
icon_file = home / ".local/share/icons/hicolor/256x256/apps/syllablaze.png"
if icon_file.exists():
print(f"Removing icon file: {icon_file}")
icon_file.unlink()
# Remove virtual environment if it exists
venv_dir = current_dir / "venv"
if venv_dir.exists():
print(f"Removing virtual environment: {venv_dir}")
shutil.rmtree(venv_dir)
# Check for old files (from previous telly-spelly installation)
old_app_dir = home / ".local/share/telly-spelly"
if old_app_dir.exists():
print(f"Removing old application directory: {old_app_dir}")
shutil.rmtree(old_app_dir)
old_launcher = home / ".local/bin/telly-spelly"
if old_launcher.exists():
print(f"Removing old launcher: {old_launcher}")
old_launcher.unlink()
old_desktop_file = home / ".local/share/applications/org.kde.telly_spelly.desktop"
if old_desktop_file.exists():
print(f"Removing old desktop file: {old_desktop_file}")
old_desktop_file.unlink()
old_icon_file = home / ".local/share/icons/hicolor/256x256/apps/telly-spelly.png"
if old_icon_file.exists():
print(f"Removing old icon file: {old_icon_file}")
old_icon_file.unlink()
# Remove build and egg-info directories if they exist
build_dir = current_dir / "build"
if build_dir.exists():
print(f"Removing build directory: {build_dir}")
shutil.rmtree(build_dir)
egg_info_dir = current_dir / "syllablaze.egg-info"
if egg_info_dir.exists():
print(f"Removing egg-info directory: {egg_info_dir}")
shutil.rmtree(egg_info_dir)
# Remove temp_app directory if it exists
temp_app_dir = current_dir / "temp_app"
if temp_app_dir.exists():
print(f"Removing temp_app directory: {temp_app_dir}")
shutil.rmtree(temp_app_dir)
# Remove desktop file in the project directory
project_desktop_file = current_dir / "org.kde.syllablaze.desktop"
if project_desktop_file.exists():
print(f"Removing desktop file in project directory: {project_desktop_file}")
try:
project_desktop_file.unlink()
except Exception as e:
print(f"Error removing desktop file in project directory: {e}")
try:
# If unlink fails, try using os.remove
os.remove(project_desktop_file)
print("Successfully removed desktop file with os.remove")
except Exception as e2:
print(f"Error removing desktop file with os.remove: {e2}")
try:
# If os.remove fails, try using rm command
subprocess.run(["rm", "-f", str(project_desktop_file)], check=True)
print("Successfully removed desktop file with rm command")
except Exception as e3:
print(f"Error removing desktop file with rm command: {e3}")
# Note about KDE favorites menu
print("\nNOTE: If the application still appears in your KDE favorites menu,")
print("you may need to log out and log back in, or manually remove it from the menu.")
# Note about whisper models
whisper_models_dir = home / ".cache/whisper"
if whisper_models_dir.exists():
print(f"\nNOTE: Whisper models in {whisper_models_dir} have been preserved.")
print("These are the .pt files that contain the trained models.")
print("If you want to remove them as well, you can delete them manually.")
print("\nApplication uninstalled successfully!")
if __name__ == "__main__":
try:
uninstall_application()
except Exception as e:
print(f"Uninstallation failed: {e}")
sys.exit(1)