Source code for pipelet.directive
## Copyright (C) 2008, 2009, 2010 APC LPNHE CNRS Universite Paris Diderot <lejeune@apc.univ-paris7.fr> <betoule@apc.univ-paris7.fr>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, see http://www.gnu.org/licenses/gpl.html
import shlex
[docs]class Directive:
""" Parse the segment code to get directives (multiplex, depend,
...)
"""
[docs] def parse(self, code):
""" Parse the code to initialiaze directive names and values.
Directive names and value are class attributs.
"""
try:
l = shlex.split(code)
except ValueError:
raise StopIteration()
it = iter(l)
if it.next() != self._name:
raise StopIteration()
for e in it:
if self.__dict__.has_key(e):
try:
setattr(self, e, it.next())
except StopIteration:
raise ValueError("The string is not a valid directive\n"+self._usage)
else:
try:
getattr(self,self._args).append(e)
except AttributeError:
setattr(self, self._args, e)
[docs]class Multiplex(Directive):
""" Multiplex directives are used to control the pipeline
parallelisation scheme.
"""
_name = "#multiplex"
_usage = "#multiplex method where 'condition' group_by 'value'"
_args = "method"
def __init__(self):
""" Init the multiplex directive.
"""
## string, multiplex method
self.method = "cross_prod"
## string, mutliplex condition
self.where = ""
## string, gathering condition
self.group_by = ""
[docs]class Depend(Directive):
""" Depend directive are used to include external code to the
hashkey computation.
"""
_name = "#depend"
_usage = "#depend file1 file2 ..."
_args = "deps"
def __init__(self):
""" Init the depend directive
"""
## list of external code files
self.deps=[]