From 696c9eaeab81ddcf2b20edf8be5ee6acfb97d314 Mon Sep 17 00:00:00 2001 From: wrought Date: Fri, 13 Jun 2014 16:23:05 -0700 Subject: [PATCH] fixes call to xsltproc, simplifies --- jats-to-mediawiki.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/jats-to-mediawiki.py b/jats-to-mediawiki.py index d394152..f852bd9 100755 --- a/jats-to-mediawiki.py +++ b/jats-to-mediawiki.py @@ -5,17 +5,13 @@ import wget import urllib import tarfile -import subprocess +from subprocess import call import glob ''' Helper functions ''' -# escape parentheses, @TODO may need to escape other characters -def shellquote(s): - return "'" + s.replace("(", "\(").replace(")", "\)") + "'" - # Unicode handling # (decode to unicode early, use unicode everywhere, encode late to string such as when # writing to disk or print) @@ -116,7 +112,7 @@ def main(): print "\nArticle IDs to convert:\n" #debug print articlepmcids #debug - # Main loop to grab the archive file, get the .nxml file, and convert + # Main loop to grab the archive file, get the .nxml file, and convert for articlepmcid in articlepmcids: # @TODO make flag an alternative to .tar.gz archive download @@ -155,14 +151,15 @@ def main(): nxmlfilepath = n print "\nConverting... " print nxmlfilepath - xsltcommand = "xsltproc jats-to-mediawiki.xsl " + shellquote(cwd + "/" + nxmlfilepath) + " > " + articlepmcid + ".xml.mw" - xsltprocess = subprocess.Popen(xsltcommand, stdout=subprocess.PIPE, shell=True) + fullnxmlfilepath = cwd + "/" + nxmlfilepath + xsltoutputfile = open(articlepmcid + ".xml.mw", 'w') + xsltcommand = call(['xsltproc', 'jats-to-mediawiki.xsl', fullnxmlfilepath], stdout=xsltoutputfile) print "\nReturning results..." - (output, err) = xsltprocess.communicate() - if output: - print "\nXSLT output..." - print output - + if xsltcommand == 0: + print xsltoutputfile.name + "\n" + else: + print "xslt conversion: failure" + sys.exit(-1) except KeyboardInterrupt: print "Killed script with keyboard interrupt, exiting..."