def livePatch(url): '''At this point weasel has started and the scripted install is parsing the .ks file. It is making calls to livePatch with URLs destined for weasel. It will only replace modules in the local directory. ''' from os import path from urlparse import urlparse import remote_files parsed = urlparse(url) remotePath = parsed[2] fileName = path.basename(remotePath) moduleName = path.splitext(fileName)[0] localPath = path.join(path.dirname(__file__), fileName) if not path.exists(localPath): log.error('Cannot install-patch a module that does not exist') return remoteFp = remote_files.remoteOpen(url) content = remoteFp.read() localFp = file(localPath, 'w') log.info('Replacing %s with new content' % localPath) localFp.write(content) localFp.close() log.info('Reloading module %s' % moduleName) module = __import__(moduleName, globals()) reload(module) if hasattr(module, 'postPatchAction'): module.postPatchAction()
def __init__(self, fileName): self.fileName = fileName if remote_files.isURL(self.fileName): fp = remote_files.remoteOpen(self.fileName) self.lines = fp.readlines() else: self.lines = open(fileName).readlines() self.lines = [line.replace('\r\n', '\n') for line in self.lines] self.index = -1 self.keyWords = '^(%post|%pre|%packages|%vmlicense_text)'