Next / Previous / Contents / Shipman's homepage

22.8. YearRow.readAllMonths(): Process input files for one year

This method looks in subdirectory self.yyyy to see if there are any files whose names look like monthly XML input files, and attempts to read them all. Those which are valid will be stored in self.__monthMap; the invalid ones will generate error messages.

# - - -   Y e a r R o w . r e a d A l l M o n t h s

    def readAllMonths ( self ):
        '''Find and read all monthly files for this year.

We use os.listdir() to get a list of all the names in the year directory, filtering it with the regular expression declared in Section 10.4, “YYYY_MM_XML_PAT: Month file name pattern”.

        #-- 1 --
        # [ monthFileNameList  :=  names from directory
        #       ('./'+self.yyyy) that match YYYY_MM_XML_PAT ]
        monthFileNameList  =  [ fileName
            for fileName in os.listdir ( self.yyyy )
            if YYYY_MM_XML_PAT.match(fileName) is not None ]

For each month file, we attempt to open and read that file using the birdnotes.BirdNoteSet constructor. The txny argument is necessary to define the valid bird codes. See Section 22.9, “YearRow.readOneMonth(): Read one monthly file”.

        #-- 2 --
        # [ self  :=  self with MonthCell instances added
        #       representing files in monthFileNameList
        #       valid against birdnotes.rnc and txny
        #   sys.stderr  +:=  error message(s) for invalid
        #       files, if any ]
        for monthFileName in monthFileNameList:
            #-- 2 body --
            # [ if monthFileName names a readable file
            #   valid against birdnotes.rnc and txny ->
            #     self.__monthMap  +:=  an entry whose key is the
            #         month number and whose value is a MonthCell
            #         representing that file
            #   else ->
            #     sys.stderr  +:=  error message(s) ]
            self.readOneMonth ( monthFileName )