Przeglądaj źródła

ximport should be nested within xpackage

David Rose 16 lat temu
rodzic
commit
9827e8e978
2 zmienionych plików z 89 dodań i 59 usunięć
  1. 7 13
      direct/src/p3d/HostInfo.py
  2. 82 46
      direct/src/p3d/Packager.py

+ 7 - 13
direct/src/p3d/HostInfo.py

@@ -82,7 +82,7 @@ class HostInfo:
 
 
         self.descriptiveName = xcontents.Attribute('descriptive_name')
         self.descriptiveName = xcontents.Attribute('descriptive_name')
 
 
-        # Get the list of packages available for download.
+        # Get the list of packages available for download and/or import.
         xpackage = xcontents.FirstChildElement('package')
         xpackage = xcontents.FirstChildElement('package')
         while xpackage:
         while xpackage:
             name = xpackage.Attribute('name')
             name = xpackage.Attribute('name')
@@ -93,19 +93,13 @@ class HostInfo:
             package.descFile.loadXml(xpackage)
             package.descFile.loadXml(xpackage)
             package.setupFilenames()
             package.setupFilenames()
 
 
-            xpackage = xpackage.NextSiblingElement('package')
-
-        # Also get the list of packages available for import.
-        ximport = xcontents.FirstChildElement('import')
-        while ximport:
-            name = ximport.Attribute('name')
-            platform = ximport.Attribute('platform')
-            version = ximport.Attribute('version')
-            package = self.__makePackage(name, platform, version)
-            package.importDescFile = FileSpec()
-            package.importDescFile.loadXml(ximport)
+            package.importDescFile = None
+            ximport = xpackage.FirstChildElement('import')
+            if ximport:
+                package.importDescFile = FileSpec()
+                package.importDescFile.loadXml(ximport)
 
 
-            ximport = ximport.NextSiblingElement('import')
+            xpackage = xpackage.NextSiblingElement('package')
 
 
         self.hasContentsFile = True
         self.hasContentsFile = True
 
 

+ 82 - 46
direct/src/p3d/Packager.py

@@ -149,44 +149,57 @@ class Packager:
             objects uniquely per package. """
             objects uniquely per package. """
             return (self.packageName, self.platform, self.version)
             return (self.packageName, self.platform, self.version)
 
 
-        def fromFile(self, packageName, platform, version, solo, isImport,
-                     installDir, descFilename):
+        def fromFile(self, packageName, platform, version, solo,
+                     installDir, descFilename, importDescFilename):
             self.packageName = packageName
             self.packageName = packageName
             self.platform = platform
             self.platform = platform
             self.version = version
             self.version = version
             self.solo = solo
             self.solo = solo
-            self.isImport = isImport
 
 
             self.descFile = FileSpec()
             self.descFile = FileSpec()
             self.descFile.fromFile(installDir, descFilename)
             self.descFile.fromFile(installDir, descFilename)
 
 
+            self.importDescFile = None
+            if importDescFilename:
+                self.importDescFile = FileSpec()
+                self.importDescFile.fromFile(installDir, importDescFilename)
+
         def loadXml(self, xelement):
         def loadXml(self, xelement):
             self.packageName = xelement.Attribute('name')
             self.packageName = xelement.Attribute('name')
             self.platform = xelement.Attribute('platform')
             self.platform = xelement.Attribute('platform')
             self.version = xelement.Attribute('version')
             self.version = xelement.Attribute('version')
             solo = xelement.Attribute('solo')
             solo = xelement.Attribute('solo')
             self.solo = int(solo or '0')
             self.solo = int(solo or '0')
-            self.isImport = (xelement.Value() == 'import')
 
 
             self.descFile = FileSpec()
             self.descFile = FileSpec()
             self.descFile.loadXml(xelement)
             self.descFile.loadXml(xelement)
 
 
+            self.importDescFile = None
+            ximport = xelement.FirstChildElement('import')
+            if ximport:
+                self.importDescFile = FileSpec()
+                self.importDescFile.loadXml(ximport)
+            
+
         def makeXml(self):
         def makeXml(self):
             """ Returns a new TiXmlElement. """
             """ Returns a new TiXmlElement. """
-            value = 'package'
-            if self.isImport:
-                value = 'import'
-            xelement = TiXmlElement(value)
-            xelement.SetAttribute('name', self.packageName)
+            xpackage = TiXmlElement('package')
+            xpackage.SetAttribute('name', self.packageName)
             if self.platform:
             if self.platform:
