Skip to content

Instantly share code, notes, and snippets.

@Monsterovich
Last active December 8, 2020 23:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Monsterovich/363a219551e07ecfc14169c765ae13b2 to your computer and use it in GitHub Desktop.
Save Monsterovich/363a219551e07ecfc14169c765ae13b2 to your computer and use it in GitHub Desktop.
cmake_uninstall script
#!/usr/bin/python3
import sys
import os
import click
if len(sys.argv) < 2:
exit("Usage: cmake_uninstall <install_manifest.txt>")
if os.geteuid() != 0:
exit("You need to have root privileges to run this script.\nPlease try again, this time using 'sudo'. Exiting.")
file = open(sys.argv[1], 'r')
content = file.readlines()
print("The following files will be REMOVED:\n")
for line in content:
print("\t" + line, end = "")
print("")
if click.confirm('Do you want to continue?', default = False):
for line in content:
try:
os.remove(line.rstrip())
except FileNotFoundError:
print("File doesn't exist: " + line.rstrip())
exit("Aborting.")
path = os.path.commonpath([line.rstrip() for line in content])
print("Removing empty directories in " + path + "\n")
empty_dirs = []
while True:
for root, dirs, files in os.walk(path):
if not len(dirs) and not len(files):
empty_dirs.append(root)
if len(empty_dirs) == 0:
break
for dir in empty_dirs:
print("\t" + dir)
os.rmdir(dir)
empty_dirs = []
print("Done!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment