-
Notifications
You must be signed in to change notification settings - Fork 1
/
transform2rdf.py
executable file
·34 lines (23 loc) · 1.02 KB
/
transform2rdf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#! /usr/bin/env python
import os
from string import Template
import argparse
xslfile = '/Users/cwulfman/work/Modnets/mjp2rdf.xsl'
cmdTemplate = Template('saxon -s:$src -xsl:$xsl -o:$out')
def transform_files(sourcedir, targetdir):
for root, dirs, files in os.walk(sourcedir):
target_subdir = '/'.join((targetdir.rstrip('/'), root.lstrip('/')))
for fname in files:
if fname.endswith('.xml'):
source = '/'.join((root, fname))
target = '/'.join((target_subdir, fname))
cmd = cmdTemplate.substitute(src=source, xsl=xslfile, out=target)
print "echo " + cmd
print cmd
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--input_dir", help="top-level directory of source xml files.")
parser.add_argument("-o", "--output_dir", help="target directory.")
args = parser.parse_args()
if args.input_dir and args.output_dir:
transform_files(args.input_dir, args.output_dir)