-                xelement.SetAttribute('platform', self.platform)
+                xpackage.SetAttribute('platform', self.platform)
             if self.version:
             if self.version:
-                xelement.SetAttribute('version', self.version)
+                xpackage.SetAttribute('version', self.version)
             if self.solo:
             if self.solo:
-                xelement.SetAttribute('solo', '1')
+                xpackage.SetAttribute('solo', '1')
+
+            self.descFile.storeXml(xpackage)
 
 
-            self.descFile.storeXml(xelement)
-            return xelement
+            if self.importDescFile:
+                ximport = TiXmlElement('import')
+                self.importDescFile.storeXml(ximport)
+                xpackage.InsertEndChild(ximport)
+            
+            return xpackage
 
 
     class Package:
     class Package:
         def __init__(self, packageName, packager):
         def __init__(self, packageName, packager):
@@ -302,7 +315,7 @@ class Packager:
 
 
             # Write the multifile to a temporary filename until we
             # Write the multifile to a temporary filename until we
             # know enough to determine the output filename.
             # know enough to determine the output filename.
-            multifileFilename = Filename.temporary('', self.packageName)
+            multifileFilename = Filename.temporary('', self.packageName + '.', '.mf')
             self.multifile.openReadWrite(multifileFilename)
             self.multifile.openReadWrite(multifileFilename)
 
 
             self.extracts = []
             self.extracts = []
@@ -463,38 +476,62 @@ class Packager:
 
 
             self.packageFullpath = Filename(self.packager.installDir, self.packageFilename)
             self.packageFullpath = Filename(self.packager.installDir, self.packageFilename)
             self.packageFullpath.makeDir()
             self.packageFullpath.makeDir()
-            self.packageFullpath.unlink()
 
 
             if self.p3dApplication:
             if self.p3dApplication:
                 self.makeP3dInfo()
                 self.makeP3dInfo()
             self.multifile.repack()
             self.multifile.repack()
             self.multifile.close()
             self.multifile.close()
 
 
-            multifileFilename.renameTo(self.packageFullpath)
-
             if self.p3dApplication:
             if self.p3dApplication:
+                # No patches for an application; just move it into place.
+                multifileFilename.renameTo(self.packageFullpath)
                 # Make the application file executable.
                 # Make the application file executable.
                 os.chmod(self.packageFullpath.toOsSpecific(), 0755)
                 os.chmod(self.packageFullpath.toOsSpecific(), 0755)
             else:
             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():
+                    # There's a previous version of the package file.
+                    # It becomes the "base".
+                    self.packageFullpath.renameTo(packageBaseFullpath)
+
+                multifileFilename.renameTo(self.packageFullpath)
                 self.compressMultifile()
                 self.compressMultifile()
                 self.writeDescFile()
                 self.writeDescFile()
                 self.writeImportDescFile()
                 self.writeImportDescFile()
 
 
                 # Replace or add the entry in the contents.
                 # Replace or add the entry in the contents.
-                a = Packager.PackageEntry()
-                a.fromFile(self.packageName, self.platform, self.version,
-                           False, False, self.packager.installDir,
-                           self.packageDesc)
-
-                b = Packager.PackageEntry()
-                b.fromFile(self.packageName, self.platform, self.version,
-                           False, True, self.packager.installDir,
-                           self.packageImportDesc)
-                self.packager.contents[a.getKey()] = [a, b]
+                pe = Packager.PackageEntry()
+                pe.fromFile(self.packageName, self.platform, self.version,
+                            False, self.packager.installDir,
+                            self.packageDesc, self.packageImportDesc)
+                
+                self.packager.contents[pe.getKey()] = pe
                 self.packager.contentsChanged = True
                 self.packager.contentsChanged = True
 
 
             self.cleanup()
             self.cleanup()
 
 
+##         def buildPatch(self, origFilename, newFilename):
+##             """ Creates a patch file from origFilename to newFilename,
+##             in a temporary filename.  Returns the temporary filename
+##             on success, or None on failure. """
+
+##             if not origFilename.exists():
+##                 # No original version to patch from.
+##                 return None
+            
+##             print "Building patch from %s" % (origFilename)
+##             patchFilename = Filename.temporary('', self.packageName + '.', '.patch')
+##             p = Patchfile()
+##             if p.build(origFilename, newFilename, patchFilename):
+##                 return patchFilename
+
+##             # Unable to build a patch for some reason.
+##             patchFilename.unlink()
+##             return None
+            
+            
+
         def installSolo(self):
         def installSolo(self):
             """ Installs the package as a "solo", which means we
             """ Installs the package as a "solo", which means we
             simply copy the one file into the install directory.  This
             simply copy the one file into the install directory.  This
