Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Function
- # Analyzes MSU Pack
- # Creates MSU manifest if necessary (zero-length file, appropriately named, based on PCM files)
- # Creates a .txt with the original filename of the game file
- # Renames the game file to match the PCM files
- # Usage
- # Place game file (*.sfc, *.smc) into MSU Pack folder
- # py msu.py --dir="path\to\MSU Pack"
- from argparse import ArgumentParser # get argument parser for commandline
- import os # for file manipulation
- # process arguments from commandline
- def process_command_line_args():
- parser = ArgumentParser()
- # give directory where MSU pack resides
- parser.add_argument("--dir",
- dest="dir",
- help="Directory where MSU pack resides",
- metavar="<dir>",
- default="."
- )
- command_line_args = vars(parser.parse_args())
- return command_line_args
- # do the thing
- def process_msu(dir):
- msu_root = "" # keep track of MSU slug
- msu_found = False # keep track if we found an MSU Manifest
- print("Processing MSU in dir: " + dir)
- # walk through the MSU & PCM files
- for _,_,f in os.walk(os.path.join(dir)):
- for file in f:
- if os.path.exists(os.path.join(dir,file)):
- filename,file_extension = os.path.splitext(file)
- # if this is a .msu, this is our MSU Manifest
- if file_extension.lower() == ".msu":
- msu_root = filename
- msu_found = True
- print("Found an MSU Manifest! Using this as Manifest name instead of any PCMs.")
- # if we don't have a slug yet, keep looking by searching the PCM files
- if msu_root == "":
- if file_extension.lower() == ".pcm":
- filenameParts = filename.split('-')
- filenameParts.pop()
- msu_root = '-'.join(filenameParts)
- print("Found a PCM! Using this as Manifest name.")
- # if we got a slug from the PCMs but we never found an MSU Manifest, make one
- if not msu_root == "":
- if not msu_found:
- print("Didn't find an MSU Manifest! Making one!")
- manifest = open(os.path.join(dir,msu_root + ".msu"),"w")
- manifest.write("")
- manifest.close()
- # walk through the game files
- for _,_,f in os.walk(os.path.join(dir)):
- for file in f:
- if os.path.exists(os.path.join(dir,file)):
- filename,file_extension = os.path.splitext(file)
- # if this is a game file
- if file_extension.lower() in [ ".sfc", ".smc" ]:
- # if we need to rename it
- if not filename == msu_root:
- # make a note
- note = open(os.path.join(dir,filename + ".txt"),"w")
- note.write("")
- note.close()
- src = os.path.join(dir,file)
- dest = os.path.join(dir,msu_root + file_extension)
- print("Found game file: " + src)
- print("Renaming note to: " + os.path.join(dir,filename) + ".txt")
- print("Renaming game file to: " + dest)
- # rename the game file
- os.rename(src,dest)
- else:
- # else, it already matches, bail and do nothing
- print("Game file found with MSU pack already! Aborting!")
- exit(1)
- else:
- # else, we couldn't find anything useful
- print("Failed to find an MSU pack!")
- def main():
- command_line_args = process_command_line_args()
- if not command_line_args["dir"]:
- command_line_args["dir"] = "."
- process_msu(command_line_args["dir"])
- #main
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment