aboutsummaryrefslogtreecommitdiff
path: root/tools/ccc/ccclib/Jobs.py
blob: 48d97db4a70536e3280faf6ed2a627230127171a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import Arguments
import Util

class Job(object):
    """Job - A set of commands to execute as a single task."""

    def iterjobs(self):
        abstract

class Command(Job):
    """Command - Represent the information needed to execute a single
    process.
    
    This currently assumes that the executable will always be the
    first argument."""

    def __init__(self, executable, args):
        assert Util.all_true(args, lambda x: isinstance(x, str))
        self.executable = executable
        self.args = args

    def __repr__(self):
        return Util.prefixAndPPrint(self.__class__.__name__,
                                    (self.executable, self.args))
    
    def getArgv(self):
        return [self.executable] + self.args

    def iterjobs(self):
        yield self
    
class PipedJob(Job):
    """PipedJob - A sequence of piped commands."""

    def __init__(self, commands):
        assert all_true(args, lambda x: isinstance(x, Arguments.Command))
        self.commands = list(commands)

    def addJob(self, job):
        assert isinstance(job, Command)
        self.commands.append(job)

    def __repr__(self):
        return Util.prefixAndPPrint(self.__class__.__name__, (self.commands,))

class JobList(Job):
    """JobList - A sequence of jobs to perform."""

    def __init__(self, jobs=[]):
        self.jobs = list(jobs)
    
    def addJob(self, job):
        self.jobs.append(job)

    def __repr__(self):
        return Util.prefixAndPPrint(self.__class__.__name__, (self.jobs,))

    def iterjobs(self):
        for j in self.jobs:
            yield j