Next / Previous / Contents / Shipman's homepage

8.7. OldInfo.__str__(): String conversion method

This method is completely identical to the corresponding method in the bigfiles.py script; see Section 7.7, “BigInfo.__str__(): String conversion method”.

oldfiles.py
# - - -   O l d I n f o . _ _ s t r _ _   - - -

    def __str__ ( self ):
        """Format an OldInfo object for printing."""

        #-- 1 --
        # [ if self represents a directory ->
        #     suffix  :=  "/"
        #   else ->
        #     suffix  :=  "" ]
        if  self.isDir():  suffix  =  "/"
        else:              suffix  =  ""

        #-- 2 --
        # [ self.__basePath is the absolute path of a directory
        #   above self.path ->
        #     relPath  :=  path to self.path relative to
        #                  self.__basePath ]
        absPath  =  os.path.abspath ( self.path )
        relPath  =  absPath [ len(self.__basePath) + 1 : ]

        #-- 3 --
        if  relPath == "":
            relPath  =  "."
            suffix   =  ""

        #-- 4 --
        return ( "%s %10s %s%s" %
                 (self.modTime(), self.size, relPath, suffix) )