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,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:

View File

@ -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")

View File

@ -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):

View File

@ -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)