diff --git a/skratch.py b/skratch.py index d88bf9a..8e4598e 100755 --- a/skratch.py +++ b/skratch.py @@ -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: