From b7781d27c3176376be0583087ddeffc74bc18b3f Mon Sep 17 00:00:00 2001 From: krateng Date: Mon, 4 Apr 2022 18:30:51 +0200 Subject: [PATCH] Aligned export and backup --- maloja/proccontrol/tasks/backup.py | 16 ++++++++-------- maloja/proccontrol/tasks/export.py | 11 +++++++++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/maloja/proccontrol/tasks/backup.py b/maloja/proccontrol/tasks/backup.py index a1c6819..73f797b 100644 --- a/maloja/proccontrol/tasks/backup.py +++ b/maloja/proccontrol/tasks/backup.py @@ -1,5 +1,5 @@ import tarfile -from datetime import datetime +import time import glob import os from ...globalconf import dir_settings @@ -36,16 +36,16 @@ def backup(targetfolder=None,include_images=False): log("Creating backup...") - now = datetime.utcnow() - timestr = now.strftime("%Y_%m_%d_%H_%M_%S") + timestr = time.strftime("%Y_%m_%d_%H_%M_%S") filename = f"maloja_backup_{timestr}.tar.gz" - archivefile = os.path.join(targetfolder,filename) - assert not os.path.exists(archivefile) - with tarfile.open(name=archivefile,mode="x:gz") as archive: + outputfile = os.path.join(targetfolder,filename) + assert not os.path.exists(outputfile) + + with tarfile.open(name=outputfile,mode="x:gz") as archive: for category, filelist in real_files.items(): for f in filelist: p = PurePath(f) r = p.relative_to(dir_settings[category]) archive.add(f,arcname=os.path.join(category,r)) - log("Backup created: " + col['yellow'](archivefile)) - return archivefile + log("Backup created: " + col['yellow'](outputfile)) + return outputfile diff --git a/maloja/proccontrol/tasks/export.py b/maloja/proccontrol/tasks/export.py index f4cf700..e6edcf5 100644 --- a/maloja/proccontrol/tasks/export.py +++ b/maloja/proccontrol/tasks/export.py @@ -6,12 +6,19 @@ from doreah.io import col from ...database.sqldb import get_scrobbles -def export(targetfolder="."): +def export(targetfolder=None): - outputfile = os.path.join(targetfolder,f"maloja_export_{time.strftime('%Y%m%d')}.json") + if targetfolder is None: + targetfolder = os.getcwd() + + timestr = time.strftime("%Y_%m_%d_%H_%M_%S") + filename = f"maloja_export_{timestr}.json" + outputfile = os.path.join(targetfolder,filename) + assert not os.path.exists(outputfile) data = {'scrobbles':get_scrobbles()} with open(outputfile,'w') as outfd: json.dump(data,outfd,indent=3) print(f"Exported {len(data['scrobbles'])} Scrobbles to {col['yellow'](outputfile)}") + return outputfile