Added extra verbosity to show parsing error

This commit is contained in:
Rob McMullen 2016-10-01 18:42:39 -07:00
parent 7e51284cb1
commit 3a988495e8
3 changed files with 14 additions and 9 deletions

View File

@ -78,7 +78,7 @@ def run():
for mime in mime_parse_order: for mime in mime_parse_order:
if options.verbose: if options.verbose:
print "Trying MIME type %s" % mime print "Trying MIME type %s" % mime
parser = guess_parser_for_mime(mime, rawdata) parser = guess_parser_for_mime(mime, rawdata, options.verbose)
if parser is None: if parser is None:
continue continue
if options.verbose: if options.verbose:

View File

@ -179,14 +179,14 @@ class AtariDosFile(object):
first = False first = False
continue continue
elif first: elif first:
raise InvalidBinaryFile raise InvalidBinaryFile("Object file doesn't start with 0xffff")
log.debug("header parsing: header=0x%x" % header) log.debug("header parsing: header=0x%x" % header)
if len(b[pos:pos + 4]) < 4: if len(b[pos:pos + 4]) < 4:
self.segments.append(ObjSegment(r[pos:pos + 4], 0, 0, 0, len(b[pos:pos + 4]), "Short Segment Header")) self.segments.append(ObjSegment(r[pos:pos + 4], 0, 0, 0, len(b[pos:pos + 4]), "Short Segment Header"))
break break
start, end = b[pos:pos + 4].view(dtype='<u2') start, end = b[pos:pos + 4].view(dtype='<u2')
if end < start: if end < start:
raise InvalidBinaryFile raise InvalidBinaryFile("Nonsensical start and end addresses")
count = end - start + 1 count = end - start + 1
found = len(b[pos + 4:pos + 4 + count]) found = len(b[pos + 4:pos + 4 + count])
if found < count: if found < count:

View File

@ -10,6 +10,9 @@ from mame import MameZipImage
from dos33 import Dos33DiskImage, ProdosDiskImage from dos33 import Dos33DiskImage, ProdosDiskImage
from errors import * from errors import *
import logging
log = logging.getLogger(__name__)
class SegmentParser(object): class SegmentParser(object):
menu_name = "" menu_name = ""
@ -27,8 +30,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 AtrError: except AtrError, e:
raise InvalidSegmentParser raise InvalidSegmentParser(e)
self.segments.extend(self.image.segments) self.segments.extend(self.image.segments)
def get_image(self, r): def get_image(self, r):
@ -38,8 +41,8 @@ class SegmentParser(object):
if self.strict: if self.strict:
try: try:
self.image.strict_check() self.image.strict_check()
except AtrError: except AtrError, e:
raise InvalidSegmentParser raise InvalidSegmentParser(e)
else: else:
self.image.relaxed_check() self.image.relaxed_check()
@ -101,14 +104,16 @@ class ProdosSegmentParser(SegmentParser):
image_type = ProdosDiskImage image_type = ProdosDiskImage
def guess_parser_for_mime(mime, r): def guess_parser_for_mime(mime, r, verbose=False):
parsers = mime_parsers[mime] parsers = mime_parsers[mime]
found = None found = None
for parser in parsers: for parser in parsers:
try: try:
found = parser(r, True) found = parser(r, True)
break break
except InvalidSegmentParser: except InvalidSegmentParser, e:
if verbose:
log.info("parser isn't %s: %s" % (parser.__name__, str(e)))
pass pass
return found return found