From 8a6d7deb244bb2db244ee373522f44e05860a7a5 Mon Sep 17 00:00:00 2001 From: Timothy GFO Date: Thu, 2 Nov 2023 00:11:01 -0400 Subject: [PATCH] Updated to use os.path.join for os cross compatibility. now it should work on windows. --- mmm-nsf-changer.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/mmm-nsf-changer.py b/mmm-nsf-changer.py index f69a52b..fc48edf 100644 --- a/mmm-nsf-changer.py +++ b/mmm-nsf-changer.py @@ -26,12 +26,14 @@ def safelist(): def check_folder_structure(megamaker_folder, og_music=False): megamaker_folder = os.path.abspath(megamaker_folder) subfolders = ([ f.path for f in os.scandir(megamaker_folder) if f.is_dir() ]) - music_folder = f"{megamaker_folder}/Music" + music_folder = os.path.join(megamaker_folder, "Music") if og_music: - music_folder = f"{megamaker_folder}/original_music" + music_folder = os.path.join(megamaker_folder, "original_music") file_names = [] if music_folder in subfolders: - file_paths = (glob(f"{music_folder}/*/*.nsf")) + glob_search = os.path.join(music_folder,"*","*.nsf") + file_paths = (glob(glob_search)) + print(file_paths) for files in file_paths: file_names.append(os.path.basename(files)) print(file_names == safelist()) @@ -46,13 +48,13 @@ def move_music_to_ogmusic(path): path = os.path.abspath(path) original_filepaths = check_folder_structure(path) if original_filepaths: - if not filecmp.cmp(f'{path}/Music/MM1/Cutman.nsf', f'{path}/Music/MM1/Oilman.nsf', shallow=False): - shutil.move(f"{path}/Music", f"{path}/original_music") + if not filecmp.cmp(os.path.join(path,"Music","MM1","Cutman.nsf"), os.path.join(path, "Music", "MM1", "Oilman.nsf"), shallow=False): + shutil.move(os.path.join(path, "Music"), os.path.join(path, "original_music") else: print("Cutman.nsf and Oilman.nsf match in Music folder.") return False - if not os.path.exists(f"{path}/Music"): - os.makedirs(f"{path}/Music") + if not os.path.exists(os.path.join(path, "Music"): + os.makedirs(os.path.join(path, "Music") def recreate_structure(new_nsf, original_paths_list): for path in original_paths_list: @@ -62,13 +64,13 @@ def recreate_structure(new_nsf, original_paths_list): #check if the contents of files in original_music != the files in music AND check if contents of input nsf == every file in music. if all of that is true replace music with original_music def restore_ogmusic(path): - if os.path.exists(f"{path}/original_music"): - if os.path.exists(f'{path}/Music'): - if check_folder_structure(f"{path}"): - if check_folder_structure(f"{path}", og_music=True): - if not filecmp.cmp(f'{path}/Music/MM1/Cutman.nsf', f'{path}/original_music/MM1/Cutman.nsf', shallow=False): - shutil.rmtree(f"{path}/Music") - shutil.move(f"{path}/original_music/", f"{path}/Music") + if os.path.exists(os.path.join(path, "original_music"): + if os.path.exists(os.path.join(path, 'Music'): + if check_folder_structure(path): + if check_folder_structure(path, og_music=True): + if not filecmp.cmp(os.path.join(path, "Music", "MM1", 'Cutman.nsf', os.path.join(path, "original_music", "MM1", "Cutman.nsf", shallow=False): + shutil.rmtree(os.path.join(path, "Music") + shutil.move(os.path.join(path, "original_music", ""), os.path.join(path, "Music") return True else: print("something went wrong...")