Skip to content

Commit

Permalink
Commit cleaned up CI script and support file
Browse files Browse the repository at this point in the history
  • Loading branch information
blchoy committed Jul 23, 2021
1 parent d06fa3f commit 9c7c7ac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
45 changes: 21 additions & 24 deletions bin/validate-examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,43 @@ def main():
print("This script must be run from the root directory of the repository, usually 'iwxxm', which contains README.md")
sys.exit(1)

# obtain codes registry content
codeLists.run('IWXXM', 'IWXXM/rule/')

# only validate the latest version and examples. Older versions had a number of issues that have already been fixed
# and there is little point in running tests against them
# get version and path to iwxxm.xsd
with open('LATEST_VERSION') as fhandle:
LV = fhandle.read().strip()
devVersion = LV.split('\n')[1]
valVersion = LV.split('\n')[0]
XSDVersion = LV.split('\n')[0]
XSDPath = LV.split('\n')[1]

iwxxmDirs = [os.path.join(cwd,devVersion)]
# obtain codes registry content
codeLists.run('IWXXM', os.path.join(XSDPath,'rule'))

FullXSDPath = os.path.join(cwd,XSDPath)
returnCode=0
for dir in iwxxmDirs:
result = validate_dir(dir, valVersion)
if result > 0:
print("========= Validation FAILED on %s =========" % dir)
returnCode = result
else:
print("========= Validation SUCCESSFUL on %s =========" % dir)
result = validate_dir(cwd, XSDPath, XSDVersion)
if result > 0:
print("========= Validation FAILED on %s =========" % FullXSDPath)
returnCode = result
else:
print("========= Validation SUCCESSFUL on %s =========" % FullXSDPath)

if returnCode != 0:
sys.exit( returnCode )

def validate_dir(dir, vver):
def validate_dir(rdir, dir, ver):
fdir = os.path.join(rdir, dir)
catalogTemplate='catalog.template.xml'
iwxxmDir=os.path.split(dir)[1]
iwxxmVersion = vver
thisCatalogFile=catalogTemplate.replace('template',iwxxmDir)
thisCatalogFile=catalogTemplate.replace('template',ver)

# replace ${IWXXM_VERSION} and ${IWXXM_VERSION_DIR} with appropriate values in the catalog.xml file
with open( catalogTemplate ) as templateFhandle:
with open( thisCatalogFile, 'w' ) as catalogFhandle:
catalogText=templateFhandle.read()
catalogText=catalogText.replace("${IWXXM_VERSION}", iwxxmVersion)
catalogText=catalogText.replace("${IWXXM_VERSION_DIR}", iwxxmDir)
catalogText=catalogText.replace("${IWXXM_VERSION}", ver)
catalogText=catalogText.replace("${IWXXM_VERSION_DIR}", dir)
catalogFhandle.write(catalogText)

print('Validating %s against XML Schema and Schematron' % dir)
examplesDir = os.path.join(dir,'examples')
validationResult = os.system( 'bin/crux-1.3-all.jar -c %s -s %s/rule/iwxxm.sch %s/*.xml' % (thisCatalogFile,dir,examplesDir) )
print('Validating %s against XML Schema and Schematron' % fdir)
examplesDir = os.path.join(fdir,'examples')
validationResult = os.system( 'bin/crux-1.3-all.jar -c %s -s %s/rule/iwxxm.sch %s/*.xml' % (thisCatalogFile,fdir,examplesDir) )
if validationResult > 0:
print('FAILED validation. Continuing...')
else:
Expand Down
2 changes: 1 addition & 1 deletion catalog.template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">

<!-- IWXXM template - IWXXM_VERSION to be replaced by the appropriate IWXXM version (such as 2.1) and IWXXM version path (such as 2.1.0) -->
<rewriteSystem systemIdStartString="http://schemas.wmo.int/iwxxm/${IWXXM_VERSION}" rewritePrefix="${IWXXM_VERSION_DIR}/"/>
<rewriteSystem systemIdStartString="http://schemas.wmo.int/iwxxm/${IWXXM_VERSION}" rewritePrefix="${IWXXM_VERSION_DIR}"/>

<!-- Other non-IWXXM schemas from schemas.wmo.int -->
<rewriteSystem systemIdStartString="http://schemas.wmo.int/" rewritePrefix="externalSchema/schemas.wmo.int/"/>
Expand Down

0 comments on commit 9c7c7ac

Please sign in to comment.