Next / Previous / Contents / Shipman's homepage

15.10. RelaxValidator.__trang(): Translate .rnc to .rng format

We use the pexpect module's run() function to execute the trang script with command line arguments of this form:

trang F.rnc F.rng

That function returns the entire output of the run as a string. The output from trang is empty if the translation succeeded; otherwise it contains the error message.
# - - -   R e l a x V a l i d a t o r . _ _ t r a n g

    def __trang(self, cName, gName):
        '''Translate an RNC schema to RNG format.

          [ 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 ]
        #-- 1 --
        # [ output  :=  all output from the execution of the command
        #               "trang (cName) (gName)" ]
        output ="trang %s %s" % (cName, gName))

        #-- 2 --
        if len(output) > 0:
            raise ValueError("Could not create '%s' from '%s':/n%s" %
                (gName, cName, output))