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: ...@@ -218,4 +218,8 @@ We provide an example XML file that is self describing:
</action> </action>
</alta> </alta>
\endverbatim \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. ...@@ -11,8 +11,10 @@ page.
import sys import sys
from sys import argv from sys import argv
from xml.etree.ElementTree import parse from xml.etree.ElementTree import parse
import subprocess
import os import os
from os import listdir
from os.path import isfile, join
""" Color capable outputing """ Color capable outputing
""" """
...@@ -155,16 +157,6 @@ def parseAction(xmlNode): ...@@ -155,16 +157,6 @@ def parseAction(xmlNode):
global lib_dir, dat_dir, out_dir global lib_dir, dat_dir, out_dir
cmd = '' 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')) cmd += parseFunctions(xmlNode.findall('function'))
for plugin in xmlNode.findall('plugin'): for plugin in xmlNode.findall('plugin'):
...@@ -178,7 +170,25 @@ def parseAction(xmlNode): ...@@ -178,7 +170,25 @@ def parseAction(xmlNode):
cmd += ' ' + param.attrib['value'] cmd += ' ' + param.attrib['value']
#end #end
return cmd # 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 #end
...@@ -186,11 +196,8 @@ def parseAction(xmlNode): ...@@ -186,11 +196,8 @@ def parseAction(xmlNode):
## Parse the configuration part of the file ## Parse the configuration part of the file
## ##
conf = root.find("configuration") conf = root.find("configuration")
if conf is None: if not (conf is None):
print '<<PYTHON>> no configuration specified in the XML file' parseConfiguration(conf)
else:
parseConfiguration(conf)
#end
## Command lines creation ## Command lines creation
...@@ -206,14 +213,20 @@ for child in root.findall('action'): ...@@ -206,14 +213,20 @@ for child in root.findall('action'):
# Parse the action # Parse the action
cmd += parseAction(child) try:
for act in parseAction(child):
printout(cmd, GREEN)
print printout(cmd + act, GREEN)
print
ret = os.system(cmd)
if ret != 0: ret = subprocess.check_call(cmd + act, shell=True)
printout('<<PYTHON>> the action was not performed', RED) if ret != 0:
#end printout('<<PYTHON>> the action was not performed', RED)
print '\n' #end
print '\n'
#end
except:
printout('<<PYTHON>> exception caught, stopping', RED)
print '\n'
exit(0)
#end #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