# Thanks to Chris Warrick for script installation tips # https://chriswarrick.com/blog/2014/09/15/python-apps-the-right-way-entry_points-and-scripts/ import argparse import sys import os from os import path import shutil from .slow_lzss import decompress from . import dispatcher def main(args=None): if args is None: args = sys.argv[1:] descriptions = { 'dump': '''Break a ROM file into rebuildable parts. Any OldWorld or NewWorld image can be processed. Because successive ROM formats tended to wrap layers around old ones, up to four layers can require 'unpeeling'.''', 'build': '''Recreate a dumped ROM file. With minor exceptions, the result should be identical to the original.''' } for key in list(descriptions): descriptions[key] = ' '.join(descriptions[key].split()) if not args or args[0] not in descriptions: print('usage: tbxi [...]') print() print('The Mac OS Toolbox Imager') print() print('commands:') for k, v in descriptions.items(): print(' ' + k.ljust(8) + ' ' + v.partition('.')[0]) exit(1) command = args.pop(0) parser = argparse.ArgumentParser(prog='tbxi ' + command, description=descriptions[command]) if command == 'dump': parser.add_argument('file', metavar='', help='original file (dest: .src') parser.add_argument('-o', dest='output', metavar='', help='destination (default: .src)') args = parser.parse_args(args) if not args.output: args.output = args.file + '.src' with open(args.file, 'rb') as f: try: shutil.rmtree(args.output) except FileNotFoundError: pass dispatcher.dump(f.read(), args.output, toplevel=True) elif command == 'build': parser.add_argument('dir', metavar='', help='source directory') parser.add_argument('-o', dest='output', metavar='', help='destination (default: .build)') args = parser.parse_args(args) with open(args.output, 'wb') as f: f.write(dispatcher.build_path(args.dir)) if __name__ == "__main__": main()