forked from viscid-hub/Viscid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.py
79 lines (62 loc) · 2.16 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
#!/usr/bin/env python
from __future__ import print_function
import json
import os
import shutil
import sys
INSTALL_MANIFEST = '.install_manifest.json'
try:
FileNotFoundError
except NameError:
class FileNotFoundError(Exception):
pass
def _main():
verb = '-v' in sys.argv or '--verbose' in sys.argv
verb = True
# read the install manifest
try:
with open(INSTALL_MANIFEST, 'r') as fin:
inst_manifest = json.load(fin)
except (IOError, FileNotFoundError):
print("Uninstall Error: Manifest not found, `make install` must be "
"run first.", file=sys.stderr)
return 0
if sys.executable in inst_manifest:
# remove the whole package directory, which now should just
# be populated with empty subdirectories
file_list = inst_manifest[sys.executable]['file_list']
for fname in file_list:
if os.path.isdir(fname):
if verb:
print("Remove tree:", fname, file=sys.stderr)
shutil.rmtree(fname, ignore_errors=False)
elif os.path.isfile(fname):
if verb:
print("Removing:", fname, file=sys.stderr)
os.remove(fname)
else:
if verb:
print("Ignoring:", fname, "(file DNE)", file=sys.stderr)
# remove the whole package directory, which now should just
# be populated with empty subdirectories
try:
pkg_instdir = inst_manifest[sys.executable]['pkg_instdir']
if verb:
print("Remove tree:", pkg_instdir, file=sys.stderr)
shutil.rmtree(pkg_instdir, ignore_errors=False)
except OSError:
pass
# pretend we were never installed in this and rewrite the
# install manifest
del inst_manifest[sys.executable]
with open(INSTALL_MANIFEST, 'w') as fout:
json.dump(inst_manifest, fout, indent=2, sort_keys=True)
elif verb:
print("Uninstall: not in manifest for", sys.executable,
file=sys.stderr)
return 0
if __name__ == "__main__":
sys.exit(_main())
##
## EOF
##