/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes
DybPython::Include::Include Class Reference

List of all members.

Public Member Functions

def __init__
def setShowIncludes
def __call__
def block
def unblock

Static Public Attributes

int fid = 0

Private Member Functions

def _doTrace
def _trace_include
def _oneline

Private Attributes

 _show
 _once
 _fcurrent

Detailed Description

Definition at line 75 of file Include.py.


Constructor & Destructor Documentation

def DybPython::Include::Include::__init__ (   self,
  show = 1 
)

Definition at line 78 of file Include.py.

00079                                  :
00080       self._show = show
00081       self._once = []
00082       self._fcurrent = ''


Member Function Documentation

def DybPython::Include::Include::setShowIncludes (   self,
  show 
)

Definition at line 83 of file Include.py.

00084                                     :
00085       self._show = show

def DybPython::Include::Include::__call__ (   self,
  fn,
  args,
  kw 
)
Include <fn> in the current scope by executing it globally.

Definition at line 86 of file Include.py.

00087                                         :
00088       """Include <fn> in the current scope by executing it globally."""
00089 
00090     # don't include file if not allowed (has to be exact match in py code)
00091       if fn in self._once:
00092          log.debug( 'file "%s" is blocked; not included', fn )
00093          return
00094 
00095     # locate the file
00096       name = FindFile( os.path.expanduser( os.path.expandvars( fn ) ), optionsPath, os.R_OK )
00097       if not name:
00098          name = FindFile( os.path.basename( fn ), optionsPath, os.R_OK )
00099          if name:
00100             log.warning( 'using %s instead of %s', name, fn )
00101          else:
00102             raise IncludeError( 'include file %s can not be found' % fn )
00103 
00104       log.debug( 'located %s as %s', fn, name )
00105 
00106     # print if 'show' is set to non-null
00107       show = self._show
00108       if 'show' in kw:
00109          show = kw[ 'show' ]
00110 
00111     # notify of start of file inclusion
00112       if show:
00113          log.info( 'including file "%s" with ID %d', fn, self.fid )
00114       else:
00115          log.info( 'including file "%s"', fn )
00116       self._fcurrent = name
00117 
00118     # actual inclusion
00119       if show and self._doTrace( name ):
00120        # traced
00121          _filecache[ name ] = open( name, 'r' ).readlines()
00122          _linecache[ name ] = 0, self.fid
00123          self.fid += 1
00124   
00125          sys.settrace( self._trace_include )
00126          execfile( name, __main__.__dict__, __main__.__dict__ )
00127          sys.settrace( sys._getframe(0).f_trace )
00128 
00129        # finish file printout
00130          ncur, fid = _linecache[ name ]
00131          buf  = _filecache[ name ]
00132          for i in range( ncur, len(buf) ):
00133             self._oneline( fid, i, silentMarker, buf )
00134 
00135          del _filecache[ name ]
00136          del _linecache[ name ]
00137 
00138          log.info( 'end of "%s"', fn )
00139 
00140       else:
00141        # non-traced
00142          execfile( name, __main__.__dict__, __main__.__dict__ )

def DybPython::Include::Include::block (   self,
  fn 
)
Disallow the given filename(s) from being included again.

Definition at line 143 of file Include.py.

00144                         :
00145       """Disallow the given filename(s) from being included again."""
00146 
00147       if type(fn) == list:
00148          self._once += fn
00149       else:
00150          self._once.append( fn )

def DybPython::Include::Include::unblock (   self,
  fn 
)
Re-allow the given filename from being included.

Definition at line 151 of file Include.py.

00152                           :
00153       """Re-allow the given filename from being included."""
00154 
00155       self._once.remove( fn )

def DybPython::Include::Include::_doTrace (   self,
  fn 
) [private]

Definition at line 157 of file Include.py.

