Next / Previous / Contents / Shipman's homepage

8.10. OldReport.__visitor(): Visitor function for os.path.walk()

Very similar to Section 7.10, “BigReport.__visitor(): Visitor function for os.path.walk().

oldfiles.py
# - - -   O l d R e p o r t . _ _ v i s i t o r   - - -

    def __visitor ( self, basePath, dirName, nameList ):
        """Visitor function for os.path.walk.

          [ (dirName is the name of a directory) and
            (nameList is a list of the names within that 
            directory) ->
              self.__oldList  :=  self.__oldList with BigInfo
                  objects added representing the accessible
                  ordinary files in nameList ]
        """

        #-- 1 --
        # [ self.__oldList  :=  self.__oldList with an OldInfo
        #       object added representing dirName ]
        try:
            dirInfo  =  OldInfo ( dirName, basePath )
            self.__oldList.append ( dirInfo )
        except OSError, detail:
            pass

        #-- 2 --
        for  fileName in nameList:
            #-- 2 body --
            # [ if fileName names an accessible regular file ->
            #     self.__oldList  :=  self.__oldList with a new
            #         OldInfo object representing fileName
            #   else -> I ]

            #-- 2.1 --
            # [ filePath  :=  dirName + fileName ]
            filePath  =  os.path.join ( dirName, fileName )

            #-- 2.2 --
            # [ if filePath is an accessible path to a regular file ->
            #     self.__oldList  :=  self.__oldList + (an OldInfo
            #         showing the status of filePath)
            #   else -> I ]
            try:
                oldInfo  =  OldInfo ( filePath, basePath )
                if  oldInfo.isFile():
                    self.__oldList.append ( oldInfo )
            except OSError, detail:
                pass