mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 14:15:42 -04:00
removed trang from xml validate script and updated documentation
This commit is contained in:
parent
468105838e
commit
2bfd9ed051
3 changed files with 38 additions and 42 deletions
|
|
@ -57,13 +57,7 @@ Validating XML Files
|
|||
|
||||
Input files can be checked before executing OpenMC using the ``xml_validate``
|
||||
script. It is located in ``src/utils/xml_validate.py`` in the source code or in
|
||||
``bin/xml_validate`` in the install directory. Before use, the third party
|
||||
package TRANG_ must be installed and in your ``PATH`` to convert the compact
|
||||
RelaxNG schema to standard RelaxNG format. For Ubuntu, you can install with:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
sudo apt-get install trang
|
||||
``bin/xml_validate`` in the install directory.
|
||||
|
||||
Two command line arguments can be set when running ``xml_validate``:
|
||||
|
||||
|
|
@ -84,7 +78,6 @@ Message Description
|
|||
======================== ===================================
|
||||
[XML ERROR] Cannot parse XML file.
|
||||
[NO RELAXNG FOUND] No RelaxNG file found for XML file.
|
||||
[TRANG FAILED] TRANG not installed properly.
|
||||
[NOT VALID] XML file does not match RelaxNG.
|
||||
[VALID] XML file matches RelaxNG.
|
||||
======================== ===================================
|
||||
|
|
@ -98,8 +91,6 @@ the following command:
|
|||
|
||||
/opt/openmc/0.6.2/bin/xml_validate
|
||||
|
||||
.. _TRANG: http://www.thaiopensource.com/relaxng/trang.html
|
||||
|
||||
--------------------------------------
|
||||
Settings Specification -- settings.xml
|
||||
--------------------------------------
|
||||
|
|
|
|||
19
src/relaxng/readme.rst
Normal file
19
src/relaxng/readme.rst
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
=====================
|
||||
Editing RelaxNG files
|
||||
=====================
|
||||
|
||||
All direct edits to RelaxNG files should be in the .rnc files. The program
|
||||
TRANG_ should be used to generate a correcsponding .rng file. For Ubuntu, you
|
||||
can install with:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
sudo apt-get install trang
|
||||
|
||||
To convert the .rnc file to .rng, use the following syntax:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
trang {filename}.rnc {filename}.rng
|
||||
|
||||
.. _TRANG: http://www.thaiopensource.com/relaxng/trang.html
|
||||
|
|
@ -50,10 +50,10 @@ if not os.path.exists(relaxng_path):
|
|||
raise Exception("RelaxNG path: {0} does not exist, set with -r "
|
||||
"command line option.".format(relaxng_path))
|
||||
|
||||
# Make sure there are .rnc files in RelaxNG path
|
||||
rnc_files = glob.glob(os.path.join(relaxng_path, "*.rnc"))
|
||||
if len(rnc_files) == 0:
|
||||
raise Exception("No .rnc files found in RelaxNG "
|
||||
# Make sure there are .rng files in RelaxNG path
|
||||
rng_files = glob.glob(os.path.join(relaxng_path, "*.rng"))
|
||||
if len(rng_files) == 0:
|
||||
raise Exception("No .rng files found in RelaxNG "
|
||||
"path: {0}.".format(relaxng_path))
|
||||
|
||||
# Get list of xml input files
|
||||
|
|
@ -80,36 +80,22 @@ for xml_file in xml_files:
|
|||
xml_prefix = os.path.basename(xml_file)
|
||||
xml_prefix = xml_prefix.split(".")[0]
|
||||
|
||||
# Search for rnc file
|
||||
rnc_file = os.path.join(relaxng_path, xml_prefix + ".rnc")
|
||||
rng_file = xml_prefix + ".rng"
|
||||
if rnc_file in rnc_files:
|
||||
# Search for rng file
|
||||
rng_file = os.path.join(relaxng_path, xml_prefix + ".rng")
|
||||
if rng_file in rng_files:
|
||||
|
||||
# convert RNC to RNG file
|
||||
rc = call("trang {0} {1}".format(rnc_file, rng_file), shell=True)
|
||||
# read in RelaxNG
|
||||
relaxng_doc = etree.parse(rng_file)
|
||||
relaxng = etree.RelaxNG(relaxng_doc)
|
||||
|
||||
# check return code
|
||||
if rc == 0:
|
||||
# validate xml file again RelaxNG
|
||||
try:
|
||||
relaxng.assertValid(xml_tree)
|
||||
print(BOLD + OK + '[VALID]' + ENDC)
|
||||
except (etree.DocumentInvalid, TypeError) as e:
|
||||
print(BOLD + FAIL + '[NOT VALID]' + ENDC)
|
||||
print(" {0}".format(e))
|
||||
|
||||
# read in RelaxNG
|
||||
relaxng_doc = etree.parse(rng_file)
|
||||
relaxng = etree.RelaxNG(relaxng_doc)
|
||||
|
||||
# validate xml file again RelaxNG
|
||||
try:
|
||||
relaxng.assertValid(xml_tree)
|
||||
print(BOLD + OK + '[VALID]' + ENDC)
|
||||
except (etree.DocumentInvalid, TypeError) as e:
|
||||
print(BOLD + FAIL + '[NOT VALID]' + ENDC)
|
||||
print(" {0}".format(e))
|
||||
|
||||
# remove rng file
|
||||
os.remove(rng_file)
|
||||
|
||||
# trang command failed
|
||||
else:
|
||||
print(BOLD + FAIL + '[TRANG FAILED]' + ENDC)
|
||||
|
||||
# RNC file does not exist
|
||||
# RNG file does not exist
|
||||
else:
|
||||
print(BOLD + NOT_FOUND + '[NO RELAXNG FOUND]' + ENDC)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue