Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 1 | import Arguments |
| 2 | import Util |
| 3 | |
| 4 | class Job(object): |
| 5 | """Job - A set of commands to execute as a single task.""" |
| 6 | |
| 7 | def iterjobs(self): |
| 8 | abstract |
| 9 | |
| 10 | class Command(Job): |
| 11 | """Command - Represent the information needed to execute a single |
Daniel Dunbar | b421dba | 2009-01-07 18:40:45 +0000 | [diff] [blame] | 12 | process. |
| 13 | |
| 14 | This currently assumes that the executable will always be the |
| 15 | first argument.""" |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 16 | |
| 17 | def __init__(self, executable, args): |
Daniel Dunbar | b421dba | 2009-01-07 18:40:45 +0000 | [diff] [blame] | 18 | assert Util.all_true(args, lambda x: isinstance(x, str)) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 19 | 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 Dunbar | b421dba | 2009-01-07 18:40:45 +0000 | [diff] [blame] | 26 | def getArgv(self): |
| 27 | return [self.executable] + self.args |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 28 | |
| 29 | def iterjobs(self): |
| 30 | yield self |
| 31 | |
| 32 | class PipedJob(Job): |
| 33 | """PipedJob - A sequence of piped commands.""" |
| 34 | |
| 35 | def __init__(self, commands): |
Anders Carlsson | c33fca9 | 2009-01-18 02:19:54 +0000 | [diff] [blame^] | 36 | assert Util.all_true(commands, lambda x: isinstance(x, Arguments.Command)) |
Daniel Dunbar | 378530c | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 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 | |
| 46 | class 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 |