Next / Previous / Contents / Shipman's homepage

15.8. RelaxValidator.__makeRNG(): Find or create an .rng file

rnc_validate.py
# - - -   R e l a x V a l i d a t o r . _ _ m a k e R N G

    def __makeRNG(self, cName, gName):
        '''Insure that a current RNG file exists.

          [ (cName names an RNC file) and (gName names an RNG file) ->
              if (file cName is readable) and (gName names a
              readable file that is newer than cName) ->
                I
              else if (cName names a readable, valid RNC file) and
              (we have write access to path gName) and
              (trang is locally installed) ->
                file gName  :=  trang's translation of file cName into RNG
              else -> raise ValueError ]
        '''

First we get the modification time of the .rnc file. See Section 15.9, “RelaxValidator.__getModTime(): When was this file last changed?”. If anything goes wrong, we raise a ValueError.

rnc_validate.py
        #-- 1 --
        # [ if we can stat file (cName) ->
        #     cTime  :=  epoch modification timestamp of that file
        #   else -> raise ValueError ]
        try:
            cTime = self.__getModTime(cName)
        except (IOError, OSError), details:
            raise ValueError("Can't read the RNC file '%s': %s" %
                (cName, str(details)))

Then we try to get the modification time of the .rng file. If that file exists and the modification time is newer, we're done, because the .rng is up to date against the requested .rnc schema. If either the file doesn't exist or it's out of date, fall through to the next step.

rnc_validate.py
        #-- 2 --
        # [ if (we can stat file (gName)) and
        #   (that file's modification time is more recent than cTime) ->
        #     return
        #   else -> I ]
        try:
            gTime = self.__getModTime(gName)
            if gTime > cTime:
                return
        except (IOError, OSError):
            pass

Now, try to recreate the .rng file by running the .rnc file through trang. See Section 15.10, “RelaxValidator.__trang(): Translate .rnc to .rng format”.

rnc_validate.py
        #-- 3 --
        # [ if (file (cName) is a valid RNC file) and
        #   (we have write access to path gName) and
        #   (trang is locally installed) ->
        #     file (gName)  :=  an RNG representation of file (cName)
        #   else -> raise ValueError ]
        self.__trang(cName, gName)