PSCF v1.1
Public Member Functions | List of all members
pscfpp.text.FileEditor Class Reference

Class to substitute text in one or more files. More...

Public Member Functions

def __init__ (self)
 Constructor. More...
 
def setFilter (self, filter)
 Set the filter string. More...
 
def setOld (self, old)
 Set the old string (the string to be replaced) More...
 
def setNew (self, new)
 Set the new string (the replacement string) More...
 
def setIsTest (self, isTest)
 Set the isTest boolean flag. More...
 
def setBlockSize (self, blockSize)
 Set the blockSize attribute. More...
 
def editFile (self, filename)
 Edit a single file - edits confined to individual lines. More...
 
def editFileBlocks (self, filename)
 Edit a single file - edits may span several lines. More...
 
def editFiles (self, dirName, pattern)
 Edit all files in specified directory that matches a pattern. More...
 

Detailed Description

Class to substitute text in one or more files.

String attributes:

The editFile method checks each line in a specified file to see if it contains a string that matches the regular expression defined by the filter attribute. If a line matches the filter expression, it search for substrings that match the regular expression defined by the "old" attribute, and replaces each occurence by the string given by the "new" attribute.

The editFiles method applies the editFile method to every file in a specified directory tree with a name that matches a specified filename pattern.

Definition at line 347 of file text.py.

Constructor & Destructor Documentation

◆ __init__()

def pscfpp.text.FileEditor.__init__ (   self)

Member Function Documentation

◆ setFilter()

def pscfpp.text.FileEditor.setFilter (   self,
  filter 
)

Set the filter string.

Set the regular expression used to identify lines for possible modification - lines that match the filter are checked for a sub-string that matches the "old" string.

Parameters
filterthe new "filter" string

Definition at line 369 of file text.py.

References pscfpp.text.RecordEditor.filter, pscfpp.text.FileEditor.filter, pscfpp.text.RecordEditor.hasFilter, pscfpp.text.FileEditor.hasFilter, pscfpp.text.RecordEditor.hasNew, pscfpp.text.FileEditor.hasNew, pscfpp.text.FileEditor.hasOld, pscfpp.text.RecordEditor.isReady, pscfpp.text.FileEditor.isReady, Pscf::PropagatorTmpl< Propagator >.isReady(), Pscf::PropagatorTmpl< TP >.isReady(), and Pscf::PropagatorTmpl< Propagator< D > >.isReady().

◆ setOld()

def pscfpp.text.FileEditor.setOld (   self,
  old 
)

◆ setNew()

def pscfpp.text.FileEditor.setNew (   self,
  new 
)

◆ setIsTest()

def pscfpp.text.FileEditor.setIsTest (   self,
  isTest 
)

Set the isTest boolean flag.

If isTest is true, the edit functions only perform a dry run in which they report what changes would be made if isTest were false.

Parameters
isTestperform a dry run (no changes) if true (boolean)

Definition at line 409 of file text.py.

References pscfpp.make.MakeMaker.isTest, pscfpp.text.RecordEditor.isTest, and pscfpp.text.FileEditor.isTest.

◆ setBlockSize()

def pscfpp.text.FileEditor.setBlockSize (   self,
  blockSize 
)

Set the blockSize attribute.

Parameters
blockSizenumber of lines in block for editFileBlock

Definition at line 417 of file text.py.

References pscfpp.text.FileEditor.blockSize.

◆ editFile()

def pscfpp.text.FileEditor.editFile (   self,
  filename 
)

◆ editFileBlocks()

def pscfpp.text.FileEditor.editFileBlocks (   self,
  filename 
)

◆ editFiles()

def pscfpp.text.FileEditor.editFiles (   self,
  dirName,
  pattern 
)

Edit all files in specified directory that matches a pattern.

Parameters
dirNamename of directory (string)
patternfilename pattern (string)

Definition at line 498 of file text.py.

References pscfpp.text.FileEditor.editFileBlocks(), pscfpp.text.RecordEditor.isReady, pscfpp.text.FileEditor.isReady, Pscf::PropagatorTmpl< Propagator< D > >.isReady(), Pscf::PropagatorTmpl< Propagator >.isReady(), and Pscf::PropagatorTmpl< TP >.isReady().


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