blob: 1c077caa8ee0dc47834dcdba543c9e3ddf11a956 [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
12 process."""
13
14 def __init__(self, executable, args):
15 assert Util.all_true(args, lambda x: isinstance(x, Arguments.Arg))
16 self.executable = executable
17 self.args = args
18
19 def __repr__(self):
20 return Util.prefixAndPPrint(self.__class__.__name__,
21 (self.executable, self.args))
22
23 def render(self, args):
24 argv = [self.executable]
Daniel Dunbar74727872009-01-06 01:35:44 +000025 for arg in self.args:
Daniel Dunbar9d32bcd2009-01-07 01:29:28 +000026 argv.extend(args.render(arg))
Daniel Dunbar378530c2009-01-05 19:53:30 +000027 return argv
28
29 def iterjobs(self):
30 yield self
31
32class PipedJob(Job):
33 """PipedJob - A sequence of piped commands."""
34
35 def __init__(self, commands):
36 assert all_true(args, lambda x: isinstance(x, Arguments.Command))
37 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