Next / Previous / Contents / Shipman's homepage

22.9. YearRow.readOneMonth(): Read one monthly file

This method attempts to read one monthly XML input file.

noteweb
# - - -   Y e a r R o w . r e a d O n e M o n t h

    def readOneMonth ( self, monthFileName ):
        '''Try to read one month's field data.

          [ monthFileName is a string matching YYYY_MM_XML_PAT ->
              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) ]              
        '''

Since our precondition guarantees that monthFileName has the form 'yyyy-mm.xml', we can extract the month name by simple slicing.

noteweb
        #-- 1 --
        # [ mm  :=  month number from monthFileName
        #   monthPath  :=  self.yyyy + '/' + monthFileName ]
        #--
        # 0         1
        # 01234567890
        # yyyy-mm.xml
        #--
        mm  =  monthFileName[5:7]
        monthPath  =  '%s/%s' % (self.yyyy, monthFileName)

We'll create a BirdNoteSet instance whose taxonomy comes from our self.txny attribute. Then we'll call its .readFile() method to add the month file (if valid).

noteweb
        #-- 2 --
        # [ birdNoteSet  :=  a new birdnotes.BirdNoteSet instance
        #       with taxonomy self.txny ]
        birdNoteSet  =  birdnotes.BirdNoteSet ( self.txny )

        #-- 3 --
        # [ if monthPath names a readable file valid against
        #   birdnotes.rnc ->
        #     birdNoteSet  :=  birdNoteSet with data added
        #         from that file
        #   else ->
        #     sys.stderr  +:=  error message(s)
        #     return ]
        try:
            birdNoteSet.readFile ( monthPath )
        except IOError, detail:
            print >>sys.stderr, ( "*** Invalid monthly file "
                "'%s': %s" % (monthFileName, detail) )
            return

Finally, create a new MonthCell instance and add it to self.__monthMap. See Section 23, “class MonthCell: One table cell”.

noteweb
        #-- 4 --
        # [ self.__monthMap[mm]  :=  a new MonthCell instance
        #       with self as the parent, month=mm, and
        #       birdNoteSet=birdNoteSet ]
        self.__monthMap[mm]  =  MonthCell ( self, mm, birdNoteSet )