mkstemp nesting cleanup

This commit is contained in:
phixxy 2026-03-05 01:32:04 -08:00
parent 95742a7e15
commit 4a77a03f45

View file

@ -12,15 +12,17 @@ def make_dir(d):
def delete_all(d):
files = list_all(d)
if files:
x = input("Delete the above files? y/N ")
if x.lower() == 'y':
for file in files:
f = os.path.join(d,file)
os.remove(f)
print(f"removing: {f}")
print("Done")
if not files:
return
x = input("Delete the above files? y/N ")
if x.lower() != 'y':
return
for file in files:
f = os.path.join(d,file)
os.remove(f)
print(f"removing: {f}")
print("Done")
def list_all(d):
if not os.path.exists(d):
print("Skratch path doesn't exist")
@ -43,17 +45,17 @@ def get_editor(use_v):
return e
def mkstemp(fp):
if fp[-6:] == "XXXXXX":
for x in range(0,1000):
r = ''.join(random.choices(string.ascii_letters, k=6))
fp = fp[:-6] + r
if not os.path.exists(fp):
return fp
print("Error: Could not create new file, try running skratch -c and try again")
return None
else:
if fp[-6:] != "XXXXXX":
print(f'Error: mkstemp got filepath: {fp}')
return None
for x in range(0,1000):
r = ''.join(random.choices(string.ascii_letters, k=6))
fp = fp[:-6] + r
if not os.path.exists(fp):
return fp
print("Error: Could not create new file, try running skratch -c and try again")
return None
def run(editor, sk_path, filename=None):
if not filename: