From 1fc186bda4bc3d58f15bcccd4afbad321ee0bbb4 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 26 Aug 2009 05:04:15 +0000 Subject: [PATCH] move to within the --- direct/src/p3d/PackageInfo.py | 8 ++- direct/src/p3d/Packager.py | 108 +++++++++++++++++++++++------- direct/src/plugin/p3dInstance.cxx | 8 ++- direct/src/plugin/p3dPackage.cxx | 13 ++-- 4 files changed, 102 insertions(+), 35 deletions(-) diff --git a/direct/src/p3d/PackageInfo.py b/direct/src/p3d/PackageInfo.py index 285f49966e..883c07d7d9 100644 --- a/direct/src/p3d/PackageInfo.py +++ b/direct/src/p3d/PackageInfo.py @@ -146,8 +146,12 @@ class PackageInfo: if not xpackage: raise ValueError - # The name for display to an English-speaking user. - self.displayName = xpackage.Attribute('display_name') + self.displayName = None + + xconfig = xpackage.FirstChildElement('config') + if xconfig: + # The name for display to an English-speaking user. + self.displayName = xconfig.Attribute('display_name') # The uncompressed archive, which will be mounted directly, # and also used for patching. diff --git a/direct/src/p3d/Packager.py b/direct/src/p3d/Packager.py index dd09e79db1..35b6ac488b 100644 --- a/direct/src/p3d/Packager.py +++ b/direct/src/p3d/Packager.py @@ -139,7 +139,8 @@ class Packager: return self.glob.matches(filename.cStr()) class PackageEntry: - """ This corresponds to an entry in the contents.xml file. """ + """ This corresponds to a entry in the contents.xml + file. """ def __init__(self): pass @@ -164,18 +165,18 @@ class Packager: self.importDescFile = FileSpec() self.importDescFile.fromFile(installDir, importDescFilename) - def loadXml(self, xelement): - self.packageName = xelement.Attribute('name') - self.platform = xelement.Attribute('platform') - self.version = xelement.Attribute('version') - solo = xelement.Attribute('solo') + def loadXml(self, xpackage): + self.packageName = xpackage.Attribute('name') + self.platform = xpackage.Attribute('platform') + self.version = xpackage.Attribute('version') + solo = xpackage.Attribute('solo') self.solo = int(solo or '0') self.descFile = FileSpec() - self.descFile.loadXml(xelement) + self.descFile.loadXml(xpackage) self.importDescFile = None - ximport = xelement.FirstChildElement('import') + ximport = xpackage.FirstChildElement('import') if ximport: self.importDescFile = FileSpec() self.importDescFile.loadXml(ximport) @@ -202,6 +203,11 @@ class Packager: return xpackage class Package: + """ This is the full information on a particular package we + are constructing. Don't confuse it with PackageEntry, above, + which contains only the information found in the toplevel + contents.xml file.""" + def __init__(self, packageName, packager): self.packageName = packageName self.packager = packager @@ -490,13 +496,15 @@ class Packager: else: # The "base" package file is the bottom of the patch chain. packageBaseFullpath = Filename(self.packageFullpath + '.base') - if not packageBaseFullpath.exists() and self.packageFullpath.exists(): + if not packageBaseFullpath.exists() and \ + self.packageFullpath.exists(): # There's a previous version of the package file. # It becomes the "base". self.packageFullpath.renameTo(packageBaseFullpath) multifileFilename.renameTo(self.packageFullpath) self.compressMultifile() + self.readDescFile() self.writeDescFile() self.writeImportDescFile() @@ -916,10 +924,38 @@ class Packager: message = 'Unable to write %s' % (compressedPath) raise PackagerError, message + def readDescFile(self): + """ Reads the existing package.xml file before rewriting + it. We need this to preserve the list of patchfiles + between sessions. """ + + self.patchVersion = '1' + self.patches = [] + + packageDescFullpath = Filename(self.packager.installDir, self.packageDesc) + doc = TiXmlDocument(packageDescFullpath.toOsSpecific()) + if not doc.LoadFile(): + return + + xpackage = doc.FirstChildElement('package') + if not xpackage: + return + + patchVersion = xpackage.Attribute('patch_version') + if not patchVersion: + patchVersion = xpackage.Attribute('last_patch_version') + if patchVersion: + self.patchVersion = patchVersion + + xpatch = xpackage.FirstChildElement('patch') + while xpatch: + self.patches.append(xpatch.Clone()) + xpatch = xpatch.NextSiblingElement('patch') + def writeDescFile(self): """ Makes the package.xml file that describes the package and its contents, for download. """ - + packageDescFullpath = Filename(self.packager.installDir, self.packageDesc) doc = TiXmlDocument(packageDescFullpath.toOsSpecific()) decl = TiXmlDeclaration("1.0", "utf-8", "") @@ -932,6 +968,8 @@ class Packager: if self.version: xpackage.SetAttribute('version', self.version) + xpackage.SetAttribute('last_patch_version', self.patchVersion) + self.__addConfigs(xpackage) for package in self.requires: @@ -947,12 +985,25 @@ class Packager: xuncompressedArchive = self.getFileSpec( 'uncompressed_archive', self.packageFullpath, self.packageBasename) + xpackage.InsertEndChild(xuncompressedArchive) + xcompressedArchive = self.getFileSpec( 'compressed_archive', self.packageFullpath + '.pz', self.packageBasename + '.pz') - xpackage.InsertEndChild(xuncompressedArchive) xpackage.InsertEndChild(xcompressedArchive) + packageBaseFullpath = Filename(self.packageFullpath + '.base') + if packageBaseFullpath.exists(): + xbaseVersion = self.getFileSpec( + 'base_version', packageBaseFullpath, + self.packageBasename + '.base') + xpackage.InsertEndChild(xbaseVersion) + + # Copy in the patch entries read from the previous version + # of the desc file. + for xpatch in self.patches: + xpackage.InsertEndChild(xpatch) + self.extracts.sort() for name, xextract in self.extracts: xpackage.InsertEndChild(xextract) @@ -963,15 +1014,20 @@ class Packager: def __addConfigs(self, xpackage): """ Adds the XML config values defined in self.configs to the indicated XML element. """ - - for variable, value in self.configs.items(): - if isinstance(value, types.UnicodeType): - xpackage.SetAttribute(variable, value.encode('utf-8')) - elif isinstance(value, types.BooleanType): - # True or False must be encoded as 1 or 0. - xpackage.SetAttribute(variable, str(int(value))) - else: - xpackage.SetAttribute(variable, str(value)) + + if self.configs: + xconfig = TiXmlElement('config') + + for variable, value in self.configs.items(): + if isinstance(value, types.UnicodeType): + xconfig.SetAttribute(variable, value.encode('utf-8')) + elif isinstance(value, types.BooleanType): + # True or False must be encoded as 1 or 0. + xconfig.SetAttribute(variable, str(int(value))) + else: + xconfig.SetAttribute(variable, str(value)) + + xpackage.InsertEndChild(xconfig) def writeImportDescFile(self): """ Makes the package.import.xml file that describes the @@ -2227,12 +2283,12 @@ class Packager: if self.hostDescriptiveName is None: self.hostDescriptiveName = xcontents.Attribute('descriptive_name') - xelement = xcontents.FirstChildElement('package') - while xelement: + xpackage = xcontents.FirstChildElement('package') + while xpackage: pe = self.PackageEntry() - pe.loadXml(xelement) + pe.loadXml(xpackage) self.contents[pe.getKey()] = pe - xelement = xelement.NextSiblingElement('package') + xpackage = xpackage.NextSiblingElement('package') def writeContentsFile(self): """ Rewrites the contents.xml file at the end of @@ -2254,8 +2310,8 @@ class Packager: contents = self.contents.items() contents.sort() for key, pe in contents: - xelement = pe.makeXml() - xcontents.InsertEndChild(xelement) + xpackage = pe.makeXml() + xcontents.InsertEndChild(xpackage) doc.InsertEndChild(xcontents) doc.SaveFile() diff --git a/direct/src/plugin/p3dInstance.cxx b/direct/src/plugin/p3dInstance.cxx index 6e4a7a5b10..33e30452ef 100644 --- a/direct/src/plugin/p3dInstance.cxx +++ b/direct/src/plugin/p3dInstance.cxx @@ -882,8 +882,12 @@ scan_app_desc_file(TiXmlDocument *doc) { } int hidden = 0; - if (xpackage->QueryIntAttribute("hidden", &hidden) == TIXML_SUCCESS) { - _hidden = (hidden != 0); + + TiXmlElement *xconfig = xpackage->FirstChildElement("config"); + if (xconfig != NULL) { + if (xconfig->QueryIntAttribute("hidden", &hidden) == TIXML_SUCCESS) { + _hidden = (hidden != 0); + } } if (_hidden && _got_wparams) { diff --git a/direct/src/plugin/p3dPackage.cxx b/direct/src/plugin/p3dPackage.cxx index 7a065e239f..994021a463 100755 --- a/direct/src/plugin/p3dPackage.cxx +++ b/direct/src/plugin/p3dPackage.cxx @@ -349,13 +349,16 @@ got_desc_file(TiXmlDocument *doc, bool freshly_downloaded) { TiXmlElement *xcompressed_archive = NULL; if (xpackage != NULL) { - const char *display_name_cstr = xpackage->Attribute("display_name"); - if (display_name_cstr != NULL) { - _package_display_name = display_name_cstr; - } - xuncompressed_archive = xpackage->FirstChildElement("uncompressed_archive"); xcompressed_archive = xpackage->FirstChildElement("compressed_archive"); + + TiXmlElement *xconfig = xpackage->FirstChildElement("config"); + if (xconfig != NULL) { + const char *display_name_cstr = xconfig->Attribute("display_name"); + if (display_name_cstr != NULL) { + _package_display_name = display_name_cstr; + } + } } if (xuncompressed_archive == NULL || xcompressed_archive == NULL) {