mkstemp nesting cleanup
This commit is contained in:
parent
95742a7e15
commit
4a77a03f45
1 changed files with 20 additions and 18 deletions
38
skratch.py
38
skratch.py
|
|
@ -12,15 +12,17 @@ def make_dir(d):
|
||||||
|
|
||||||
def delete_all(d):
|
def delete_all(d):
|
||||||
files = list_all(d)
|
files = list_all(d)
|
||||||
if files:
|
if not files:
|
||||||
x = input("Delete the above files? y/N ")
|
return
|
||||||
if x.lower() == 'y':
|
x = input("Delete the above files? y/N ")
|
||||||
for file in files:
|
if x.lower() != 'y':
|
||||||
f = os.path.join(d,file)
|
return
|
||||||
os.remove(f)
|
for file in files:
|
||||||
print(f"removing: {f}")
|
f = os.path.join(d,file)
|
||||||
print("Done")
|
os.remove(f)
|
||||||
|
print(f"removing: {f}")
|
||||||
|
print("Done")
|
||||||
|
|
||||||
def list_all(d):
|
def list_all(d):
|
||||||
if not os.path.exists(d):
|
if not os.path.exists(d):
|
||||||
print("Skratch path doesn't exist")
|
print("Skratch path doesn't exist")
|
||||||
|
|
@ -43,17 +45,17 @@ def get_editor(use_v):
|
||||||
return e
|
return e
|
||||||
|
|
||||||
def mkstemp(fp):
|
def mkstemp(fp):
|
||||||
if fp[-6:] == "XXXXXX":
|
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:
|
|
||||||
print(f'Error: mkstemp got filepath: {fp}')
|
print(f'Error: mkstemp got filepath: {fp}')
|
||||||
return None
|
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):
|
def run(editor, sk_path, filename=None):
|
||||||
if not filename:
|
if not filename:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue