Attention une mise à jour du serveur va être effectuée le lundi 17 mai entre 13h et 13h30. Cette mise à jour va générer une interruption du service de quelques minutes.

Commit 9d0e6de3 authored by Laurent Belcour's avatar Laurent Belcour

The xml_cmd script allows to generate a command over a list of file in a...

The xml_cmd script allows to generate a command over a list of file in a directory. This can be useful to perform the same command on many inputs.
parent ab16ff3e
......@@ -218,4 +218,8 @@ We provide an example XML file that is self describing:
</action>
</alta>
\endverbatim
The `<input>` command can take two different kind of attributes:
+ `name="filename"` when the action is done for a single input file.
+ `directory="dirname"` when all file withing 'dirname' must be processed using the current action.
*/
......@@ -11,8 +11,10 @@ page.
import sys
from sys import argv
from xml.etree.ElementTree import parse
import subprocess
import os
from os import listdir
from os.path import isfile, join
""" Color capable outputing
"""
......@@ -155,16 +157,6 @@ def parseAction(xmlNode):
global lib_dir, dat_dir, out_dir
cmd = ''
inputNode = xmlNode.find('input')
if not (inputNode is None):
cmd += ' --input ' + inputNode.attrib['name']
#end
outputNode = xmlNode.find('output')
if not (outputNode is None):
cmd += ' --output ' + outputNode.attrib['name']
#end
cmd += parseFunctions(xmlNode.findall('function'))
for plugin in xmlNode.findall('plugin'):
......@@ -178,6 +170,24 @@ def parseAction(xmlNode):
cmd += ' ' + param.attrib['value']
#end
# Search the input file to the command. It is possible for the xml
# command to loop over a list of file present in a directory using
# the directory attrib. In that case, cmd is duplicated into a cmd
# list.
inputNode = xmlNode.find('input')
outputNode = xmlNode.find('output')
if not (inputNode is None) and not (outputNode is None):
if 'directory' in inputNode.attrib:
dirname = inputNode.attrib['directory']
cmds = [cmd + ' --input ' + join(dirname, f) + ' --output ' + f + '.out' for f in listdir(dirname) if isfile(join(dirname, f))]
cmd = cmds;
else:
cmd += ' --input ' + inputNode.attrib['name']
cmd += ' --output ' + outputNode.attrib['name']
cmd = [cmd]
#end
#end
return cmd
#end
......@@ -186,11 +196,8 @@ def parseAction(xmlNode):
## Parse the configuration part of the file
##
conf = root.find("configuration")
if conf is None:
print '<<PYTHON>> no configuration specified in the XML file'
else:
if not (conf is None):
parseConfiguration(conf)
#end
## Command lines creation
......@@ -206,14 +213,20 @@ for child in root.findall('action'):
# Parse the action
cmd += parseAction(child)
try:
for act in parseAction(child):
printout(cmd, GREEN)
printout(cmd + act, GREEN)
print
ret = os.system(cmd)
ret = subprocess.check_call(cmd + act, shell=True)
if ret != 0:
printout('<<PYTHON>> the action was not performed', RED)
#end
print '\n'
#end
except:
printout('<<PYTHON>> exception caught, stopping', RED)
print '\n'
exit(0)
#end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment