def _runPyPatch(self, srcDir, patchDir): """ As python doesn't keep open python files, it is trivial to patch a running python file. Unpack the patch, extract and then restart the application """ try: patchdiff.applyPatchDirectory(srcDir, patchDir) except patchdiff.PatchError: self._setBroken() raise BrokenError(('There was an error patching.' + ' See patcherr.log for more information')) self._removeCfgFile() shutil.rmtree(patchDir) os.spawnlp(sys.executable, sys.executable, *sys.argv) sys.exit()
def _finishFrozenPatch(self): cfg = _jsonFromFile(self.cfgPath) oldBin = cfg['oldbin'] srcDir = cfg['srcdir'] patchDir = cfg['patchdir'] try: patchdiff.applyPatchDirectory(srcDir, patchDir) except patchdiff.PatchError: self._setBroken() raise BrokenError(('There was an error patching.' + ' See patcherr.log for more information')) self._removeCfgFile() shutil.rmtree(patchDir) os.execlp(oldBin, oldBin) sys.exit()