Move saved-game deletion to separate file
This commit is contained in:
parent
2715d1992f
commit
b91481f685
|
@ -12,6 +12,7 @@ import json
|
|||
import info
|
||||
import stty
|
||||
import shutil
|
||||
import delete_save
|
||||
from blessings import Terminal
|
||||
|
||||
|
||||
|
@ -223,30 +224,7 @@ group.add_argument(
|
|||
args = parser.parse_args()
|
||||
|
||||
if args.delete_save:
|
||||
try:
|
||||
shutil.move(gamesave_path, gamesave_path + "-old")
|
||||
print("Saved game deleted.")
|
||||
print(f"A backup was created at `{gamesave_path}-old`. To restore it, run:")
|
||||
print(f"mv {gamesave_path}-old {gamesave_path}")
|
||||
except FileNotFoundError:
|
||||
print("No saved game found.")
|
||||
except Exception as e:
|
||||
print("An error occurred.")
|
||||
print(str(type(e)).split("'")[1] + ": " + str(e))
|
||||
cont = input(
|
||||
"Do you want to try to non-recoverably delete the saved game? [Y/n] "
|
||||
)
|
||||
if cont[0] in "Yy":
|
||||
try:
|
||||
os.unlink(gamesave_path)
|
||||
print("Saved game deleted.")
|
||||
except Exception as e:
|
||||
print("An error occurred.")
|
||||
print(str(type(e)).split("'")[1] + ": " + str(e))
|
||||
sys.exit(1)
|
||||
else:
|
||||
sys.exit(1)
|
||||
sys.exit(0)
|
||||
delete_save.delete_save(gamesave_path)
|
||||
elif args.save_game:
|
||||
height = 24
|
||||
width = 80
|
||||
|
|
30
wormpy/delete_save.py
Normal file
30
wormpy/delete_save.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
import os
|
||||
import sys
|
||||
import shutil
|
||||
|
||||
|
||||
def delete_save(gamesave_path):
|
||||
try:
|
||||
shutil.move(gamesave_path, gamesave_path + "-old")
|
||||
print("Saved game deleted.")
|
||||
print(f"A backup was created at `{gamesave_path}-old`. To restore it, run:")
|
||||
print(f"mv {gamesave_path}-old {gamesave_path}")
|
||||
except FileNotFoundError:
|
||||
print("No saved game found.")
|
||||
except Exception as e:
|
||||
print("An error occurred.")
|
||||
print(str(type(e)).split("'")[1] + ": " + str(e))
|
||||
cont = input(
|
||||
"Do you want to try to non-recoverably delete the saved game? [Y/n] "
|
||||
)
|
||||
if cont[0] in "Yy":
|
||||
try:
|
||||
os.unlink(gamesave_path)
|
||||
print("Saved game deleted.")
|
||||
except Exception as e:
|
||||
print("An error occurred.")
|
||||
print(str(type(e)).split("'")[1] + ": " + str(e))
|
||||
sys.exit(1)
|
||||
else:
|
||||
sys.exit(1)
|
||||
sys.exit(0)
|
Loading…
Reference in New Issue
Block a user