From 80653eab7cfdea3d0b9255ab2c0e984dbd488937 Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 1 Jun 2022 16:22:16 -0400 Subject: [PATCH] fix: added a check in cleanup.py to see if the assets folder exists before clearing it --- utils/cleanup.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/utils/cleanup.py b/utils/cleanup.py index c2f104f..ee3453b 100644 --- a/utils/cleanup.py +++ b/utils/cleanup.py @@ -1,20 +1,23 @@ import os +from os.path import exists def cleanup() -> int: - count = 0 - files = [f for f in os.listdir('.') if f.endswith('.mp4') and 'temp' in f.lower()] - count += len(files) - for f in files: - os.remove(f) - try: - for file in os.listdir('./assets/temp/mp4'): + if exists('./assets/temp'): + count = 0 + files = [f for f in os.listdir('.') if f.endswith('.mp4') and 'temp' in f.lower()] + count += len(files) + for f in files: + os.remove(f) + try: + for file in os.listdir('./assets/temp/mp4'): + count += 1 + os.remove('./assets/temp/mp4/' + file) + except FileNotFoundError: + pass + for file in os.listdir('./assets/temp/mp3'): count += 1 - os.remove('./assets/temp/mp4/' + file) - except FileNotFoundError: - pass - for file in os.listdir('./assets/temp/mp3'): - count += 1 - os.remove('./assets/temp/mp3/' + file) - return count + os.remove('./assets/temp/mp3/' + file) + return count + return 0