Backupbackend angepasst
Dateigrößen Backup Upload
This commit is contained in:
parent
0d5d977a1e
commit
681ad9d3fe
55
lib/admin.py
55
lib/admin.py
@ -626,6 +626,8 @@ Dies kann nicht rückgängig gemacht werden!''')
|
||||
output_dict["button_height"] = button_height_input.value
|
||||
output_dict["user_notes"] = notes_switch.value
|
||||
output_dict["holidays"] = data["holidays"]
|
||||
output_dict["version"] = app_version
|
||||
|
||||
json_dict = json.dumps(output_dict, indent=4)
|
||||
with open(os.path.join(scriptpath, usersettingsfilename), "w") as outputfile:
|
||||
outputfile.write(json_dict)
|
||||
@ -1248,32 +1250,40 @@ Dies kann nicht rückgängig gemacht werden!''')
|
||||
ui.markdown('**Backups**')
|
||||
|
||||
date_format = '%Y-%m-%d_%H-%M'
|
||||
searchpath = os.path.join(scriptpath, backupfolder)
|
||||
|
||||
@ui.refreshable
|
||||
def backup_list():
|
||||
if not os.path.isdir(os.path.join(scriptpath, backupfolder)):
|
||||
os.makedirs(os.path.join(scriptpath, backupfolder))
|
||||
|
||||
if not os.path.isdir(searchpath):
|
||||
os.makedirs(os.path.join(searchpath))
|
||||
|
||||
backup_files = []
|
||||
with ui.grid(columns='auto auto auto'):
|
||||
for file in os.listdir(os.path.join(scriptpath, backupfolder)):
|
||||
file_and_size = []
|
||||
with ui.grid(columns='auto auto auto auto auto'):
|
||||
|
||||
for file in os.listdir(searchpath):
|
||||
if file.endswith(".zip"):
|
||||
backup_files.append(file)
|
||||
file_and_size = [file, os.path.getsize(os.path.join(searchpath, file))]
|
||||
backup_files.append(file_and_size)
|
||||
backup_files.sort()
|
||||
backup_files.reverse()
|
||||
|
||||
if len(backup_files) == 0:
|
||||
ui.label("Keine Backups vorhanden")
|
||||
|
||||
for file in backup_files:
|
||||
for file, size in backup_files:
|
||||
date_string = file[0:-4]
|
||||
try:
|
||||
date_string_dt = datetime.datetime.strptime(date_string, date_format)
|
||||
button_string = date_string_dt.strftime('%d.%m.%Y - %H:%M')
|
||||
except ValueError:
|
||||
button_string = date_string
|
||||
ui.button(button_string,
|
||||
on_click=lambda file=date_string: ui.download.file(os.path.join(scriptpath, backupfolder, f'{file}.zip'))).tooltip("Backup herunterladen")
|
||||
ui.markdown(button_string)
|
||||
ui.markdown(f'{round(size/1_000_000,2)} MB')
|
||||
ui.button(icon='download', on_click=lambda file=date_string: ui.download.file(
|
||||
os.path.join(scriptpath, backupfolder, f'{file}.zip'))).tooltip(
|
||||
"Backup herunterladen")
|
||||
|
||||
def del_backup_dialog(file):
|
||||
def del_backup():
|
||||
@ -1320,7 +1330,8 @@ Dies kann nicht rückgängig gemacht werden!''')
|
||||
|
||||
ui.separator()
|
||||
|
||||
def make_backup():
|
||||
async def make_backup():
|
||||
n = ui.notification("Backup wird erzeugt...")
|
||||
compress = zipfile.ZIP_DEFLATED
|
||||
filename = os.path.join(scriptpath, backupfolder,
|
||||
datetime.datetime.now().strftime(date_format) + '.zip')
|
||||
@ -1332,9 +1343,35 @@ Dies kann nicht rückgängig gemacht werden!''')
|
||||
target.write(add)
|
||||
target.write(usersettingsfilename)
|
||||
backup_list.refresh()
|
||||
n.dismiss()
|
||||
ui.notify("Backup erstellt")
|
||||
|
||||
ui.button("Neues Backup erstellen", on_click=make_backup)
|
||||
|
||||
def handle_upload(e: events.UploadEventArguments):
|
||||
filename = e.name
|
||||
upload = True
|
||||
if os.path.exists(os.path.join(searchpath, filename )):
|
||||
with ui.dialog() as dialog, ui.card():
|
||||
ui.label("Datei mit diesem Namen existiert bereits. Die Datei kann nicht hochgeladen werden.")
|
||||
ui.button("OK", on_click=dialog.close)
|
||||
dialog.open()
|
||||
upload = False
|
||||
|
||||
if upload:
|
||||
|
||||
content = e.content.read()
|
||||
with open(os.path.join(searchpath, filename), 'wb') as output:
|
||||
output.write(content)
|
||||
ui.notify("Datei hochgeladen")
|
||||
backup_list.refresh()
|
||||
uploader.reset()
|
||||
|
||||
ui.separator()
|
||||
ui.label("Backup hochladen").classes('font-bold')
|
||||
ui.label(f"Stellen Sie sicher, dass Sie nur zur aktuellen Programmversion ({app_version}) Backups hochladen.")
|
||||
uploader = ui.upload(on_upload=handle_upload).props('accept=.zip')
|
||||
|
||||
# Alternativ zur Loginseite navigieren
|
||||
else:
|
||||
login = login_mask()
|
||||
|
Loading…
x
Reference in New Issue
Block a user