@@ -542,11 +579,11 @@ class Packager:
                     file.filename, targetPath)
                     file.filename, targetPath)
 
 
             # Replace or add the entry in the contents.
             # Replace or add the entry in the contents.
-            a = Packager.PackageEntry()
-            a.fromFile(self.packageName, self.platform, self.version,
-                       True, False, self.packager.installDir,
-                       Filename(packageDir, file.newName))
-            self.packager.contents[a.getKey()] = [a]
+            pe = Packager.PackageEntry()
+            pe.fromFile(self.packageName, self.platform, self.version,
+                        True, self.packager.installDir,
+                        Filename(packageDir, file.newName), None)
+            self.packager.contents[pe.getKey()] = pe
             self.packager.contentsChanged = True
             self.packager.contentsChanged = True
 
 
             self.cleanup()
             self.cleanup()
@@ -606,7 +643,7 @@ class Packager:
                     # Skip this file.
                     # Skip this file.
                     continue
                     continue
 
 
-                tempFile = Filename.temporary('', 'p3d_')
+                tempFile = Filename.temporary('', 'p3d_', '.txt')
                 command = 'dumpbin /dependents "%s" >"%s"' % (
                 command = 'dumpbin /dependents "%s" >"%s"' % (
                     file.filename.toOsSpecific(),
                     file.filename.toOsSpecific(),
                     tempFile.toOsSpecific())
                     tempFile.toOsSpecific())
@@ -689,7 +726,7 @@ class Packager:
                     # Skip this file.
                     # Skip this file.
                     continue
                     continue
 
 
-                tempFile = Filename.temporary('', 'p3d_')
+                tempFile = Filename.temporary('', 'p3d_', '.txt')
                 command = 'otool -L "%s" >"%s"' % (
                 command = 'otool -L "%s" >"%s"' % (
                     file.filename.toOsSpecific(),
                     file.filename.toOsSpecific(),
                     tempFile.toOsSpecific())
                     tempFile.toOsSpecific())
@@ -761,7 +798,7 @@ class Packager:
                     # Skip this file.
                     # Skip this file.
                     continue
                     continue
 
 
-                tempFile = Filename.temporary('', 'p3d_')
+                tempFile = Filename.temporary('', 'p3d_', '.txt')
                 command = 'ldd "%s" >"%s"' % (
                 command = 'ldd "%s" >"%s"' % (
                     file.filename.toOsSpecific(),
                     file.filename.toOsSpecific(),
                     tempFile.toOsSpecific())
                     tempFile.toOsSpecific())
@@ -2090,7 +2127,7 @@ class Packager:
             if not newName:
             if not newName:
                 newName = str(filenames[0])
                 newName = str(filenames[0])
 
 
-            tempFile = Filename.temporary('', self.currentPackage.packageName)
+            tempFile = Filename.temporary('', self.currentPackage.packageName + '.', Filename(newName).getExtension())
             temp = open(tempFile.toOsSpecific(), 'w')
             temp = open(tempFile.toOsSpecific(), 'w')
             temp.write(text)
             temp.write(text)
             temp.close()
             temp.close()
@@ -2190,12 +2227,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()
+            xelement = xcontents.FirstChildElement('package')
             while xelement:
             while xelement:
-                package = self.PackageEntry()
-                package.loadXml(xelement)
-                self.contents.setdefault(package.getKey(), []).append(package)
-                xelement = xelement.NextSiblingElement()
+                pe = self.PackageEntry()
+                pe.loadXml(xelement)
+                self.contents[pe.getKey()] = pe
+                xelement = xelement.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
@@ -2216,10 +2253,9 @@ class Packager:
 
 
         contents = self.contents.items()
         contents = self.contents.items()
         contents.sort()
         contents.sort()
-        for key, entryList in contents:
-            for entry in entryList:
-                xelement = entry.makeXml()
-                xcontents.InsertEndChild(xelement)
+        for key, pe in contents:
+            xelement = pe.makeXml()
+            xcontents.InsertEndChild(xelement)
 
 
         doc.InsertEndChild(xcontents)
         doc.InsertEndChild(xcontents)
         doc.SaveFile()
         doc.SaveFile()