-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
uninstall.py
76 lines (65 loc) · 2.37 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
#!/usr/bin/python3
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
# MenuLibre - Advanced fd.o Compliant Menu Editor
# Copyright (C) 2024 Sean Davis <[email protected]>
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import sys
import subprocess
if len(sys.argv) > 1:
args = sys.argv[1:]
else:
args = []
command = [sys.executable, 'setup.py', 'install'] + \
args + ['--record', 'files.txt']
returncode = subprocess.run(
command,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL).returncode
if returncode != 0:
sys.stderr.write("Invalid commandline arguments provided.\n")
sys.stderr.write(
"Use the same commandline arguments you used to install.\n\n")
sys.stderr.write("\t$ python3 uninstall.py --user\n")
sys.stderr.write("\t$ sudo python3 uninstall.py\n\n")
sys.exit(returncode)
if not os.path.exists('files.txt'):
sys.stderr.write("Failed to generate uninstall file list.\n")
sys.exit(1)
files = []
target = None
with open('files.txt', 'r') as filelist:
for line in filelist.readlines():
line = line.strip()
files.append(line)
if target is None and 'share' in line.split('/'):
target = line.split('/share')[0]
os.remove('files.txt')
files.append('%s/share/pixmaps/menulibre.png' % target)
for size in ['scalable', '16x16', '24x24', '32x32', '48x48', '64x64']:
files.append(
'%s/share/icons/hicolor/%s/apps/menulibre.svg' %
(target, size))
if len(files) == 0:
sys.stderr.write("Failed to parse uninstall file list.\n")
sys.exit(1)
for filename in files:
if not os.path.exists(filename):
continue
try:
os.remove(filename)
print("Removing %s" % filename)
except FileNotFoundError:
print("Failed to remove %s" % filename)
sys.exit(0)