00158                            :
00159     # Tracing into non-included files is controlled with two variables:
00160     # excludeTracePattern and includeTracePattern. The former goes first,
00161     # the latter can override any excluded results.
00162 
00163       if fn in _notrcache:
00164          return False
00165 
00166       doTrace = True
00167       for tracePattern in excludeTracePattern:
00168          if fnmatch.fnmatch( fn, tracePattern ):
00169             doTrace = False
00170             break
00171 
00172       if not doTrace:
00173          for tracePattern in includeTracePattern:
00174             if fnmatch.fnmatch( fn, tracePattern ):
00175                doTrace = True
00176                break
00177 
00178       if not os.path.exists( fn ):
00179          doTrace = False
00180 
00181       if not doTrace:
00182          _notrcache[ fn ] = 1
00183 
00184       return doTrace

def DybPython::Include::Include::_trace_include (   self,
  frame,
  event,
  arg 
) [private]

Definition at line 186 of file Include.py.

00187                                                 :
00188       fn  = frame.f_code.co_filename
00189 
00190       if not self._doTrace( fn ):
00191          return self._trace_include
00192 
00193       if not _filecache.has_key( fn ):
00194        # wait until importing of the module is done to minimize pollution
00195          f = frame.f_back
00196          while f is not None:
00197             try:
00198                if 'import' in _filecache[ f.f_code.co_filename ][ f.f_lineno ]:
00199                   return self._trace_include
00200             except:
00201                pass
00202             f = f.f_back
00203          del f
00204 
00205        # import is done, and we're back, accept this file from this point on
00206          _filecache[ fn ] = open( fn, 'r' ).readlines() or '\n'
00207          _linecache[ fn ] = sys.maxint, self.fid
00208          self.fid += 1
00209 
00210       lno = frame.f_lineno
00211       aln = lno - 1 > 0 and lno - 1 or 0
00212 
00213       ncur, fid = _linecache[ fn ]
00214       buf = _filecache[ fn ]
00215 
00216       if self._fcurrent != fn:
00217          log.info( 'continued trace of "%s"', basename2( fn ) )
00218          self._fcurrent = fn
00219 
00220       if event == 'line':
00221          for i in range( ncur, aln ):
00222             self._oneline( fid, i, silentMarker, buf )
00223 
00224          if ncur <= aln:
00225             self._oneline( fid, aln, activeMarker, buf )
00226          elif 0 <= aln:
00227             self._oneline( fid, aln, tracedMarker, buf )
00228 
00229          if ncur < lno:
00230             _linecache[ fn ] = lno, fid
00231 
00232       elif event == 'call':
00233          if lno < ncur:
00234             self._oneline( fid, aln, callMarker, buf )
00235 
00236       elif event == 'return':
00237          if lno < ncur:
00238             fln = frame.f_code.co_firstlineno - 1
00239             self._oneline( fid, fln, returnMarker, None )
00240 
00241       return self._trace_include

def DybPython::Include::Include::_oneline (   self,
  fid,
  lineno,
  detail,
  buf 
) [private]

Definition at line 243 of file Include.py.

00244                                                  :
00245       print marker, fidMarker % fid, lineMarker % lineno, detail,
00246 
00247     # simple eol case
00248       if not buf or not buf[ lineno ]:
00249          print
00250          return
00251 
00252     # in general, an interpreter "line" may be longer than a file line
00253       line = buf[ lineno ].rstrip()
00254       while line and ( line[-1] == '(' or line[-1] == '\\' ):
00255        # this line appears to have a continuation ...
00256          try:
00257           # output traced line
00258             print line
00259 
00260           # output continued line
00261             lineno += 1
00262             print marker, fidMarker % fid, lineMarker % lineno, detail,
00263             line = buf[ lineno ].rstrip()
00264          except IndexError:
00265           # shouldn't happen; but must mean that the diagnosis above is
00266           # wrong and that there is no continuation, keep silent
00267             break
00268 
00269       print line
00270 
# use this for backward compatibility

Member Data Documentation

Definition at line 76 of file Include.py.

Definition at line 78 of file Include.py.

Definition at line 78 of file Include.py.

Definition at line 78 of file Include.py.


The documentation for this class was generated from the following file:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:55:41 for DybPython by doxygen 1.7.4