From 5f9acaa802df43bae6e8686edf7d807031aeee58 Mon Sep 17 00:00:00 2001 From: Rob McMullen Date: Tue, 7 Mar 2017 10:43:46 -0800 Subject: [PATCH] Added UnsupportedDiskImage error to show that the disk has a known format but it's not able to be parsed --- atrcopy/__init__.py | 53 ++++++++++++++++++++++++++++++--------------- atrcopy/dos33.py | 11 +++++++++- atrcopy/errors.py | 12 ++++++++++ atrcopy/parsers.py | 2 ++ 4 files changed, 59 insertions(+), 19 deletions(-) diff --git a/atrcopy/__init__.py b/atrcopy/__init__.py index 5d0c35f..677fa2c 100644 --- a/atrcopy/__init__.py +++ b/atrcopy/__init__.py @@ -46,26 +46,31 @@ def process(image, dirent, options): print dirent def find_diskimage(filename): - with open(filename, "rb") as fh: - if options.verbose: - print "Loading file %s" % filename - rawdata = SegmentData(fh.read()) - parser = None - for mime in mime_parse_order: + try: + with open(filename, "rb") as fh: if options.verbose: - print "Trying MIME type %s" % mime - parser = guess_parser_for_mime(mime, rawdata, options.verbose) + print "Loading file %s" % filename + rawdata = SegmentData(fh.read()) + parser = None + for mime in mime_parse_order: + if options.verbose: + print "Trying MIME type %s" % mime + parser = guess_parser_for_mime(mime, rawdata, options.verbose) + if parser is None: + continue + if options.verbose: + print "Found parser %s" % parser.menu_name + print "%s: %s" % (filename, parser.image) + break if parser is None: - continue - if options.verbose: - print "Found parser %s" % parser.menu_name - print "%s: %s" % (filename, parser.image) - break - if parser is None: - print "%s: Unknown disk image type" % filename - parser.image.filename = filename - parser.image.ext = "" - return parser + print "%s: Unknown disk image type" % filename + except UnsupportedDiskImage, e: + print "%s: %s" % (filename, e) + return None + else: + parser.image.filename = filename + parser.image.ext = "" + return parser def extract_files(image, files): for name in files: @@ -219,7 +224,19 @@ def run(): if options.all and file_list: raise AtrError("Specifying a list of files and --all doesn't make sense.") + image_files = [] for filename in options.files: + if filename == "-": + import fileinput + + for line in fileinput.input(["-"]): + line = line.rstrip() + print "-->%s<--" % line + image_files.append(line) + else: + image_files.append(filename) + + for filename in image_files: parser = find_diskimage(filename) if parser and parser.image: if options.all: diff --git a/atrcopy/dos33.py b/atrcopy/dos33.py index 13a59bd..1626e2b 100644 --- a/atrcopy/dos33.py +++ b/atrcopy/dos33.py @@ -602,4 +602,13 @@ class ProdosDiskImage(DiskImageBase): if prodos == "PRODOS": swap_order = True else: - raise InvalidDiskImage("No ProDOS header info found") + # FIXME: this doesn't seem to be the only way to identify a + # PRODOS disk. I have example images where PRODOS occurs at + # 0x21 - 0x27 in t0s14 and 0x11 - 0x16 in t0s01. Using 3 - + # 9 as magic bytes was from the cppo script from + # https://github.com/RasppleII/a2server but it seems that + # more magic bytes might be acceptable? + + #raise InvalidDiskImage("No ProDOS header info found") + pass + raise UnsupportedDiskImage("ProDOS format found but not supported") diff --git a/atrcopy/errors.py b/atrcopy/errors.py index 9e679b2..72f4b00 100644 --- a/atrcopy/errors.py +++ b/atrcopy/errors.py @@ -8,6 +8,18 @@ class InvalidCartHeader(AtrError): pass class InvalidDiskImage(AtrError): + """ Disk image is not recognized by a parser. + + Usually a signal to try the next parser; this error doesn't propagate out + to the user much. + """ + pass + +class UnsupportedDiskImage(AtrError): + """ Disk image is recognized by a parser but it isn't supported yet. + + This error does propagate out to the user. + """ pass class InvalidDirent(AtrError): diff --git a/atrcopy/parsers.py b/atrcopy/parsers.py index f347d66..3f5bd82 100644 --- a/atrcopy/parsers.py +++ b/atrcopy/parsers.py @@ -29,6 +29,8 @@ class SegmentParser(object): self.image = self.get_image(r) self.check_image() self.image.parse_segments() + except UnsupportedDiskImage: + raise except AtrError, e: raise InvalidSegmentParser(e) self.segments.extend(self.image.segments)