4 def __init__(self, args, redirects):
6 self.redirects = list(redirects)
9 return 'Command(%r, %r)' % (self.args, self.redirects)
11 def __cmp__(self, other):
12 if not isinstance(other, Command):
15 return cmp((self.args, self.redirects),
16 (other.args, other.redirects))
18 def toShell(self, file):
22 elif '"' not in arg and '$' not in arg:
25 raise NotImplementedError,'Unable to quote %r' % arg
28 # For debugging / validation.
29 dequoted = list(ShUtil.ShLexer(quoted).lex())
31 raise NotImplementedError,'Unable to quote %r' % arg
33 for r in self.redirects:
35 print >>file, "%s '%s'" % (r[0][0], r[1]),
37 print >>file, "%s%s '%s'" % (r[0][1], r[0][0], r[1]),
40 def __init__(self, commands, negate=False, pipe_err=False):
41 self.commands = commands
43 self.pipe_err = pipe_err
46 return 'Pipeline(%r, %r, %r)' % (self.commands, self.negate,
49 def __cmp__(self, other):
50 if not isinstance(other, Pipeline):
53 return cmp((self.commands, self.negate, self.pipe_err),
54 (other.commands, other.negate, self.pipe_err))
56 def toShell(self, file, pipefail=False):
57 if pipefail != self.pipe_err:
58 raise ValueError,'Inconsistent "pipefail" attribute!'
61 for cmd in self.commands:
63 if cmd is not self.commands[-1]:
67 def __init__(self, lhs, op, rhs):
68 assert op in (';', '&', '||', '&&')
74 return 'Seq(%r, %r, %r)' % (self.lhs, self.op, self.rhs)
76 def __cmp__(self, other):
77 if not isinstance(other, Seq):
80 return cmp((self.lhs, self.op, self.rhs),
81 (other.lhs, other.op, other.rhs))
83 def toShell(self, file, pipefail=False):
84 self.lhs.toShell(file, pipefail)
85 print >>file, ' %s\n' % self.op
86 self.rhs.toShell(file, pipefail)