Updated to use os.path.join for os cross compatibility. now it should work on windows.

This commit is contained in:
Timothy GFO 2023-11-02 00:11:01 -04:00
parent f4bd81bf7b
commit 8a6d7deb24

View file

@ -26,12 +26,14 @@ def safelist():
def check_folder_structure(megamaker_folder, og_music=False): def check_folder_structure(megamaker_folder, og_music=False):
megamaker_folder = os.path.abspath(megamaker_folder) megamaker_folder = os.path.abspath(megamaker_folder)
subfolders = ([ f.path for f in os.scandir(megamaker_folder) if f.is_dir() ]) 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: if og_music:
music_folder = f"{megamaker_folder}/original_music" music_folder = os.path.join(megamaker_folder, "original_music")
file_names = [] file_names = []
if music_folder in subfolders: 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: for files in file_paths:
file_names.append(os.path.basename(files)) file_names.append(os.path.basename(files))
print(file_names == safelist()) print(file_names == safelist())
@ -46,13 +48,13 @@ def move_music_to_ogmusic(path):
path = os.path.abspath(path) path = os.path.abspath(path)
original_filepaths = check_folder_structure(path) original_filepaths = check_folder_structure(path)
if original_filepaths: if original_filepaths:
if not filecmp.cmp(f'{path}/Music/MM1/Cutman.nsf', f'{path}/Music/MM1/Oilman.nsf', shallow=False): if not filecmp.cmp(os.path.join(path,"Music","MM1","Cutman.nsf"), os.path.join(path, "Music", "MM1", "Oilman.nsf"), shallow=False):
shutil.move(f"{path}/Music", f"{path}/original_music") shutil.move(os.path.join(path, "Music"), os.path.join(path, "original_music")
else: else:
print("Cutman.nsf and Oilman.nsf match in Music folder.") print("Cutman.nsf and Oilman.nsf match in Music folder.")
return False return False
if not os.path.exists(f"{path}/Music"): if not os.path.exists(os.path.join(path, "Music"):
os.makedirs(f"{path}/Music") os.makedirs(os.path.join(path, "Music")
def recreate_structure(new_nsf, original_paths_list): def recreate_structure(new_nsf, original_paths_list):
for path in 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 #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): def restore_ogmusic(path):
if os.path.exists(f"{path}/original_music"): if os.path.exists(os.path.join(path, "original_music"):
if os.path.exists(f'{path}/Music'): if os.path.exists(os.path.join(path, 'Music'):
if check_folder_structure(f"{path}"): if check_folder_structure(path):
if check_folder_structure(f"{path}", og_music=True): if check_folder_structure(path, og_music=True):
if not filecmp.cmp(f'{path}/Music/MM1/Cutman.nsf', f'{path}/original_music/MM1/Cutman.nsf', shallow=False): 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(f"{path}/Music") shutil.rmtree(os.path.join(path, "Music")
shutil.move(f"{path}/original_music/", f"{path}/Music") shutil.move(os.path.join(path, "original_music", ""), os.path.join(path, "Music")
return True return True
else: else:
print("something went wrong...") print("something went wrong...")