Esempio n. 1
0
 def replaceInFile(self, fileName, replaceMethod, *args):
     newFileName = fileName + ".tmp"
     newFile = encodingutils.openEncoded(newFileName, "w")
     for i, line in enumerate(encodingutils.openEncoded(fileName)):
         newLine = replaceMethod(line, i, *args)
         if newLine:
             newFile.write(newLine)
     newFile.close()
     shutil.move(newFileName, fileName)
Esempio n. 2
0
 def __init__(self, scriptName, ignoreComments=False):
     self.commands = []
     self.exitObservers = []
     self.pointer = 0
     self.name = scriptName
     if not os.path.isfile(scriptName):
         raise UseCaseScriptError, "Cannot replay script " + repr(scriptName) + ", no such file or directory."
     for line in encodingutils.openEncoded(scriptName):
         line = line.strip("\r\n")
         if not ignoreComments or (line != "" and line[0] != "#"):
             self.commands.append(line)
Esempio n. 3
0
 def _record(self, line):
     if not self.fileForAppend:
         self.fileForAppend = encodingutils.openEncoded(self.scriptName, "w")
     # File is in binary mode, must use correct line ending explicitly, "\n" will be UNIX line endings on all platforms
     self.fileForAppend.write(line + os.linesep)
     self.fileForAppend.flush()
Esempio n. 4
0
 def getAllCommands(self): 
     return [ line.strip() for line in encodingutils.openEncoded(self.fileName) ]