Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
pipes.Template Class Reference

List of all members.

Public Member Functions

def __init__
def __repr__
def reset
def clone
def debug
def append
def prepend
def open
def open_r
def open_w
def copy
def makepipeline

Public Attributes

 debugging
 steps

Detailed Description

Class representing a pipeline template.

Definition at line 82 of file pipes.py.


Constructor & Destructor Documentation

def pipes.Template.__init__ (   self)
Template() returns a fresh pipeline template.

Definition at line 85 of file pipes.py.

00085 
00086     def __init__(self):
00087         """Template() returns a fresh pipeline template."""
00088         self.debugging = 0
00089         self.reset()

Here is the caller graph for this function:


Member Function Documentation

def pipes.Template.__repr__ (   self)
t.__repr__() implements repr(t).

Definition at line 90 of file pipes.py.

00090 
00091     def __repr__(self):
00092         """t.__repr__() implements repr(t)."""
00093         return '<Template instance, steps=%r>' % (self.steps,)

def pipes.Template.append (   self,
  cmd,
  kind 
)
t.append(cmd, kind) adds a new step at the end.

Definition at line 110 of file pipes.py.

00110 
00111     def append(self, cmd, kind):
00112         """t.append(cmd, kind) adds a new step at the end."""
00113         if type(cmd) is not type(''):
00114             raise TypeError('Template.append: cmd must be a string')
00115         if kind not in stepkinds:
00116             raise ValueError('Template.append: bad kind %r' % (kind,))
00117         if kind == SOURCE:
00118             raise ValueError('Template.append: SOURCE can only be prepended')
00119         if self.steps and self.steps[-1][1] == SINK:
00120             raise ValueError('Template.append: already ends with SINK')
00121         if kind[0] == 'f' and not re.search(r'\$IN\b', cmd):
00122             raise ValueError('Template.append: missing $IN in cmd')
00123         if kind[1] == 'f' and not re.search(r'\$OUT\b', cmd):
00124             raise ValueError('Template.append: missing $OUT in cmd')
00125         self.steps.append((cmd, kind))

Here is the call graph for this function:

Here is the caller graph for this function:

def pipes.Template.clone (   self)
t.clone() returns a new pipeline template with identical
initial state as the current one.

Definition at line 98 of file pipes.py.

00098 
00099     def clone(self):
00100         """t.clone() returns a new pipeline template with identical
00101         initial state as the current one."""
00102         t = Template()
00103         t.steps = self.steps[:]
00104         t.debugging = self.debugging
00105         return t

def pipes.Template.copy (   self,
  infile,
  outfile 
)

Definition at line 170 of file pipes.py.

00170 
00171     def copy(self, infile, outfile):
00172         return os.system(self.makepipeline(infile, outfile))

Here is the call graph for this function:

def pipes.Template.debug (   self,
  flag 
)
t.debug(flag) turns debugging on or off.

Definition at line 106 of file pipes.py.

00106 
00107     def debug(self, flag):
00108         """t.debug(flag) turns debugging on or off."""
00109         self.debugging = flag

def pipes.Template.makepipeline (   self,
  infile,
  outfile 
)

Definition at line 173 of file pipes.py.

00173 
00174     def makepipeline(self, infile, outfile):
00175         cmd = makepipeline(infile, self.steps, outfile)
00176         if self.debugging:
00177             print(cmd)
00178             cmd = 'set -x; ' + cmd
00179         return cmd
00180 

Here is the caller graph for this function:

def pipes.Template.open (   self,
  file,
  rw 
)
t.open(file, rw) returns a pipe or file object open for
reading or writing; the file is the other end of the pipeline.

Definition at line 142 of file pipes.py.

00142 
00143     def open(self, file, rw):
00144         """t.open(file, rw) returns a pipe or file object open for
00145         reading or writing; the file is the other end of the pipeline."""
00146         if rw == 'r':
00147             return self.open_r(file)
00148         if rw == 'w':
00149             return self.open_w(file)
00150         raise ValueError('Template.open: rw must be \'r\' or \'w\', not %r'
00151                          % (rw,))

Here is the call graph for this function:

def pipes.Template.open_r (   self,
  file 
)
t.open_r(file) and t.open_w(file) implement
t.open(file, 'r') and t.open(file, 'w') respectively.

Definition at line 152 of file pipes.py.

00152 
00153     def open_r(self, file):
00154         """t.open_r(file) and t.open_w(file) implement
00155         t.open(file, 'r') and t.open(file, 'w') respectively."""
00156         if not self.steps:
00157             return open(file, 'r')
00158         if self.steps[-1][1] == SINK:
00159             raise ValueError('Template.open_r: pipeline ends width SINK')
00160         cmd = self.makepipeline(file, '')
00161         return os.popen(cmd, 'r')

Here is the call graph for this function:

Here is the caller graph for this function:

def pipes.Template.open_w (   self,
  file 
)

Definition at line 162 of file pipes.py.

00162 
00163     def open_w(self, file):
00164         if not self.steps:
00165             return open(file, 'w')
00166         if self.steps[0][1] == SOURCE:
00167             raise ValueError('Template.open_w: pipeline begins with SOURCE')
00168         cmd = self.makepipeline('', file)
00169         return os.popen(cmd, 'w')

Here is the call graph for this function:

Here is the caller graph for this function:

def pipes.Template.prepend (   self,
  cmd,
  kind 
)
t.prepend(cmd, kind) adds a new step at the front.

Definition at line 126 of file pipes.py.

00126 
00127     def prepend(self, cmd, kind):
00128         """t.prepend(cmd, kind) adds a new step at the front."""
00129         if type(cmd) is not type(''):
00130             raise TypeError('Template.prepend: cmd must be a string')
00131         if kind not in stepkinds:
00132             raise ValueError('Template.prepend: bad kind %r' % (kind,))
00133         if kind == SINK:
00134             raise ValueError('Template.prepend: SINK can only be appended')
00135         if self.steps and self.steps[0][1] == SOURCE:
00136             raise ValueError('Template.prepend: already begins with SOURCE')
00137         if kind[0] == 'f' and not re.search(r'\$IN\b', cmd):
00138             raise ValueError('Template.prepend: missing $IN in cmd')
00139         if kind[1] == 'f' and not re.search(r'\$OUT\b', cmd):
00140             raise ValueError('Template.prepend: missing $OUT in cmd')
00141         self.steps.insert(0, (cmd, kind))

Here is the call graph for this function:

def pipes.Template.reset (   self)
t.reset() restores a pipeline template to its initial state.

Definition at line 94 of file pipes.py.

00094 
00095     def reset(self):
00096         """t.reset() restores a pipeline template to its initial state."""
00097         self.steps = []

Here is the caller graph for this function:


Member Data Documentation

Definition at line 87 of file pipes.py.

Definition at line 96 of file pipes.py.


The documentation for this class was generated from the following file: