Added UnsupportedDiskImage error to show that the disk has a known format but it's not able to be parsed

This commit is contained in:
Rob McMullen 2017-03-07 10:43:46 -08:00
parent e38b94fc0c
commit 5f9acaa802
4 changed files with 59 additions and 19 deletions

View File

@ -46,6 +46,7 @@ def process(image, dirent, options):
print dirent print dirent
def find_diskimage(filename): def find_diskimage(filename):
try:
with open(filename, "rb") as fh: with open(filename, "rb") as fh:
if options.verbose: if options.verbose:
print "Loading file %s" % filename print "Loading file %s" % filename
@ -63,6 +64,10 @@ def find_diskimage(filename):
break break
if parser is None: if parser is None:
print "%s: Unknown disk image type" % filename print "%s: Unknown disk image type" % filename
except UnsupportedDiskImage, e:
print "%s: %s" % (filename, e)
return None
else:
parser.image.filename = filename parser.image.filename = filename
parser.image.ext = "" parser.image.ext = ""
return parser return parser
@ -219,7 +224,19 @@ def run():
if options.all and file_list: if options.all and file_list:
raise AtrError("Specifying a list of files and --all doesn't make sense.") raise AtrError("Specifying a list of files and --all doesn't make sense.")
image_files = []
for filename in options.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) parser = find_diskimage(filename)
if parser and parser.image: if parser and parser.image:
if options.all: if options.all:

View File

@ -602,4 +602,13 @@ class ProdosDiskImage(DiskImageBase):
if prodos == "PRODOS": if prodos == "PRODOS":
swap_order = True swap_order = True
else: 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")

View File

@ -8,6 +8,18 @@ class InvalidCartHeader(AtrError):
pass pass
class InvalidDiskImage(AtrError): 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 pass
class InvalidDirent(AtrError): class InvalidDirent(AtrError):

View File

@ -29,6 +29,8 @@ class SegmentParser(object):
self.image = self.get_image(r) self.image = self.get_image(r)
self.check_image() self.check_image()
self.image.parse_segments() self.image.parse_segments()
except UnsupportedDiskImage:
raise
except AtrError, e: except AtrError, e:
raise InvalidSegmentParser(e) raise InvalidSegmentParser(e)
self.segments.extend(self.image.segments) self.segments.extend(self.image.segments)