Loading [MathJax]/extensions/TeX/AMSsymbols.js
PSCF v1.2
pscfpp.text.FileEditor Class Reference

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

Public Member Functions

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

Detailed Description

Class to substitute text in one or more files.

String attributes:

  • filter : a regex used to filter lines for possible editing
  • old : a regex pattern that should be replaced in lines
  • new : the string that should replace the old string

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__()

Member Function Documentation

◆ setFilter()

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.FileEditor.filter, pscfpp.text.RecordEditor.filter, pscfpp.text.FileEditor.hasFilter, pscfpp.text.RecordEditor.hasFilter, pscfpp.text.FileEditor.hasNew, pscfpp.text.RecordEditor.hasNew, pscfpp.text.FileEditor.hasOld, Pscf::PropagatorTmpl< TP >.isReady(), Pscf::PropagatorTmpl< Propagator >.isReady(), Pscf::PropagatorTmpl< Propagator< D > >.isReady(), pscfpp.text.FileEditor.isReady, and pscfpp.text.RecordEditor.isReady.

◆ setOld()

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

◆ setNew()

◆ setIsTest()

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.FileEditor.isTest, and pscfpp.text.RecordEditor.isTest.

◆ setBlockSize()

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()

◆ editFileBlocks()

◆ editFiles()

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(), Pscf::PropagatorTmpl< TP >.isReady(), Pscf::PropagatorTmpl< Propagator >.isReady(), Pscf::PropagatorTmpl< Propagator< D > >.isReady(), pscfpp.text.FileEditor.isReady, and pscfpp.text.RecordEditor.isReady.


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