move <config> to within the <package>

This commit is contained in:
David Rose 2009-08-26 05:04:15 +00:00
parent 9827e8e978
commit 1fc186bda4
4 changed files with 102 additions and 35 deletions

View File

@ -146,8 +146,12 @@ class PackageInfo:
if not xpackage: if not xpackage:
raise ValueError raise ValueError
# The name for display to an English-speaking user. self.displayName = None
self.displayName = xpackage.Attribute('display_name')
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, # The uncompressed archive, which will be mounted directly,
# and also used for patching. # and also used for patching.

View File

@ -139,7 +139,8 @@ class Packager:
return self.glob.matches(filename.cStr()) return self.glob.matches(filename.cStr())
class PackageEntry: class PackageEntry:
""" This corresponds to an entry in the contents.xml file. """ """ This corresponds to a <package> entry in the contents.xml
file. """
def __init__(self): def __init__(self):
pass pass
@ -164,18 +165,18 @@ class Packager:
self.importDescFile = FileSpec() self.importDescFile = FileSpec()
self.importDescFile.fromFile(installDir, importDescFilename) self.importDescFile.fromFile(installDir, importDescFilename)
def loadXml(self, xelement): def loadXml(self, xpackage):
self.packageName = xelement.Attribute('name') self.packageName = xpackage.Attribute('name')
self.platform = xelement.Attribute('platform') self.platform = xpackage.Attribute('platform')
self.version = xelement.Attribute('version') self.version = xpackage.Attribute('version')
solo = xelement.Attribute('solo') solo = xpackage.Attribute('solo')
self.solo = int(solo or '0') self.solo = int(solo or '0')
self.descFile = FileSpec() self.descFile = FileSpec()
self.descFile.loadXml(xelement) self.descFile.loadXml(xpackage)
self.importDescFile = None self.importDescFile = None
ximport = xelement.FirstChildElement('import') ximport = xpackage.FirstChildElement('import')
if ximport: if ximport:
self.importDescFile = FileSpec() self.importDescFile = FileSpec()
self.importDescFile.loadXml(ximport) self.importDescFile.loadXml(ximport)
@ -202,6 +203,11 @@ class Packager:
return xpackage return xpackage
class Package: 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): def __init__(self, packageName, packager):
self.packageName = packageName self.packageName = packageName
self.packager = packager self.packager = packager
@ -490,13 +496,15 @@ class Packager:
else: else:
# The "base" package file is the bottom of the patch chain. # The "base" package file is the bottom of the patch chain.
packageBaseFullpath = Filename(self.packageFullpath + '.base') 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. # There's a previous version of the package file.
# It becomes the "base". # It becomes the "base".
self.packageFullpath.renameTo(packageBaseFullpath) self.packageFullpath.renameTo(packageBaseFullpath)
multifileFilename.renameTo(self.packageFullpath) multifileFilename.renameTo(self.packageFullpath)
self.compressMultifile() self.compressMultifile()
self.readDescFile()
self.writeDescFile() self.writeDescFile()
self.writeImportDescFile() self.writeImportDescFile()
@ -916,10 +924,38 @@ class Packager:
message = 'Unable to write %s' % (compressedPath) message = 'Unable to write %s' % (compressedPath)
raise PackagerError, message 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): def writeDescFile(self):
""" Makes the package.xml file that describes the package """ Makes the package.xml file that describes the package
and its contents, for download. """ and its contents, for download. """
packageDescFullpath = Filename(self.packager.installDir, self.packageDesc) packageDescFullpath = Filename(self.packager.installDir, self.packageDesc)
doc = TiXmlDocument(packageDescFullpath.toOsSpecific()) doc = TiXmlDocument(packageDescFullpath.toOsSpecific())
decl = TiXmlDeclaration("1.0", "utf-8", "") decl = TiXmlDeclaration("1.0", "utf-8", "")
@ -932,6 +968,8 @@ class Packager:
if self.version: if self.version:
xpackage.SetAttribute('version', self.version) xpackage.SetAttribute('version', self.version)
xpackage.SetAttribute('last_patch_version', self.patchVersion)
self.__addConfigs(xpackage) self.__addConfigs(xpackage)
for package in self.requires: for package in self.requires:
@ -947,12 +985,25 @@ class Packager:
xuncompressedArchive = self.getFileSpec( xuncompressedArchive = self.getFileSpec(
'uncompressed_archive', self.packageFullpath, 'uncompressed_archive', self.packageFullpath,
self.packageBasename) self.packageBasename)
xpackage.InsertEndChild(xuncompressedArchive)
xcompressedArchive = self.getFileSpec( xcompressedArchive = self.getFileSpec(
'compressed_archive', self.packageFullpath + '.pz', 'compressed_archive', self.packageFullpath + '.pz',
self.packageBasename + '.pz') self.packageBasename + '.pz')
xpackage.InsertEndChild(xuncompressedArchive)
xpackage.InsertEndChild(xcompressedArchive) 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() self.extracts.sort()
for name, xextract in self.extracts: for name, xextract in self.extracts:
xpackage.InsertEndChild(xextract) xpackage.InsertEndChild(xextract)
@ -963,15 +1014,20 @@ class Packager:
def __addConfigs(self, xpackage): def __addConfigs(self, xpackage):
""" Adds the XML config values defined in self.configs to """ Adds the XML config values defined in self.configs to
the indicated XML element. """ the indicated XML element. """
for variable, value in self.configs.items(): if self.configs:
if isinstance(value, types.UnicodeType): xconfig = TiXmlElement('config')
xpackage.SetAttribute(variable, value.encode('utf-8'))
elif isinstance(value, types.BooleanType): for variable, value in self.configs.items():
# True or False must be encoded as 1 or 0. if isinstance(value, types.UnicodeType):
xpackage.SetAttribute(variable, str(int(value))) xconfig.SetAttribute(variable, value.encode('utf-8'))
else: elif isinstance(value, types.BooleanType):
xpackage.SetAttribute(variable, str(value)) # 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): def writeImportDescFile(self):
""" Makes the package.import.xml file that describes the """ Makes the package.import.xml file that describes the
@ -2227,12 +2283,12 @@ class Packager:
if self.hostDescriptiveName is None: if self.hostDescriptiveName is None:
self.hostDescriptiveName = xcontents.Attribute('descriptive_name') self.hostDescriptiveName = xcontents.Attribute('descriptive_name')
xelement = xcontents.FirstChildElement('package') xpackage = xcontents.FirstChildElement('package')
while xelement: while xpackage:
pe = self.PackageEntry() pe = self.PackageEntry()
pe.loadXml(xelement) pe.loadXml(xpackage)
self.contents[pe.getKey()] = pe self.contents[pe.getKey()] = pe
xelement = xelement.NextSiblingElement('package') xpackage = xpackage.NextSiblingElement('package')
def writeContentsFile(self): def writeContentsFile(self):
""" Rewrites the contents.xml file at the end of """ Rewrites the contents.xml file at the end of
@ -2254,8 +2310,8 @@ class Packager:
contents = self.contents.items() contents = self.contents.items()
contents.sort() contents.sort()
for key, pe in contents: for key, pe in contents:
xelement = pe.makeXml() xpackage = pe.makeXml()
xcontents.InsertEndChild(xelement) xcontents.InsertEndChild(xpackage)
doc.InsertEndChild(xcontents) doc.InsertEndChild(xcontents)
doc.SaveFile() doc.SaveFile()

View File

@ -882,8 +882,12 @@ scan_app_desc_file(TiXmlDocument *doc) {
} }
int hidden = 0; 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) { if (_hidden && _got_wparams) {

View File

@ -349,13 +349,16 @@ got_desc_file(TiXmlDocument *doc, bool freshly_downloaded) {
TiXmlElement *xcompressed_archive = NULL; TiXmlElement *xcompressed_archive = NULL;
if (xpackage != 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"); xuncompressed_archive = xpackage->FirstChildElement("uncompressed_archive");
xcompressed_archive = xpackage->FirstChildElement("compressed_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) { if (xuncompressed_archive == NULL || xcompressed_archive == NULL) {