Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
Template Class Reference

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
 

Data Fields

 debugging
 
 steps
 

Detailed Description

Class representing a pipeline template.

Definition at line 83 of file pipes.py.

Constructor & Destructor Documentation

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

Definition at line 86 of file pipes.py.

86 
87  def __init__(self):
88  """Template() returns a fresh pipeline template."""
89  self.debugging = 0
90  self.reset()

Member Function Documentation

def __repr__ (   self)
t.__repr__() implements `t`.

Definition at line 91 of file pipes.py.

91 
92  def __repr__(self):
93  """t.__repr__() implements `t`."""
94  return '<Template instance, steps=' + `self.steps` + '>'
def append (   self,
  cmd,
  kind 
)
t.append(cmd, kind) adds a new step at the end.

Definition at line 111 of file pipes.py.

112  def append(self, cmd, kind):
113  """t.append(cmd, kind) adds a new step at the end."""
114  if type(cmd) is not type(''):
115  raise TypeError, \
116  'Template.append: cmd must be a string'
117  if kind not in stepkinds:
118  raise ValueError, \
119  'Template.append: bad kind ' + `kind`
120  if kind == SOURCE:
121  raise ValueError, \
122  'Template.append: SOURCE can only be prepended'
123  if self.steps and self.steps[-1][1] == SINK:
124  raise ValueError, \
125  'Template.append: already ends with SINK'
126  if kind[0] == 'f' and not re.search(r'\$IN\b', cmd):
127  raise ValueError, \
128  'Template.append: missing $IN in cmd'
129  if kind[1] == 'f' and not re.search(r'\$OUT\b', cmd):
130  raise ValueError, \
131  'Template.append: missing $OUT in cmd'
132  self.steps.append((cmd, kind))
def clone (   self)
t.clone() returns a new pipeline template with identical
initial state as the current one.

Definition at line 99 of file pipes.py.

99 
100  def clone(self):
101  """t.clone() returns a new pipeline template with identical
102  initial state as the current one."""
103  t = Template()
104  t.steps = self.steps[:]
105  t.debugging = self.debugging
106  return t
def copy (   self,
  infile,
  outfile 
)

Definition at line 185 of file pipes.py.

References Template.makepipeline().

186  def copy(self, infile, outfile):
187  return os.system(self.makepipeline(infile, outfile))
def debug (   self,
  flag 
)
t.debug(flag) turns debugging on or off.

Definition at line 107 of file pipes.py.

108  def debug(self, flag):
109  """t.debug(flag) turns debugging on or off."""
110  self.debugging = flag
def makepipeline (   self,
  infile,
  outfile 
)

Definition at line 188 of file pipes.py.

References Template.debugging, FTP.debugging, NNTP.debugging, and Template.steps.

189  def makepipeline(self, infile, outfile):
190  cmd = makepipeline(infile, self.steps, outfile)
191  if self.debugging:
192  print cmd
193  cmd = 'set -x; ' + cmd
194  return cmd
195 
def 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 155 of file pipes.py.

References Template.open_r(), and Template.open_w().

156  def open(self, file, rw):
157  """t.open(file, rw) returns a pipe or file object open for
158  reading or writing; the file is the other end of the pipeline."""
159  if rw == 'r':
160  return self.open_r(file)
161  if rw == 'w':
162  return self.open_w(file)
163  raise ValueError, \
164  'Template.open: rw must be \'r\' or \'w\', not ' + `rw`
def 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 165 of file pipes.py.

References Template.makepipeline(), and Template.steps.

166  def open_r(self, file):
167  """t.open_r(file) and t.open_w(file) implement
168  t.open(file, 'r') and t.open(file, 'w') respectively."""
169  if not self.steps:
170  return open(file, 'r')
171  if self.steps[-1][1] == SINK:
172  raise ValueError, \
173  'Template.open_r: pipeline ends width SINK'
174  cmd = self.makepipeline(file, '')
175  return os.popen(cmd, 'r')
def open_w (   self,
  file 
)

Definition at line 176 of file pipes.py.

References Template.makepipeline(), Template.open(), and Template.steps.

177  def open_w(self, file):
178  if not self.steps:
179  return open(file, 'w')
180  if self.steps[0][1] == SOURCE:
181  raise ValueError, \
182  'Template.open_w: pipeline begins with SOURCE'
183  cmd = self.makepipeline('', file)
184  return os.popen(cmd, 'w')
def prepend (   self,
  cmd,
  kind 
)
t.prepend(cmd, kind) adds a new step at the front.

Definition at line 133 of file pipes.py.

134  def prepend(self, cmd, kind):
135  """t.prepend(cmd, kind) adds a new step at the front."""
136  if type(cmd) is not type(''):
137  raise TypeError, \
138  'Template.prepend: cmd must be a string'
139  if kind not in stepkinds:
140  raise ValueError, \
141  'Template.prepend: bad kind ' + `kind`
142  if kind == SINK:
143  raise ValueError, \
144  'Template.prepend: SINK can only be appended'
145  if self.steps and self.steps[0][1] == SOURCE:
146  raise ValueError, \
147  'Template.prepend: already begins with SOURCE'
148  if kind[0] == 'f' and not re.search(r'\$IN\b', cmd):
149  raise ValueError, \
150  'Template.prepend: missing $IN in cmd'
151  if kind[1] == 'f' and not re.search(r'\$OUT\b', cmd):
152  raise ValueError, \
153  'Template.prepend: missing $OUT in cmd'
154  self.steps.insert(0, (cmd, kind))
def reset (   self)
t.reset() restores a pipeline template to its initial state.

Definition at line 95 of file pipes.py.

95 
96  def reset(self):
97  """t.reset() restores a pipeline template to its initial state."""
98  self.steps = []

Field Documentation

debugging

Definition at line 88 of file pipes.py.

steps

Definition at line 97 of file pipes.py.


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