Added verbose_info property for segments allowing more descriptive text

This commit is contained in:
Rob McMullen 2016-03-04 23:52:05 -08:00
parent f2f36f11c5
commit d6fec961b8
2 changed files with 49 additions and 4 deletions

View File

@ -37,14 +37,18 @@ class AtariDosDirent(object):
self.parse_raw_dirent(image, bytes)
def __str__(self):
flags = self.summary()
return "File #%-2d (%s) %03d %-8s%-3s %03d" % (self.file_num, flags, self.starting_sector, self.filename, self.ext, self.num_sectors)
def summary(self):
output = "o" if self.opened_output else "."
dos2 = "2" if self.dos_2 else "."
mydos = "m" if self.mydos else "."
in_use = "u" if self.in_use else "."
deleted = "d" if self.deleted else "."
locked = "*" if self.locked else " "
flags = "%s%s%s%s%s%s %03d" % (output, dos2, mydos, in_use, deleted, locked, self.starting_sector)
return "File #%-2d (%s) %-8s%-3s %03d" % (self.file_num, flags, self.filename, self.ext, self.num_sectors)
flags = "%s%s%s%s%s%s" % (output, dos2, mydos, in_use, deleted, locked)
return flags
def parse_raw_dirent(self, image, bytes):
if bytes is None:
@ -291,7 +295,8 @@ class AtariDosDiskImage(DiskImageBase):
if last:
break
if len(byte_order) > 0:
segment = IndexedByteSegment(self.bytes, self.style, byte_order, name=dirent.get_filename())
name = "%s (%s) %ds@%d" % (dirent.get_filename(), dirent.summary(), dirent.num_sectors, dirent.starting_sector)
segment = IndexedByteSegment(self.bytes, self.style, byte_order, name=name)
else:
segment = EmptySegment(self.bytes, self.style, name=dirent.get_filename())
return segment

View File

@ -36,11 +36,18 @@ class DefaultSegment(object):
self._search_copy = None
def __str__(self):
s = "%s (%d bytes)" % (self.name, len(self))
s = "%s ($%x bytes)" % (self.name, len(self))
if self.error:
s += " " + self.error
return s
@property
def verbose_info(self):
s = "%s ($%x bytes)" % (self.name, len(self))
if self.error:
s += " error='%s'" % self.error
return s
def __len__(self):
return np.alen(self.data)
@ -190,6 +197,13 @@ class EmptySegment(DefaultSegment):
s += " " + self.error
return s
@property
def verbose_info(self):
s = "%s (empty file)" % (self.name, )
if self.error:
s += " error='%s'" % self.error
return s
def __len__(self):
return 0
@ -206,6 +220,14 @@ class ObjSegment(DefaultSegment):
if self.error:
s += " " + self.error
return s
@property
def verbose_info(self):
count = len(self)
s = "%s address range: $%04x-$%04x ($%04x bytes), file index of first byte: $%04x" % (self.name, self.start_addr, self.start_addr + count, count, self.data_start)
if self.error:
s += " error='%s'" % self.error
return s
class RawSectorsSegment(DefaultSegment):
@ -226,6 +248,17 @@ class RawSectorsSegment(DefaultSegment):
s += " " + self.error
return s
@property
def verbose_info(self):
if self.num_sectors > 1:
s = "%s (sectors %d-%d)" % (self.name, self.first_sector, self.first_sector + self.num_sectors - 1)
else:
s = "%s (sector %d)" % (self.name, self.first_sector)
s += " $%x bytes" % (len(self), )
if self.error:
s += " error='%s'" % self.error
return s
def label(self, index, lower_case=True):
boot_size = self.num_boot_sectors * self.boot_sector_size
if index >= boot_size:
@ -275,6 +308,13 @@ class IndexedByteSegment(DefaultSegment):
s += " " + self.error
return s
@property
def verbose_info(self):
s = "%s ($%04x bytes) non-contiguous file; file index of first byte: $%04x" % (self.name, len(self), self.order[0])
if self.error:
s += " error='%s'" % self.error
return s
def __len__(self):
return np.alen(self.order)