コード例 #1
0
ファイル: scherror.py プロジェクト: jhill1/stk
    def on_validate_schematron(self, widget=None):
        """
    Tools > Validate Schematron. This uses the etree.Schematron API, if it exists, to
    validate the document tree against a supplied schematron file.
    """

        if self.schematron_file is None:
            dialogs.error(self.parent.main_window,
                          "No schematron file supplied")
            return

        # Write the current version out to file.
        tmp = tempfile.NamedTemporaryFile()
        self.parent.tree.write(tmp.name)
        std_input, std_output, err_output = os.popen3(
            "xmllint --schematron %s %s --noout" %
            (self.schematron_file, tmp.name))
        output = err_output.read()

        output = output.replace("%s fails to validate" % tmp.name, "")
        output = output.strip()

        if output == "%s validates" % tmp.name:
            self.destroy_error_list()
            dialogs.message_box(
                self.parent.main_window,
                "XML file validated successfully against %s" %
                self.schematron_file, "XML validation successful")

        # Clear the list, as there may still be errors from a previous schematron validation.
        self.model.clear()
        self.errlist_type = 0

        # Add each line of output as a new row.
        lines = output.split("\n")

        for line in lines:
            if len(line) == 0:
                continue

        tokens = line.split(" ")
        self.model.append([tokens[0], " ".join(tokens[3:]), 0])

        # Finish set up of list view widget.
        self.listview.set_property("visible", True)
        self.listwindow.set_property("visible", True)
        self.parent.statusbar.set_statusbar(
            "There are %u Schematron errors in the document" % len(lines))
コード例 #2
0
ファイル: scherror.py プロジェクト: FluidityProject/fluidity
  def on_validate_schematron(self, widget=None):
    """
    Tools > Validate Schematron. This uses the etree.Schematron API, if it exists, to
    validate the document tree against a supplied schematron file.
    """

    if self.schematron_file is None:
      dialogs.error(self.parent.main_window, "No schematron file supplied")
      return

    # Write the current version out to file.
    tmp = tempfile.NamedTemporaryFile()
    self.parent.tree.write(tmp.name)
    std_input, std_output, err_output = os.popen3("xmllint --schematron %s %s --noout" % (self.schematron_file, tmp.name))
    output = err_output.read()

    output = output.replace("%s fails to validate" % tmp.name, "")
    output = output.strip()

    if output == "%s validates" % tmp.name:
      self.destroy_error_list()
      dialogs.message_box(self.parent.main_window, "XML file validated successfully against %s" % self.schematron_file, "XML validation successful")

    # Clear the list, as there may still be errors from a previous schematron validation.
    self.model.clear()
    self.errlist_type = 0

    # Add each line of output as a new row.
    lines = output.split("\n")

    for line in lines:
      if len(line) == 0:
        continue

    tokens = line.split(" ")
    self.model.append([ tokens[0], " ".join(tokens[3:]), 0 ])

    # Finish set up of list view widget.
    self.listview.set_property("visible", True)
    self.listwindow.set_property("visible", True)
    self.parent.statusbar.set_statusbar("There are %u Schematron errors in the document" % len(lines))
コード例 #3
0
ファイル: scherror.py プロジェクト: jhill1/stk
    def on_validate(self, widget=None):
        """
    Tools > Validate XML. This writes out the XML to a temporary file, then calls
    xmllint on it. (I didn't use the Xvif validation capabilities because the error
    messages are worse than useless; xmllint actually gives line numbers and such).
    """

        if self.schema_file is None:
            dialogs.error(self.parent.main_window, "No schema file open")
            return

        self.tmp = tempfile.NamedTemporaryFile()
        self.parent.tree.write(self.tmp.name)

        std_input, std_output, std_error = os.popen3(
            "xmllint --relaxng %s %s --noout --path \".\"" %
            (self.schema_file, self.tmp.name))
        output = std_error.read()

        output = output.replace("%s fails to validate" % self.tmp.name, "")

        if output.strip() == "%s validates" % self.tmp.name:
            # No errors. Close the error list (if it is open) and display a congratulatory message box.
            self.destroy_error_list()
            dialogs.message_box(self.parent.main_window,
                                "XML file validated successfully",
                                "Validation successful")
        else:
            self.create_error_list()

            self.errlist_type = 1
            self.model.clear()

            lines = output.split("\n")

            # Read the temporary output file, split it by lines and use it to convert
            # line numbers to xpaths for the column data.
            f = file(self.tmp.name)
            data = f.read()
            output_lines = data.split("\n")

            for line in lines:
                if len(line) == 0:
                    continue

                tokens = line.split(" ")

                # Parse each line of the xmllint --relaxng output.
                # FORMAT:
                # ELEMENT:LINE: element NAME:  Relax-NG validity error : ERROR MESSAGE
                # (Capitals denotes variable data). Update the following code if the output changes.
                sub_tokens = tokens[0].split(":")

                message = " ".join(tokens[7:])

                line = sub_tokens[1]
                xpath = self.add_to_xpath(output_lines, "", long(line) - 1)

                self.model.append([xpath, message])

            self.listview.set_property("visible", True)
            self.listwindow.set_property("visible", True)

            # Update the status bar. Inform the user of the number of errors.
            self.parent.statusbar.set_statusbar(
                "There are %u Relax-NG errors in the document" % len(lines))

        return
コード例 #4
0
ファイル: scherror.py プロジェクト: FluidityProject/fluidity
  def on_validate(self, widget=None):
    """
    Tools > Validate XML. This writes out the XML to a temporary file, then calls
    xmllint on it. (I didn't use the Xvif validation capabilities because the error
    messages are worse than useless; xmllint actually gives line numbers and such).
    """

    if self.schema_file is None:
      dialogs.error(self.parent.main_window, "No schema file open")
      return

    self.tmp = tempfile.NamedTemporaryFile()
    self.parent.tree.write(self.tmp.name)

    std_input, std_output, std_error = os.popen3("xmllint --relaxng %s %s --noout --path \".\"" % (self.schema_file, self.tmp.name))
    output = std_error.read()

    output = output.replace("%s fails to validate" % self.tmp.name, "")

    if output.strip() == "%s validates" % self.tmp.name:
      # No errors. Close the error list (if it is open) and display a congratulatory message box.
      self.destroy_error_list()
      dialogs.message_box(self.parent.main_window, "XML file validated successfully", "Validation successful")
    else:
      self.create_error_list()

      self.errlist_type = 1
      self.model.clear()

      lines = output.split("\n")

      # Read the temporary output file, split it by lines and use it to convert
      # line numbers to xpaths for the column data.
      f = file(self.tmp.name)
      data = f.read()
      output_lines = data.split("\n")

      for line in lines:
        if len(line) == 0:
          continue

        tokens = line.split(" ")

	# Parse each line of the xmllint --relaxng output.
	# FORMAT:
	# ELEMENT:LINE: element NAME:  Relax-NG validity error : ERROR MESSAGE
	# (Capitals denotes variable data). Update the following code if the output changes.
        sub_tokens = tokens[0].split(":")

        message = " ".join(tokens[7:])

        line = sub_tokens[1]
        xpath = self.add_to_xpath(output_lines, "", long(line)-1)

        self.model.append([ xpath, message ])

      self.listview.set_property("visible", True)
      self.listwindow.set_property("visible", True)

      # Update the status bar. Inform the user of the number of errors.
      self.parent.statusbar.set_statusbar("There are %u Relax-NG errors in the document" % len(lines))

    return