+ cleaned up directories
[qpalma.git] / pipeline / Pipeline.py
1 #!/usr/bin/env python
2 # -*- coding:latin-1 -*-
3
4 import subprocess
5
6 class PipelineStep:
7 """
8 The purpose of this class is to wrap a pipeline step which can be the
9 execution of a binary a small sequences of shell commands
10 """
11
12 def __init__(self,cL):
13 self.commandList = cL
14
15 def __call__(self):
16 success,pre_mes = self.checkPreConditions()
17 if not success:
18 return False,pre_mes
19
20 all_output = []
21 for currentCommand in self.commandList:
22 streams = subprocess.Popen(currentCommand,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
23 out,err = streams.communicate()
24
25 if err != '':
26 return False,err
27
28 all_output.append(out)
29
30 success,post_mes = self.checkPostConditions()
31 if not success:
32 return False,post_mes
33
34 return True,all_output
35
36
37 def checkPreConditions(self):
38 return True,''
39
40
41 def checkPostConditions(self):
42 return True,''
43
44
45 if __name__ == '__main__':
46 macro = PipelineStep(['date','w'])
47 status,mes = macro()
48 print status
49 print mes