From 63f62a7347f4fd9e9173ca721d0bff368bc6c333 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= Date: Mon, 20 Jul 2020 15:12:27 +0200 Subject: [PATCH] Minor code cleanup --- CB/Core.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/CB/Core.py b/CB/Core.py index 52fb5cc..66b8299 100644 --- a/CB/Core.py +++ b/CB/Core.py @@ -350,10 +350,9 @@ def backup_toggle(self): def backup_check(self): if self.config['Backup']['Enabled']: if not os.path.isfile(Path('WTF-Backup', f'{datetime.datetime.now().strftime("%d%m%y")}.zip')): - listofbackups = glob.glob('WTF-Backup/*.zip') - fullpath = [Path(x) for x in listofbackups] - if len([name for name in listofbackups]) == self.config['Backup']['Number']: - oldest_file = min(fullpath, key=os.path.getctime) + listofbackups = [Path(x) for x in glob.glob('WTF-Backup/*.zip')] + if len(listofbackups) == self.config['Backup']['Number']: + oldest_file = min(listofbackups, key=os.path.getctime) os.remove(oldest_file) return True else: @@ -365,17 +364,15 @@ def backup_wtf(self, console): zipf = zipfile.ZipFile(Path('WTF-Backup', f'{datetime.datetime.now().strftime("%d%m%y")}.zip'), 'w', zipfile.ZIP_DEFLATED) filecount = 0 - for root, dirs, files in os.walk('WTF/', topdown=True): + for _, _, files in os.walk('WTF/', topdown=True): files = [f for f in files if not f[0] == '.'] - dirs[:] = [d for d in dirs if not d[0] == '.'] filecount += len(files) with Progress('{task.completed}/{task.total}', '|', BarColumn(bar_width=None), '|', auto_refresh=False, console=console) as progress: task = progress.add_task('', total=filecount) while not progress.finished: - for root, dirs, files in os.walk('WTF/', topdown=True): + for root, _, files in os.walk('WTF/', topdown=True): files = [f for f in files if not f[0] == '.'] - dirs[:] = [d for d in dirs if not d[0] == '.'] for f in files: zipf.write(Path(root, f)) progress.update(task, advance=1, refresh=True)