The constructor takes as an argument the name of a
directory, and the name of a directory above it so it can
display the path name relative to that directory. First
we initialize the internal .__bigList
attribute.
# - - - B i g R e p o r t . _ _ i n i t _ _ - - -
def __init__ ( self, dir ):
"""Constructor for the BigReport class."""
#-- 1 --
self.__bigList = []
To visit every file in the subtree, we use the os.path.walk() function. This function takes
three arguments:
The name of the directory subtree to be walked.
A “visitor function” that will be called once for every directory in the subtree, including the starting directory.
The third argument gets passed on to the visitor
function as its first argument. We'll use this
argument to pass the starting directory name to
the visitor function, because the BigInfo object needs it to determine
relative path names.
#-- 2 --
# [ dir is a string ->
# self.__bigList := self.__bigList with BigInfo
# objects added representing every accessible
# file in the subtree named by dir ]
os.path.walk ( dir, self.__visitor, dir )
All that remains in the constructor is to sort the list.
#-- 3 --
# [ self.__bigList := self.__bigList, sorted ]
self.__bigList.sort()