Skip to content

Commit

Permalink
Merge branch 'dev-0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
gothub committed Sep 5, 2019
2 parents 5b37866 + b0a8512 commit e3d5809
Show file tree
Hide file tree
Showing 82 changed files with 23,368 additions and 19,666 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ rsconnect/

# Intellij project directory
.idea/

# Ant distribution directory
dist/**
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## metadig-checks: MetaDIG suites and checks for data and metadata improvement and guidance.


- **Author**: Matthew B. Jones, Peter Slaughter ([NCEAS](http://www.nceas.ucsb.edu), Ted Habermann, Sean Gordon
- **Author**: Matthew B. Jones, Peter Slaughter ([NCEAS](http://www.nceas.ucsb.edu)), Ted Habermann, Sean Gordon
- **License**: [Apache 2](http://opensource.org/licenses/Apache-2.0)
- [**Submit Bugs and feature requests**](https://github.com/NCEAS/metadig-checks/issues)

Expand Down
73 changes: 73 additions & 0 deletions bin/stageFiles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/Library/Frameworks/Python.framework/Versions/3.6/bin/python3

import xml.etree.ElementTree as ET
import os
import re
import argparse

from shutil import copyfile

# Locate files starting at path, with filenames that match a regex
def findfiles(path, regex):
#print("regex: {}".format(regex))
regObj = re.compile(regex)
res = []
for root, dirs, fnames in os.walk(path):
for fname in fnames:
#print("fname: {}".format(fname))
if regObj.match(fname):
res.append(os.path.join(root, fname))
#print("root: {}, fname: {}".format(root, fname))
return res

if __name__ == '__main__':

parser = argparse.ArgumentParser(description='stage MetaDIG checks and suites.')
parser.add_argument('src', metavar='N', type=str, nargs='+',
help='source directory')
parser.add_argument('dst', metavar='N', type=str, nargs='+',
help='destination directory')
parser.add_argument('suites', metavar='N', type=str, nargs='+',
help='suites to stage')

args = parser.parse_args()
src = args.src[0]
dst = args.dst[0]
suites = args.suites[0].split(",")
cwd = os.getcwd()

print("source: {}".format(src))
print("destination: {}".format(dst))
print("suites: {}".format(suites))

for suite in suites:
# Parse the next suite XML to and find all the checks listed
print("processing suite: {}".format(suite))
copyfile("src/suites/{}".format(suite), "{}/suites/{}".format(dst, suite))

tree = ET.parse('src/suites/{}'.format(suite))
root = tree.getroot()

# Loop through all '<check' elements in this suite XML file
for check in root.findall('check'):
# Get the <id> element from the check
id = check.find('id').text
print("id: {}".format(id))

#print findfiles('src/checks', "<id>\s*{}\s*</id>".format(id))
#print findfiles('./src/checks', "<id>\s*{}\s*</id>".format(id))

# Find all check files available
checkFiles = findfiles('{}/checks'.format(src), "^.*xml$")
#print checkFiles
# for this id, search each check file to find the check file with this id
for file in checkFiles:
#print("file {}".format(file))
with open(file) as thisFile:
if id in thisFile.read():
print('found check id {} in file {}'.format(id, file))
srcfile = "{}/{}".format(cwd, file)
fname = os.path.basename(file)
dstfile = "{}/{}/checks/{}".format(cwd, dst, fname)
print("cp {} {}".format(srcfile, dstfile))
copyfile(srcfile, dstfile)
15 changes: 15 additions & 0 deletions build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Ant build properties files for the metadig-checks build

# MetaDIG checks version
metadig-checks.version=0.2.0

build=build
dist=dist
src=src
bin=bin
data=data
# The script that reads suite XML files and copies all needed checks to dist
stagescript=stageFiles.py
# The suites to include in the distribution tar file
#suites=arctic-data-center.xml,ess-dive.xml,FAIR-suite.xml,knb-suite.xml
suites=FAIR-suite.xml
59 changes: 59 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<project name="MetaDIG-checks" default="dist" basedir=".">
<!-- This build file provides tasks to create distributions for the
MetaDIG Quality Engine.
Set properties in the file 'build.properties' to control the operation
of the tasks
-->
<property file="build.properties" />
<description>
MetaDIG Quality Engine Suites and Checks
</description>
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
</target>
<target name="dist" depends="init"
description="generate the MetaDIG Checks distribution">
<!-- Create the distribution directory -->
<mkdir dir="${dist}"/>
<mkdir dir="${dist}/checks"/>
<mkdir dir="${dist}/data"/>
<mkdir dir="${dist}/suites"/>

<copy todir="${dist}/data">
<fileset dir="${data}">
</fileset>
</copy>

<exec executable="${bin}/${stagescript}" spawn="false" output="stage.log">
<arg value="src"/>
<arg value="dist"/>
<arg value="${suites}"/>
</exec>

<tar destfile="${dist}/metadig-checks-${metadig-checks.version}.tar">
<tarfileset dir="${dist}/checks"
prefix="checks"
preserveLeadingSlashes="false">
<include name="*.xml"/>
</tarfileset>
<tarfileset dir="${dist}/suites"
prefix="suites"
preserveLeadingSlashes="false">
<include name="*.xml"/>
</tarfileset>
<tarfileset dir="${dist}/data"
prefix="data"
preserveLeadingSlashes="false">
<include name="*.*"/>
</tarfileset>
</tar>
</target>

<target name="clean"
description="clean up">
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>
Loading

0 comments on commit e3d5809

Please sign in to comment.