2023-08-08 09:38:43 +00:00
|
|
|
import glob
|
|
|
|
import os
|
2023-08-29 03:15:16 +00:00
|
|
|
import shutil
|
2023-08-08 09:38:43 +00:00
|
|
|
|
|
|
|
from contextlib import contextmanager
|
|
|
|
|
|
|
|
@contextmanager
|
|
|
|
def pushd(new_dir):
|
|
|
|
previous_dir = os.getcwd()
|
|
|
|
os.chdir(new_dir)
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
os.chdir(previous_dir)
|
|
|
|
|
|
|
|
|
|
|
|
def removeall(dir):
|
|
|
|
[os.remove(f) for f in glob.iglob("{}/*".format(dir), recursive=True)]
|
|
|
|
os.removedirs(dir)
|
2023-08-29 03:15:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
def yeetdir(path):
|
|
|
|
os.makedirs(path, exist_ok=True)
|
|
|
|
shutil.rmtree(path)
|
|
|
|
|
|
|
|
|
|
|
|
def yeetfile(path):
|
|
|
|
if os.path.exists(path):
|
|
|
|
os.remove(path)
|