blob: 0b3c3a3935a6a1df9bd955f052549cd1b812d6d2 [file] [log] [blame]
Daniel Dunbar378530c2009-01-05 19:53:30 +00001import Arguments
2import Util
3
4class Job(object):
5 """Job - A set of commands to execute as a single task."""
6
7 def iterjobs(self):
8 abstract
9
10class Command(Job):
11 """Command - Represent the information needed to execute a single
Daniel Dunbarb421dba2009-01-07 18:40:45 +000012 process.
13
14 This currently assumes that the executable will always be the
15 first argument."""
Daniel Dunbar378530c2009-01-05 19:53:30 +000016
17 def __init__(self, executable, args):
Daniel Dunbarb421dba2009-01-07 18:40:45 +000018 assert Util.all_true(args, lambda x: isinstance(x, str))
Daniel Dunbar378530c2009-01-05 19:53:30 +000019 self.executable = executable
20 self.args = args
21
22 def __repr__(self):
23 return Util.prefixAndPPrint(self.__class__.__name__,
24 (self.executable, self.args))
25
Daniel Dunbarb421dba2009-01-07 18:40:45 +000026 def getArgv(self):
27 return [self.executable] + self.args
Daniel Dunbar378530c2009-01-05 19:53:30 +000028
29 def iterjobs(self):
30 yield self
31
32class PipedJob(Job):
33 """PipedJob - A sequence of piped commands."""
34
35 def __init__(self, commands):
Anders Carlssonc33fca92009-01-18 02:19:54 +000036 assert Util.all_true(commands, lambda x: isinstance(x, Arguments.Command))
Daniel Dunbar378530c2009-01-05 19:53:30 +000037 self.commands = list(commands)
38
39 def addJob(self, job):
40 assert isinstance(job, Command)
41 self.commands.append(job)
42
43 def __repr__(self):
44 return Util.prefixAndPPrint(self.__class__.__name__, (self.commands,))
45
46class JobList(Job):
47 """JobList - A sequence of jobs to perform."""
48
49 def __init__(self, jobs=[]):
50 self.jobs = list(jobs)
51
52 def addJob(self, job):
53 self.jobs.append(job)
54
55 def __repr__(self):
56 return Util.prefixAndPPrint(self.__class__.__name__, (self.jobs,))
57
58 def iterjobs(self):
59 for j in self.jobs:
60 yield j