python-adfs

changeset 65:828d28f47e66

Added the ability to read time stamps. Updated the version number.
author David Boddie <david@boddie.org.uk>
date Sun Jun 08 21:46:34 2008 +0200
parents 2e2bd0a863db
children 715522effc0b
files ADFSlib.py
diffstat 1 files changed, 48 insertions(+), 8 deletions(-) [+]
line diff
     1.1 --- a/ADFSlib.py	Sun Jun 08 20:17:05 2008 +0200
     1.2 +++ b/ADFSlib.py	Sun Jun 08 21:46:34 2008 +0200
     1.3 @@ -25,16 +25,19 @@
     1.4  
     1.5  __author__ = "David Boddie <david@boddie.org.uk>"
     1.6  __date__ = "Sun 8th June 2008"
     1.7 -__version__ = "0.30"
     1.8 +__version__ = "0.31"
     1.9  
    1.10  
    1.11 -import os, string, struct
    1.12 +import os, string, struct, time
    1.13  
    1.14  
    1.15  INFORM = 0
    1.16  WARNING = 1
    1.17  ERROR = 2
    1.18  
    1.19 +# Find the number of centiseconds between 1900 and 1970.
    1.20 +between_epochs = ((365 * 70) + 17) * 24 * 360000L
    1.21 +
    1.22  
    1.23  class ADFS_exception(Exception):
    1.24  
    1.25 @@ -77,9 +80,31 @@
    1.26      
    1.27          return '<%s instance, "%s", at %x>' % (self.__class__, self.name, id(self))
    1.28      
    1.29 +    def has_filetype(self):
    1.30 +    
    1.31 +        return self.load_address & 0xfff00000 == 0xfff00000
    1.32 +    
    1.33      def filetype(self):
    1.34      
    1.35          return "%x" % ((self.load_address >> 8) & 0xfff)
    1.36 +    
    1.37 +    def time_stamp(self):
    1.38 +    
    1.39 +        # RISC OS time is given as a five byte block containing the
    1.40 +        # number of centiseconds since 1900 (presumably 1st January 1900).
    1.41 +        
    1.42 +        # Convert the time to the time elapsed since the Epoch (assuming
    1.43 +        # 1970 for this value).
    1.44 +        date_num = struct.unpack("<Q",
    1.45 +            struct.pack("<IBxxx", self.execution_address, self.load_address & 0xff))[0]
    1.46 +        
    1.47 +        centiseconds = date_num - between_epochs
    1.48 +        
    1.49 +        # Convert this to a value in seconds and return a time tuple.
    1.50 +        try:
    1.51 +            return time.localtime(centiseconds / 100.0)
    1.52 +        except ValueError:
    1.53 +            return ()
    1.54  
    1.55  
    1.56  class ADFSdisc:
    1.57 @@ -1399,12 +1424,27 @@
    1.58                  
    1.59                  else:
    1.60                  
    1.61 -                    # Load address treated as a filetype.
    1.62 -                    print string.expandtabs(
    1.63 -                        "%s.%s\t%s\t%X" % (
    1.64 -                            path, name, obj.filetype().upper(), obj.length
    1.65 -                            ), 16
    1.66 -                        )
    1.67 +                    # Load address treated as a filetype; load and execution
    1.68 +                    # addresses treated as a time stamp.
    1.69 +                    
    1.70 +                    time_stamp = obj.time_stamp()
    1.71 +                    if not time_stamp or not obj.has_filetype():
    1.72 +                    
    1.73 +                        print string.expandtabs(
    1.74 +                            "%s.%s\t%X\t%X\t%X" % (
    1.75 +                                path, name, obj.load_address,
    1.76 +                                obj.execution_address, obj.length
    1.77 +                                ), 16
    1.78 +                            )
    1.79 +                    else:
    1.80 +                    
    1.81 +                        time_stamp = time.strftime("%H:%M:%S, %a %m %b %Y", time_stamp)
    1.82 +                        print string.expandtabs(
    1.83 +                            "%s.%s\t%s\t%s\t%X" % (
    1.84 +                                path, name, obj.filetype().upper(), time_stamp,
    1.85 +                                obj.length
    1.86 +                                ), 16
    1.87 +                            )
    1.88              
    1.89              else:
    1.90