forked from huzecong/ghcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
purge_folder.py
executable file
·30 lines (26 loc) · 1 KB
/
purge_folder.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
#!/usr/bin/env python3
import argparse
import os
import subprocess
import flutes
import ghcc
parser = argparse.ArgumentParser()
parser.add_argument("folder", type=str) # the folder to clean up
parser.add_argument("-y", action="store_true", default=False) # yes
args = parser.parse_args()
try:
parent = os.path.abspath(os.path.join(args.folder, ".."))
folder = os.path.split(os.path.abspath(args.folder))[1]
yes = args.y
if not yes:
confirm = input(f"This will delete {parent} / {folder}. Confirm? [y/N] ")
yes = confirm.lower() in ["y", "yes"]
if yes:
ghcc.utils.run_docker_command(["rm", "-rf", f"/usr/src/{folder}"],
user=0, directory_mapping={parent: "/usr/src"})
except subprocess.CalledProcessError as e:
flutes.log(f"Command failed with retcode {e.returncode}", "error")
output = e.output.decode("utf-8")
if len(output) > 200:
output = output[:200] + "... (omitted)"
flutes.log("Captured output: " + output)