1'''! Utilities for manipulating and searching text strings. '''
106 for i
in range(len(line)):
117 self.
fields.append(line[begin:end])
123 self.
fields.append(line[begin:])
133 for i
in range(self.
size):
196 print(
'RecordEditor is not ready')
199 oldfile = open(filename,
'r')
200 lines = oldfile.readlines()
205 newfile = open (filename,
'w')
212 newfile.write(str(record) +
'\n')
233 line = file.readline()
234 groups = line.strip().split(
'=')
235 if groups[0].strip() != label:
236 print(
'Error: Expected label = ' + label)
237 print(
' : Found = ' + groups[0].strip())
240 print(
'Error: More than one = sign in line')
245 return groups[1].strip()
267 groups = line.split(
' ')
268 for i
in range(len(groups)):
270 list.append(groups[i])
299 self.
filters.append(re.compile(filter))
316 file = open(filename,
'r')
317 lines = file.readlines()
323 if (self.
filters[i].search(line)):
370 self.
filter = re.compile(filter)
428 print(
'FileEditor is not ready')
431 oldfile = open(filename,
'r')
432 lines = oldfile.readlines()
437 newfile = open (filename,
'w')
440 if (self.
filter.search(line)):
445 line = re.sub(self.
old, self.
new, line);
460 print(
'FileEditor is not ready')
463 oldfile = open(filename,
'r')
464 lines = oldfile.readlines()
469 newfile = open (filename,
'w')
473 block = join(lines[i:i + self.
blockSize],
'')
474 if (self.
filter.search(block)):
479 block = re.sub(self.
old, self.
new, block)
481 if (block[-1] ==
'\n'):
483 list = split(block,
'\n')
484 for j
in range(len(list)):
485 list[j] = list[j] +
'\n'
500 print(
'FileEditor is not ready')
503 filenames = dir.filenames(pattern)
504 for filename
in filenames:
Class that represents a directory.
Class to substitute text in one or more files.
def __init__(self)
Constructor.
def setIsTest(self, isTest)
Set the isTest boolean flag.
def setNew(self, new)
Set the new string (the replacement string)
def setOld(self, old)
Set the old string (the string to be replaced)
def setFilter(self, filter)
Set the filter string.
def editFile(self, filename)
Edit a single file - edits confined to individual lines.
def editFiles(self, dirName, pattern)
Edit all files in specified directory that matches a pattern.
def setBlockSize(self, blockSize)
Set the blockSize attribute.
def editFileBlocks(self, filename)
Edit a single file - edits may span several lines.
Class to search for text in a file.
def grep(self, filename)
Search for lines in the file that match any filter.
def clearResults(self)
Clear results list (but not filters)
def addFilter(self, filter)
Add a regular expression string to the list.
def __init__(self)
Constructor.
Class to modify selected Records in a file of records.
def editFile(self, filename)
Open and edit the specified file of records.
def setNew(self, new, field)
Set new string.
def setIsTest(self, isTest)
Set isTest flag, to decide whether to perform a dry run.
def __init__(self)
Constructor.
def setFilter(self, filter, field=0)
Set filter string.
A Record represents a string of fields separated by whitespace.
def __init__(self, line)
Constructor.
def __str__(self)
String representation - line from which Record was constructed.
Class to wrap line breaks.
def clear(self)
Clear mutable attributes (column and text).
def __repr__(self)
Return string containing wrapped text (self.text).
def __init__(self, eol='\n', nIndent=0)
Constructor.
def __str__(self)
Return string containing wrapped text (self.text).
def append(self, string)
Add contents of string to wrapped text.
Utilities for manipulating files and paths.
def readLabelledList(file, label)
Read line of form "label = string", in which string may contains spaces.
def readLabelledLine(file, label)
Read a line of the form "label = string", return string.