From 3de95e30d878a7a204436c2f1358a7a207727c92 Mon Sep 17 00:00:00 2001 From: Torrin Leonard <82110564+torrinworx@users.noreply.github.com> Date: Sun, 17 Apr 2022 18:20:35 -0400 Subject: [PATCH] Adding file sorting method to Constants.py --- main/Checks.py | 6 ++---- main/Constants.py | 20 +++++++++++++++++++- main/DNA_Generator.py | 2 +- main/Exporter.py | 11 +---------- main/Refactorer.py | 7 +++---- 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/main/Checks.py b/main/Checks.py index 2f2434c..a3ac781 100644 --- a/main/Checks.py +++ b/main/Checks.py @@ -12,7 +12,7 @@ import json from collections import Counter, defaultdict from . import DNA_Generator, get_combinations -from .Constants import bcolors, removeList +from .Constants import bcolors, removeList, remove_file_by_extension # Checks: @@ -130,9 +130,7 @@ def check_FailedBatches(batch_json_save_path): failed_dna_index = None if os.path.isdir(batch_json_save_path): - batch_folders = os.listdir(batch_json_save_path) - - batch_folders = [x for x in batch_folders if (x not in removeList)] + batch_folders = remove_file_by_extension(os.listdir(batch_json_save_path)) for i in batch_folders: batch = json.load(open(os.path.join(batch_json_save_path, i))) diff --git a/main/Constants.py b/main/Constants.py index 1314d23..c88edef 100644 --- a/main/Constants.py +++ b/main/Constants.py @@ -1,7 +1,25 @@ # Purpose: # This file is for storing or updating constant values that may need to be changes depending on system requirements and # different usecases. -removeList = [".gitignore", ".DS_Store", "desktop.ini"] +import os + + +removeList = [".gitignore", ".DS_Store", "desktop.ini", ".ini"] + +def remove_file_by_extension(dirlist): + """ + Checks if a given directory list contains any of the files or file extensions listed above, if so, remove them from + list and return a clean dir list. These files interfer with BMNFTs operations and should be removed whenever dealing + with directories. + """ + + return_dirs = [] + for directory in dirlist: + if not str(os.path.splitext(directory)[1]) in removeList: + return_dirs.append(directory) + + return return_dirs + class bcolors: """ diff --git a/main/DNA_Generator.py b/main/DNA_Generator.py index b467c3e..7833841 100644 --- a/main/DNA_Generator.py +++ b/main/DNA_Generator.py @@ -11,7 +11,7 @@ import random from functools import partial from .loading_animation import Loader from . import Rarity, Logic, Checks -from .Constants import bcolors, removeList +from .Constants import bcolors, removeList, remove_file_by_extension def get_hierarchy(): diff --git a/main/Exporter.py b/main/Exporter.py index c4acd27..7dc636f 100644 --- a/main/Exporter.py +++ b/main/Exporter.py @@ -8,16 +8,7 @@ import time import json import datetime from .loading_animation import Loader - - -class bcolors: - """ - The colour of console messages. - """ - OK = '\033[92m' # GREEN - WARNING = '\033[93m' # YELLOW - ERROR = '\033[91m' # RED - RESET = '\033[0m' # RESET COLOR +from .Constants import bcolors, removeList, remove_file_by_extension # Save info diff --git a/main/Refactorer.py b/main/Refactorer.py index 9239da8..fad9015 100644 --- a/main/Refactorer.py +++ b/main/Refactorer.py @@ -8,7 +8,7 @@ import json import shutil from . import Metadata -from .Constants import bcolors, removeList +from .Constants import bcolors, removeList, remove_file_by_extension def getNFType(nftBatch_save_path): @@ -17,9 +17,8 @@ def getNFType(nftBatch_save_path): models = False metaData = False - batch1 = [x for x in os.listdir(nftBatch_save_path) if (x not in removeList)][0] # Gets first Batch and ignores removeList files - batchContent = os.listdir(os.path.join(nftBatch_save_path, batch1)) - batchContent = [x for x in batchContent if (x not in removeList)] + batch1 = sorted(remove_file_by_extension(os.listdir(nftBatch_save_path)))[0] + batchContent = remove_file_by_extension(os.listdir(os.path.join(nftBatch_save_path, batch1))) if "Images" in batchContent: images = True