Next / Previous / Contents / Shipman's homepage

7.5. BirdNoteSet._fileTime(): Update the most recent modification time

birdnotes.py
# - - -   B i r d N o t e S e t . _ f i l e T i m e

    def _fileTime(self, fileName):
        """Update self._newestTime

          [ fileName is a string ->
              if fileName does not exist ->
                raise IOError
              else if (self.newestTime is None) or
              (self.newestTime < modification time of fileName) ->
                self.newestTime  :=  modification time of fileName
              else -> I ]
        """
        #-- 1 --
        # [ if fileName names a file that does not exist or is
        #   unreadable ->
        #     raise IOError
        #   else ->
        #     modTime  :=  modification timestamp of that file ]
        if  os.path.exists(fileName):
            status = os.stat(fileName)
            modTime = status[stat.ST_MTIME]
        else:
            raise IOError("No such file: '%s'" % fileName)

        #-- 2 --
        if ((self.newestTime is None) or
              (self.newestTime < modTime)):
            self.newestTime = modTime