From d6fec961b84bbd06ce6919ec5f2f833d3bd9ea19 Mon Sep 17 00:00:00 2001 From: Rob McMullen Date: Fri, 4 Mar 2016 23:52:05 -0800 Subject: [PATCH] Added verbose_info property for segments allowing more descriptive text --- atrcopy/ataridos.py | 11 ++++++++--- atrcopy/segments.py | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/atrcopy/ataridos.py b/atrcopy/ataridos.py index 1907d48..0ec0d5a 100755 --- a/atrcopy/ataridos.py +++ b/atrcopy/ataridos.py @@ -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 diff --git a/atrcopy/segments.py b/atrcopy/segments.py index 82d345f..ea6c3c0 100755 --- a/atrcopy/segments.py +++ b/atrcopy/segments.py @@ -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)