Allow deleting and renaming stories in the browser

This commit is contained in:
Gnome Ann
2021-08-31 18:22:30 -04:00
parent db284b2367
commit c276220a35
6 changed files with 260 additions and 27 deletions

View File

@ -1,7 +1,9 @@
import tkinter as tk
from tkinter import filedialog
from os import getcwd, listdir, path
import os
import json
import string
#==================================================================#
# Generic Method for prompting for file path
@ -54,6 +56,12 @@ def getdirpath(dir, title):
else:
return None
#==================================================================#
# Returns the path (as a string) to the given story by its name
#==================================================================#
def storypath(name):
return path.join(path.dirname(path.realpath(__file__)), "stories", name + ".json")
#==================================================================#
# Returns an array of dicts containing story files in /stories
#==================================================================#
@ -83,4 +91,22 @@ def getstoryfiles():
# Returns True if json file exists with requested save name
#==================================================================#
def saveexists(name):
return path.exists(path.dirname(path.realpath(__file__))+"/stories/"+name+".json")
return path.exists(storypath(name))
#==================================================================#
# Delete save file by name; returns None if successful, or the exception if not
#==================================================================#
def deletesave(name):
try:
os.remove(storypath(name))
except Exception as e:
return e
#==================================================================#
# Rename save file; returns None if successful, or the exception if not
#==================================================================#
def renamesave(name, new_name):
try:
os.replace(storypath(name), storypath(new_name))
except Exception as e:
return e