forked from Tudat/tudatBundle
-
Notifications
You must be signed in to change notification settings - Fork 12
/
uninstall.py
51 lines (42 loc) · 1.43 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
import sys
from pathlib import Path
import os
def usage() -> None:
"""Print usage information."""
print("Usage: python uninstall.py [OPTIONS]", end="\n\n")
print("Options:")
print(" --build-dir <path> Select build directory")
print(" --help, -h Display this information")
return None
if __name__ == "__main__":
ARGUMENTS = {"BUILD_DIR": "build"}
ENVIRONMENT = os.environ
# Define arguments
args = iter(sys.argv[1:])
for arg in args:
if arg == "--build-dir":
ARGUMENTS["BUILD_DIR"] = next(args)
elif arg in ("--help", "-h"):
usage()
exit(0)
else:
usage()
raise ValueError("Invalid argument")
# Ensure that build dir exists
build_dir = Path(ARGUMENTS["BUILD_DIR"]).resolve()
if not build_dir.exists():
raise FileNotFoundError("Failed to cd into build directory")
# Look for installation manifest
if not (build_dir / "custom-manifest.txt").exists():
raise FileNotFoundError("Installation manifest not found")
# Uninstall
with (build_dir / "custom-manifest.txt").open() as manifest:
for line in manifest:
path = Path(line.strip())
if path.exists():
try:
path.unlink()
except PermissionError:
path.rmdir()
else:
print(f"Not installed: {path}")