Add menus for saving presets/characters/instruction templates/prompts (#2621)
This commit is contained in:
parent
ea0eabd266
commit
6133675e0f
5 changed files with 220 additions and 98 deletions
|
@ -3,6 +3,42 @@ import re
|
|||
from pathlib import Path
|
||||
|
||||
from modules import shared
|
||||
from modules.logging_colors import logger
|
||||
|
||||
|
||||
def save_file(fname, contents):
|
||||
if fname == '':
|
||||
logger.error('File name is empty!')
|
||||
return
|
||||
|
||||
root_folder = Path(__file__).resolve().parent.parent
|
||||
abs_path = Path(fname).resolve()
|
||||
rel_path = abs_path.relative_to(root_folder)
|
||||
if rel_path.parts[0] == '..':
|
||||
logger.error(f'Invalid file path: {fname}')
|
||||
return
|
||||
|
||||
with open(abs_path, 'w', encoding='utf-8') as f:
|
||||
f.write(contents)
|
||||
|
||||
logger.info(f'Saved {abs_path}.')
|
||||
|
||||
|
||||
def delete_file(fname):
|
||||
if fname == '':
|
||||
logger.error('File name is empty!')
|
||||
return
|
||||
|
||||
root_folder = Path(__file__).resolve().parent.parent
|
||||
abs_path = Path(fname).resolve()
|
||||
rel_path = abs_path.relative_to(root_folder)
|
||||
if rel_path.parts[0] == '..':
|
||||
logger.error(f'Invalid file path: {fname}')
|
||||
return
|
||||
|
||||
if abs_path.exists():
|
||||
abs_path.unlink()
|
||||
logger.info(f'Deleted {fname}.')
|
||||
|
||||
|
||||
def atoi(text):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue