Browse Source

protect from builds without net or openssl

David Rose 16 years ago
parent
commit
f17536da77
4 changed files with 50 additions and 25 deletions
  1. 12 5
      direct/src/p3d/AppRunner.py
  2. 22 17
      direct/src/p3d/HostInfo.py
  3. 6 3
      direct/src/p3d/PackageInfo.py
  4. 10 0
      direct/src/p3d/runp3d.py

+ 12 - 5
direct/src/p3d/AppRunner.py

@@ -28,11 +28,13 @@ else:
     # Otherwise, we can import the VFSImporter normally.  We have to
     # Otherwise, we can import the VFSImporter normally.  We have to
     # import PandaModules first, to get the funny renaming with
     # import PandaModules first, to get the funny renaming with
     # pandaexpress.
     # pandaexpress.
+    import direct
     from pandac import PandaModules
     from pandac import PandaModules
     from direct.showbase import VFSImporter
     from direct.showbase import VFSImporter
 
 
 from direct.showbase.DirectObject import DirectObject
 from direct.showbase.DirectObject import DirectObject
-from pandac.PandaModules import VirtualFileSystem, Filename, Multifile, loadPrcFileData, unloadPrcFile, getModelPath, HTTPClient, Thread, WindowProperties, readXmlStream, ExecutionEnvironment, PandaSystem, URLSpec, Notify, StreamWriter, ConfigVariableString
+from pandac.PandaModules import VirtualFileSystem, Filename, Multifile, loadPrcFileData, unloadPrcFile, getModelPath, Thread, WindowProperties, ExecutionEnvironment, PandaSystem, Notify, StreamWriter, ConfigVariableString
+from pandac import PandaModules
 from direct.stdpy import file
 from direct.stdpy import file
 from direct.task.TaskManagerGlobal import taskMgr
 from direct.task.TaskManagerGlobal import taskMgr
 from direct.showbase.MessengerGlobal import messenger
 from direct.showbase.MessengerGlobal import messenger
@@ -88,7 +90,10 @@ class AppRunner(DirectObject):
         self.started = False
         self.started = False
         self.windowOpened = False
         self.windowOpened = False
         self.windowPrc = None
         self.windowPrc = None
-        self.http = HTTPClient.getGlobalPtr()
+
+        self.http = None
+        if hasattr(PandaModules, 'HTTPClient'):
+            self.http = PandaModules.HTTPClient.getGlobalPtr()
 
 
         self.Undefined = Undefined
         self.Undefined = Undefined
         self.ConcreteStruct = ConcreteStruct
         self.ConcreteStruct = ConcreteStruct
@@ -332,8 +337,10 @@ class AppRunner(DirectObject):
             # It's good, keep it.
             # It's good, keep it.
             return True
             return True
 
 
+        assert self.http
+
         # It's stale, get a new one.
         # It's stale, get a new one.
-        url = URLSpec(host.hostUrlPrefix + fileSpec.filename)
+        url = PandaModules.URLSpec(host.hostUrlPrefix + fileSpec.filename)
         print "Freshening %s" % (url)
         print "Freshening %s" % (url)
         doc = self.http.getDocument(url)
         doc = self.http.getDocument(url)
         if not doc.isValid():
         if not doc.isValid():
@@ -581,9 +588,9 @@ class AppRunner(DirectObject):
         self.p3dPackage = None
         self.p3dPackage = None
         self.p3dConfig = None
         self.p3dConfig = None
         self.allowPythonDev = False
         self.allowPythonDev = False
-        
+
         i = mf.findSubfile('p3d_info.xml')
         i = mf.findSubfile('p3d_info.xml')
-        if i >= 0:
+        if i >= 0 and hasattr(PandaModules, 'readXmlStream'):
             stream = mf.openReadSubfile(i)
             stream = mf.openReadSubfile(i)
             self.p3dInfo = readXmlStream(stream)
             self.p3dInfo = readXmlStream(stream)
             mf.closeReadSubfile(stream)
             mf.closeReadSubfile(stream)

+ 22 - 17
direct/src/p3d/HostInfo.py

@@ -1,4 +1,5 @@
-from pandac.PandaModules import TiXmlDocument, HashVal, Filename, PandaSystem, DocumentSpec, Ramfile
+from pandac.PandaModules import HashVal, Filename, PandaSystem, DocumentSpec, Ramfile
+from pandac import PandaModules
 from direct.p3d.PackageInfo import PackageInfo
 from direct.p3d.PackageInfo import PackageInfo
 from direct.p3d.FileSpec import FileSpec
 from direct.p3d.FileSpec import FileSpec
 import time
 import time
@@ -78,24 +79,25 @@ class HostInfo:
             # We've already got one.
             # We've already got one.
             return True
             return True
 
 
-        url = self.hostUrlPrefix + 'contents.xml'
-        # Append a uniquifying query string to the URL to force the
-        # download to go all the way through any caches.  We use the
-        # time in seconds; that's unique enough.
-        url += '?' + str(int(time.time()))
+        if http:
+            url = self.hostUrlPrefix + 'contents.xml'
+            # Append a uniquifying query string to the URL to force the
+            # download to go all the way through any caches.  We use the
+            # time in seconds; that's unique enough.
+            url += '?' + str(int(time.time()))
 
 
-        # We might as well explicitly request the cache to be disabled
-        # too, since we have an interface for that via HTTPChannel.
-        request = DocumentSpec(url)
-        request.setCacheControl(DocumentSpec.CCNoCache)
+            # We might as well explicitly request the cache to be disabled
+            # too, since we have an interface for that via HTTPChannel.
+            request = DocumentSpec(url)
+            request.setCacheControl(DocumentSpec.CCNoCache)
 
 
-        print "Downloading contents file %s" % (request)
+            print "Downloading contents file %s" % (request)
 
 
-        rf = Ramfile()
-        channel = http.makeChannel(False)
-        channel.getDocument(request)
-        if not channel.downloadToRam(rf):
-            print "Unable to download %s" % (url)
+            rf = Ramfile()
+            channel = http.makeChannel(False)
+            channel.getDocument(request)
+            if not channel.downloadToRam(rf):
+                print "Unable to download %s" % (url)
 
 
         filename = Filename(self.hostDir, 'contents.xml')
         filename = Filename(self.hostDir, 'contents.xml')
         filename.makeDir()
         filename.makeDir()
@@ -150,7 +152,10 @@ class HostInfo:
 
 
         filename = Filename(self.hostDir, 'contents.xml')
         filename = Filename(self.hostDir, 'contents.xml')
 
 
-        doc = TiXmlDocument(filename.toOsSpecific())
+        if not hasattr(PandaModules, 'TiXmlDocument'):
+            return False
+        
+        doc = PandaModules.TiXmlDocument(filename.toOsSpecific())
         if not doc.LoadFile():
         if not doc.LoadFile():
             return False
             return False
         
         

+ 6 - 3
direct/src/p3d/PackageInfo.py

@@ -1,4 +1,5 @@
-from pandac.PandaModules import Filename, URLSpec, DocumentSpec, Ramfile, TiXmlDocument, Multifile, Decompressor, EUOk, EUSuccess, VirtualFileSystem, Thread, getModelPath, Patchfile, ExecutionEnvironment
+from pandac.PandaModules import Filename, URLSpec, DocumentSpec, Ramfile, Multifile, Decompressor, EUOk, EUSuccess, VirtualFileSystem, Thread, getModelPath, ExecutionEnvironment
+from pandac import PandaModules
 from direct.p3d.FileSpec import FileSpec
 from direct.p3d.FileSpec import FileSpec
 from direct.showbase import VFSImporter
 from direct.showbase import VFSImporter
 import os
 import os
@@ -221,7 +222,9 @@ class PackageInfo:
 
 
         filename = Filename(self.packageDir, self.descFileBasename)
         filename = Filename(self.packageDir, self.descFileBasename)
 
 
-        doc = TiXmlDocument(filename.toOsSpecific())
+        if not hasattr(PandaModules, 'TiXmlDocument'):
+            return False
+        doc = PandaModules.TiXmlDocument(filename.toOsSpecific())
         if not doc.LoadFile():
         if not doc.LoadFile():
             return False
             return False
 
 
@@ -683,7 +686,7 @@ class PackageInfo:
         result = Filename.temporary('', 'patch_')
         result = Filename.temporary('', 'patch_')
         print "Patching %s with %s" % (origPathname, patchPathname)
         print "Patching %s with %s" % (origPathname, patchPathname)
 
 
-        p = Patchfile()  # The C++ class
+        p = PandaModules.Patchfile()  # The C++ class
 
 
         ret = p.initiate(patchPathname, origPathname, result)
         ret = p.initiate(patchPathname, origPathname, result)
         if ret == EUSuccess:
         if ret == EUSuccess:

+ 10 - 0
direct/src/p3d/runp3d.py

@@ -56,6 +56,16 @@ def parseSysArgs():
 
 
     return [arg0] + args[1:]
     return [arg0] + args[1:]
 
 
+def runPackedApp(pathname):
+    runner = AppRunner()
+    runner.gotWindow = True
+    try:
+        runner.setP3DFilename(pathname, tokens = [], argv = [],
+                              instanceId = 0, interactiveConsole = False)
+    except ArgumentError, e:
+        print e.args[0]
+        sys.exit(1)
+
 if __name__ == '__main__':
 if __name__ == '__main__':
     runner = AppRunner()
     runner = AppRunner()
     runner.gotWindow = True
     runner.gotWindow = True