Next / Previous / Contents / Shipman's homepage

9.5. LinkReport.__init__(): Constructor

The constructor starts by initializing self.__linkList as an empty list.

softlinks.py
# - - -   L i n k R e p o r t . _ _ i n i t _ _   - - -

    def __init__ ( self, dir ):
        """Constructor for the LinkReport class."""

        #-- 1 --
        self.__linkList  =  []

The os.path.walk function calls our .__visitor() method once for each directory in and under dir, passing it a list of the names in that directory; see Section 9.6, “LinkReport.__visitor(): Visitor function for os.path.walk(). The end result is to add one LinkInfo instance to self.__linkList for each soft link in the tree.

softlinks.py
        #-- 2 --
        # [ dir is a string ->
        #     self.__linkList  :=  self.__linkList with LinkInfo
        #         instances added representing every accessible
        #         soft link in the subtree rooted in dir ]
        os.path.walk ( dir, self.__visitor, dir )

All that remains is to sort the links by path name.

softlinks.py
        #-- 3 --
        # [ self.__linkList  :=  self.__linkList, sorted ]
        self.__linkList.sort()