mirror of
https://github.com/KrisKennaway/pyapple2disk.git
synced 2024-11-29 14:50:00 +00:00
Add a utils.HexDump library
Be a bit more robust about dealing with data corruption
This commit is contained in:
parent
b97c404514
commit
b4ea155b24
@ -1,9 +1,7 @@
|
|||||||
import applesoft
|
import applesoft
|
||||||
import bitstring
|
import bitstring
|
||||||
import disk as disklib
|
import disk as disklib
|
||||||
import string
|
import utils
|
||||||
|
|
||||||
PRINTABLE = set(string.letters + string.digits + string.punctuation + ' ')
|
|
||||||
|
|
||||||
class FileType(object):
|
class FileType(object):
|
||||||
def __init__(self, short_type, long_type, parser=None):
|
def __init__(self, short_type, long_type, parser=None):
|
||||||
@ -227,7 +225,11 @@ class Dos33Disk(disklib.Disk):
|
|||||||
#print "XXX found a sparse sector?"
|
#print "XXX found a sparse sector?"
|
||||||
continue
|
continue
|
||||||
(t, s) = ts
|
(t, s) = ts
|
||||||
fds = FileDataSector.fromSector(self.ReadSector(t, s), entry.FileName())
|
try:
|
||||||
|
fds = FileDataSector.fromSector(self.ReadSector(t, s), entry.FileName())
|
||||||
|
except disklib.IOError, e:
|
||||||
|
print "%s: Failed to read File data sector: %s" % (entry, e)
|
||||||
|
continue
|
||||||
contents.append(fds.data)
|
contents.append(fds.data)
|
||||||
|
|
||||||
return File(entry, contents)
|
return File(entry, contents)
|
||||||
@ -276,8 +278,11 @@ class File(object):
|
|||||||
self.catalog_entry = catalog_entry
|
self.catalog_entry = catalog_entry
|
||||||
|
|
||||||
self.contents = contents
|
self.contents = contents
|
||||||
|
self.parsed_contents = None
|
||||||
parser = catalog_entry.file_type.parser
|
parser = catalog_entry.file_type.parser
|
||||||
if parser:
|
if parser:
|
||||||
self.parsed_contents = parser(contents)
|
try:
|
||||||
else:
|
self.parsed_contents = parser(contents)
|
||||||
self.parsed_contents = None
|
except Exception:
|
||||||
|
print "Failed to parse file %s" % self.catalog_entry
|
||||||
|
print utils.HexDump(contents.tobytes())
|
17
src/apple2disk/utils.py
Normal file
17
src/apple2disk/utils.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import string
|
||||||
|
|
||||||
|
PRINTABLE = set(string.letters + string.digits + string.punctuation + ' ')
|
||||||
|
|
||||||
|
def HexDump(data):
|
||||||
|
line = []
|
||||||
|
for idx, b in enumerate(data):
|
||||||
|
if idx % 8 == 0:
|
||||||
|
print '$%02x: ' % idx,
|
||||||
|
print "%02x" % ord(b),
|
||||||
|
if b in PRINTABLE:
|
||||||
|
line.append(b)
|
||||||
|
else:
|
||||||
|
line.append('.')
|
||||||
|
if (idx + 1) % 8 == 0:
|
||||||
|
print " %s" % ''.join(line)
|
||||||
|
line = []
|
Loading…
Reference in New Issue
Block a user