Browse Source

more super-mirror stuff

David Rose 16 years ago
parent
commit
0fd8c7a18d
2 changed files with 47 additions and 24 deletions
  1. 44 24
      direct/src/p3d/HostInfo.py
  2. 3 0
      direct/src/plugin/p3dInstanceManager.cxx

+ 44 - 24
direct/src/p3d/HostInfo.py

@@ -70,7 +70,7 @@ class HostInfo:
         assert self.hostDir
         assert self.hostDir
         self.importsDir = Filename(self.hostDir, 'imports')
         self.importsDir = Filename(self.hostDir, 'imports')
 
 
-    def downloadContentsFile(self, http):
+    def downloadContentsFile(self, http, redownload = False):
         """ Downloads the contents.xml file for this particular host,
         """ Downloads the contents.xml file for this particular host,
         synchronously, and then reads it.  Returns true on success,
         synchronously, and then reads it.  Returns true on success,
         false on failure. """
         false on failure. """
@@ -79,31 +79,51 @@ class HostInfo:
             # We've already got one.
             # We've already got one.
             return True
             return True
 
 
+        rf = None
         if http:
         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)
-
-            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)
+            if not redownload and self.appRunner and self.appRunner.superMirrorUrl:
+                # We start with the "super mirror", if it's defined.
+                url = self.appRunner.superMirrorUrl + 'contents.xml'
+                request = DocumentSpec(url)
+                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 = None
+
+            if not rf:
+                # Then go to the main host, if our super mirror let us
+                # down.
+
+                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)
+
+                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 = None
 
 
         filename = Filename(self.hostDir, 'contents.xml')
         filename = Filename(self.hostDir, 'contents.xml')
-        filename.makeDir()
-        f = open(filename.toOsSpecific(), 'wb')
-        f.write(rf.getData())
-        f.close()
+        if rf:
+            filename.makeDir()
+            f = open(filename.toOsSpecific(), 'wb')
+            f.write(rf.getData())
+            f.close()
 
 
         if not self.readContentsFile():
         if not self.readContentsFile():
             print "Failure reading %s" % (filename)
             print "Failure reading %s" % (filename)
@@ -127,7 +147,7 @@ class HostInfo:
 
 
         # Now download it again.
         # Now download it again.
         self.hasContentsFile = False
         self.hasContentsFile = False
-        if not self.downloadContentsFile(http):
+        if not self.downloadContentsFile(http, redownload = True):
             return False
             return False
 
 
         hv2 = HashVal()
         hv2 = HashVal()

+ 3 - 0
direct/src/plugin/p3dInstanceManager.cxx

@@ -385,6 +385,9 @@ set_plugin_version(int major, int minor, int sequence,
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void P3DInstanceManager::
 void P3DInstanceManager::
 set_super_mirror(const string &super_mirror_url) {
 set_super_mirror(const string &super_mirror_url) {
+  if (!super_mirror_url.empty()) {
+    nout << "super_mirror = " << super_mirror_url << "\n";
+  }
   _super_mirror_url = super_mirror_url;
   _super_mirror_url = super_mirror_url;
 
 
   // Make sure it ends with a slash.
   // Make sure it ends with a slash.