def _remoteFileAppendContents(self, filename, data): data = Util.escapeDoubleQuotes(data, times=4) rc, output = self._nodeShell('"echo \\"%s\\" >> %s"' % (data, filename), withOutput=True, shell=True) if rc != 0: Util.printError("Failed to append to %s\n%s" % (filename, output))
def _remoteAppendOrReplaceInFile(self, filename, search, replace): res = self._nodeShell(['grep', '"%s"'%search, filename]) replace = Util.escapeDoubleQuotes(replace) if self._patternExists(res): rc, output = self._nodeShell('"sed -i \'s|%s|%s|\' %s"' % (search, replace, filename), withOutput=True, shell=True) if rc != 0: Util.printError("Failed to modify %s.\n%s" % (filename, output)) else: self._remoteFileAppendContents(filename, replace)