From ae3a12507b3f65670b4b17b1c6b479220b5469f7 Mon Sep 17 00:00:00 2001 From: "T. Joseph Carter" Date: Fri, 7 Jul 2017 08:07:20 -0700 Subject: [PATCH] Fix arg parsing, move arg processing to cppo Not quite finished with this, but the goal here is not have args being passed in to the legacy cppo at all. The g namespace is not ideal, but it does work and it isolates the legacy code from needing to understand what's going on in the shell level. So we'll take advantage of that for the time being. The bigger problem was that when I moved the arg parsing out of cppo, I failed to move all of it--a block that checked the number of args got lost. Restored. --- blocksfree/legacy.py | 24 ++++-------------------- cppo | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/blocksfree/legacy.py b/blocksfree/legacy.py index 82d479c..0d04a52 100755 --- a/blocksfree/legacy.py +++ b/blocksfree/legacy.py @@ -87,6 +87,7 @@ g.DIRPATH = "" g.target_name = None g.target_dir = "" g.appledouble_dir = None +g.image_file = None g.extract_file = None # runtime options @@ -1030,7 +1031,7 @@ def hexdump( def run_cppo(args: list): try: - disk = Disk(args[1]) + disk = Disk(g.image_file) except IOError as e: log.critical(e) quit_now(2) @@ -1051,24 +1052,6 @@ def run_cppo(args: list): "ShrinkIt archive.") quit_now(2) - if len(args) == 4: - g.extract_file = args[2] - - if g.extract_file: - targetPath = args[3] - if os.path.isdir(targetPath): - g.target_dir = targetPath - elif len(targetPath.rsplit("/", 1)) > 1: - g.target_dir, g.target_name = targetPath.rsplit("/", 1) - if not os.path.isdir(g.target_dir): - print("Target directory {} not found.".format(g.target_dir)) - quit_now(2) - else: - if not g.catalog_only: - if not os.path.isdir(args[2]): - print("Target directory not found.") - quit_now(2) - if g.src_shk: g.prodos_names = False if not g.catalog_only: @@ -1222,7 +1205,8 @@ def run_cppo(args: list): if (not g.src_shk and not g.dos33 and g.extract_file and (args[2][0] not in ('/', ':'))): log.critical("Cannot extract {} from {}: " - "ProDOS volume name required".format(args[2], args[1])) + "ProDOS volume name required".format( + g.extract_file, g.image_file)) quit_now(2) if g.dos33: diff --git a/cppo b/cppo index 8ab1b93..293391e 100755 --- a/cppo +++ b/cppo @@ -45,6 +45,7 @@ Wildcard matching (*) is not supported and images are not validated. ShrinkIt support requires Nulib2. cppo requires Python 2.6+ or 3.0+.""" import sys +import os from blocksfree.legacy import g import blocksfree.legacy @@ -98,6 +99,35 @@ def cppo(args: list): else: usage() + if g.use_appledouble and g.use_extended: + usage() + if g.catalog_only: + if len(args) != 2: + usage() + else: + if len(args) not in (3, 4): + usage() + + g.image_file = args[1] + + if len(args) == 4: + g.extract_file = args[2] + + if g.extract_file: + target_path = args[3] + if os.path.isdir(target_path): + g.target_dir = target_path + elif len(target_path.rsplit("/", 1)) > 1: + g.target_dir, g.target_name = target_path.rsplit("/", 1) + if not os.path.isdir(g.target_dir): + log.critical("Directory {} not found.".format(g.target_dir)) + sys.exit(2) + else: + if not g.catalog_only: + if not os.path.isdir(args[2]): + log.critical("Directory {} not found.".format(g.target_dir)) + sys.exit(2) + blocksfree.legacy.run_cppo(args) if __name__ == '__main__':