class Patchfile: """ A single patchfile for a package. """ def __init__(self, package): self.package = package self.packageName = package.packageName self.platform = package.platform self.version = package.version self.hostUrl = None # FileSpec for the patchfile itself self.file = None # FileSpec for the package file that the patch is applied to self.sourceFile = None # FileSpec for the package file that the patch generates self.targetFile = None # The PackageVersion corresponding to our sourceFile self.fromPv = None # The PackageVersion corresponding to our targetFile self.toPv = None def getSourceKey(self): """ Returns the key for locating the package that this patchfile can be applied to. """ return (self.packageName, self.platform, self.version, self.hostUrl, self.sourceFile) def getTargetKey(self): """ Returns the key for locating the package that this patchfile will generate. """ return (self.packageName, self.platform, self.version, self.hostUrl, self.targetFile) def fromFile(self, packageDir, patchFilename, sourceFile, targetFile): """ Creates the data structures from an existing patchfile on disk. """ self.file = FileSpec() self.file.fromFile(packageDir, patchFilename) self.sourceFile = sourceFile self.targetFile = targetFile def loadXml(self, xpatch): """ Reads the data structures from an xml file. """ self.packageName = xpatch.Attribute('name') or self.packageName self.platform = xpatch.Attribute('platform') or self.platform self.version = xpatch.Attribute('version') or self.version self.hostUrl = xpatch.Attribute('host') or self.hostUrl self.file = FileSpec() self.file.loadXml(xpatch) xsource = xpatch.FirstChildElement('source') if xsource: self.sourceFile = FileSpec() self.sourceFile.loadXml(xsource) xtarget = xpatch.FirstChildElement('target') if xtarget: self.targetFile = FileSpec() self.targetFile.loadXml(xtarget) def makeXml(self, package): xpatch = TiXmlElement('patch') if self.packageName != package.packageName: xpatch.SetAttribute('name', self.packageName) if self.platform != package.platform: xpatch.SetAttribute('platform', self.platform) if self.version != package.version: xpatch.SetAttribute('version', self.version) if self.hostUrl != package.hostUrl: xpatch.SetAttribute('host', self.hostUrl) self.file.storeXml(xpatch) xsource = TiXmlElement('source') self.sourceFile.storeMiniXml(xsource) xpatch.InsertEndChild(xsource) xtarget = TiXmlElement('target') self.targetFile.storeMiniXml(xtarget) xpatch.InsertEndChild(xtarget) return xpatch