PSCF v1.2
|
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. | |
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.
pscfpp.text.FileEditor.__init__ | ( | self | ) |
Constructor.
Definition at line 352 of file text.py.
References pscfpp.text.FileEditor.blockSize, 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, pscfpp.text.RecordEditor.isReady, pscfpp.make.MakeMaker.isTest, pscfpp.text.FileEditor.isTest, and pscfpp.text.RecordEditor.isTest.
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.
filter | the 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.
pscfpp.text.FileEditor.setOld | ( | self, | |
old ) |
Set the old string (the string to be replaced)
The "old" string is replaced by the "new" string in lines that match the "filter" string.
old | the "old" string, to be replaced |
Definition at line 383 of file text.py.
References 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, pscfpp.text.RecordEditor.isReady, and pscfpp.text.FileEditor.old.
pscfpp.text.FileEditor.setNew | ( | self, | |
new ) |
Set the new string (the replacement string)
new | the "new" string that replaces the old string |
Definition at line 394 of file text.py.
References 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, pscfpp.text.RecordEditor.isReady, pscfpp.text.FileEditor.new, and pscfpp.text.RecordEditor.new.
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.
isTest | perform 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.
pscfpp.text.FileEditor.setBlockSize | ( | self, | |
blockSize ) |
Set the blockSize attribute.
blockSize | number of lines in block for editFileBlock |
Definition at line 417 of file text.py.
References pscfpp.text.FileEditor.blockSize.
pscfpp.text.FileEditor.editFile | ( | self, | |
filename ) |
Edit a single file - edits confined to individual lines.
filename | name of file to be edited |
Definition at line 425 of file text.py.
References pscfpp.text.FileEditor.filter, pscfpp.text.RecordEditor.filter, Pscf::PropagatorTmpl< TP >.isReady(), Pscf::PropagatorTmpl< Propagator >.isReady(), Pscf::PropagatorTmpl< Propagator< D > >.isReady(), pscfpp.text.FileEditor.isReady, pscfpp.text.RecordEditor.isReady, pscfpp.make.MakeMaker.isTest, pscfpp.text.FileEditor.isTest, pscfpp.text.RecordEditor.isTest, pscfpp.text.FileEditor.new, pscfpp.text.RecordEditor.new, and pscfpp.text.FileEditor.old.
pscfpp.text.FileEditor.editFileBlocks | ( | self, | |
filename ) |
Edit a single file - edits may span several lines.
filename | name of file to be edited |
Definition at line 457 of file text.py.
References pscfpp.text.FileEditor.blockSize, pscfpp.text.FileEditor.filter, pscfpp.text.RecordEditor.filter, Pscf::PropagatorTmpl< TP >.isReady(), Pscf::PropagatorTmpl< Propagator >.isReady(), Pscf::PropagatorTmpl< Propagator< D > >.isReady(), pscfpp.text.FileEditor.isReady, pscfpp.text.RecordEditor.isReady, pscfpp.make.MakeMaker.isTest, pscfpp.text.FileEditor.isTest, pscfpp.text.RecordEditor.isTest, pscfpp.text.FileEditor.new, pscfpp.text.RecordEditor.new, and pscfpp.text.FileEditor.old.
Referenced by pscfpp.text.FileEditor.editFiles().
pscfpp.text.FileEditor.editFiles | ( | self, | |
dirName, | |||
pattern ) |
Edit all files in specified directory that matches a pattern.
dirName | name of directory (string) |
pattern | filename 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.