mkstemp nesting cleanup
This commit is contained in:
parent
95742a7e15
commit
4a77a03f45
1 changed files with 20 additions and 18 deletions
36
skratch.py
36
skratch.py
|
|
@ -12,14 +12,16 @@ 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):
|
||||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue