Explorar el Código

wxGUI/toolboxes: try to read XMLs after writing them

This is just to be sure they are basically OK.

We cannot use DTD validation beacause it is not available in standard Python and even if we would use lxml, if available, we would have to do the same for writing to write down DOCTYPE line.


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@65199 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras hace 10 años
padre
commit
6bb95f044e
Se han modificado 2 ficheros con 15 adiciones y 0 borrados
  1. 3 0
      gui/wxpython/Makefile
  2. 12 0
      gui/wxpython/core/toolboxes.py

+ 3 - 0
gui/wxpython/Makefile

@@ -38,9 +38,11 @@ $(DSTDIR)/%: % | $(PYDSTDIRS) $(DSTDIRS)
 
 xml/menudata.xml: core/toolboxes.py
 	$(call run_grass,$(PYTHON) $< > $@)
+	$(call run_grass,$(PYTHON) $< "validate" $@)
 
 xml/module_tree_menudata.xml: core/toolboxes.py
 	$(call run_grass,$(PYTHON) $< "module_tree" > $@)
+	$(call run_grass,$(PYTHON) $< "validate" $@)
 
 menustrings.py: core/menutree.py $(DSTDIR)/xml/menudata.xml $(DSTDIR)/xml/module_tree_menudata.xml $(DSTDIR)/xml/menudata_modeler.xml $(DSTDIR)/xml/menudata_psmap.xml
 	@echo "# This is a generated file.\n" > $@
@@ -52,6 +54,7 @@ menustrings.py: core/menutree.py $(DSTDIR)/xml/menudata.xml $(DSTDIR)/xml/module
 $(DSTDIR)/xml/module_items.xml: tools/build_modules_xml.py
 	@echo "Generating interface description for all modules..."
 	$(call run_grass,$(PYTHON) $< > $@)
+	$(call run_grass,$(PYTHON) $< "validate" $@)
 
 $(PYDSTDIRS): %: | $(DSTDIR)
 	$(MKDIR) $@

+ 12 - 0
gui/wxpython/core/toolboxes.py

@@ -827,6 +827,16 @@ def module_test():
         return 0
 
 
+def validate_file(filename):
+    try:
+        etree.parse(filename)
+    except ETREE_EXCEPTIONS as error:
+        print "XML file <{name}> is not well formed: {error}".format(
+            name=filename, error=error)
+        return 1
+    return 0
+
+
 def main():
     """Converts the toolboxes files on standard paths to the menudata file
 
@@ -852,4 +862,6 @@ if __name__ == '__main__':
             sys.exit(doc_test())
         elif sys.argv[1] == 'test':
             sys.exit(module_test())
+        elif sys.argv[1] == 'validate':
+            sys.exit(validate_file(sys.argv[2]))
     sys.exit(main())