Next / Previous / Contents / Shipman's homepage

20.2. BirdNoteTree._findMonths(): Scan yearly directories

birdnotes.py
# - - -   B i r d N o t e T r e e . _ f i n d M o n t h s

    def _findMonths(self, yyyy):
        '''Scan one year directory for month files.

          [ (self.rootDir is as invariant) and
            (yyyy is a year number as a 4-digit string) ->
              if subdirectory (yyyy) of self.rootDir can be read ->
                self._monthList  +:=  the "YYYY-MM" part of
                    the names of files in that subdirectory
                    whose names match YYYY_MM_XML_PAT
              else -> raise IOError ]
        '''

For the pattern that matches month file names, see Section 5.3, “YYYY_MM_XML_PAT: Month file name pattern”.

birdnotes.py
        #-- 1 --
        # [ subDirPath  :=  path to subdirectory (yyyy) of
        #                   directory (self.rootDir) ]
        subDirPath = os.path.join(self.rootDir, yyyy)

        #-- 2 --
        # [ if directory (subDirPath) can be read ->
        #     fileList  :=  list of names in that directory that
        #                   match YYYY_MM_XML_PAT
        #   else -> raise IOError ]
        fileList = [ fileName
                     for fileName in os.listdir(subDirPath)
                     if YYYY_MM_XML_PAT.match(fileName) ]

The ._monthList attribute contains only the "YYYY-MM" strings.

birdnotes.py
        #-- 3 --
        # [ self._monthList  +:=  the "YYYY-MM" parts of
        #       the elements of fileList ]
        for fileName in fileList:
            self._monthList.append(fileName[:7])