mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 02:15:43 -04:00
deal better with stale contents.xml file in local directory
This commit is contained in:
parent
955b03dff9
commit
79d2e645d8
@ -802,7 +802,8 @@ class AppRunner(DirectObject):
|
|||||||
self.readConfigXml()
|
self.readConfigXml()
|
||||||
|
|
||||||
|
|
||||||
def addPackageInfo(self, name, platform, version, hostUrl, hostDir = None):
|
def addPackageInfo(self, name, platform, version, hostUrl, hostDir = None,
|
||||||
|
recurse = False):
|
||||||
""" Called by the browser for each one of the "required"
|
""" Called by the browser for each one of the "required"
|
||||||
packages that were preloaded before starting the application.
|
packages that were preloaded before starting the application.
|
||||||
If for some reason the package isn't already downloaded, this
|
If for some reason the package isn't already downloaded, this
|
||||||
@ -830,6 +831,11 @@ class AppRunner(DirectObject):
|
|||||||
platform = None
|
platform = None
|
||||||
package = host.getPackage(name, version, platform = platform)
|
package = host.getPackage(name, version, platform = platform)
|
||||||
if not package:
|
if not package:
|
||||||
|
if not recurse:
|
||||||
|
# Maybe the contents.xml file isn't current. Re-fetch it.
|
||||||
|
if host.redownloadContentsFile(self.http):
|
||||||
|
return self.addPackageInfo(name, platform, version, hostUrl, hostDir = hostDir, recurse = True)
|
||||||
|
|
||||||
message = "Couldn't find %s %s on %s" % (name, version, hostUrl)
|
message = "Couldn't find %s %s on %s" % (name, version, hostUrl)
|
||||||
raise OSError, message
|
raise OSError, message
|
||||||
|
|
||||||
|
@ -106,10 +106,13 @@ class HostInfo:
|
|||||||
# https-protected hostUrl, it will be the cleartext channel.
|
# https-protected hostUrl, it will be the cleartext channel.
|
||||||
self.downloadUrlPrefix = self.hostUrlPrefix
|
self.downloadUrlPrefix = self.hostUrlPrefix
|
||||||
|
|
||||||
def downloadContentsFile(self, http, redownload = False):
|
def downloadContentsFile(self, http, redownload = False,
|
||||||
|
hashVal = None):
|
||||||
""" 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. If hashVal is not None, it should be a
|
||||||
|
HashVal object, which will be filled with the hash from the
|
||||||
|
new contents.xml file."""
|
||||||
|
|
||||||
if self.hasCurrentContentsFile():
|
if self.hasCurrentContentsFile():
|
||||||
# We've already got one.
|
# We've already got one.
|
||||||
@ -159,6 +162,8 @@ class HostInfo:
|
|||||||
f = open(tempFilename.toOsSpecific(), 'wb')
|
f = open(tempFilename.toOsSpecific(), 'wb')
|
||||||
f.write(rf.getData())
|
f.write(rf.getData())
|
||||||
f.close()
|
f.close()
|
||||||
|
if hashVal:
|
||||||
|
hashVal.hashString(rf.getData())
|
||||||
|
|
||||||
if not self.readContentsFile(tempFilename, freshDownload = True):
|
if not self.readContentsFile(tempFilename, freshDownload = True):
|
||||||
self.notify.warning("Failure reading %s" % (url))
|
self.notify.warning("Failure reading %s" % (url))
|
||||||
@ -192,14 +197,15 @@ class HostInfo:
|
|||||||
|
|
||||||
# Now download it again.
|
# Now download it again.
|
||||||
self.hasContentsFile = False
|
self.hasContentsFile = False
|
||||||
if not self.downloadContentsFile(http, redownload = True):
|
|
||||||
return False
|
|
||||||
|
|
||||||
hv2 = HashVal()
|
hv2 = HashVal()
|
||||||
filename = Filename(self.hostDir, 'contents.xml')
|
if not self.downloadContentsFile(http, redownload = True,
|
||||||
hv2.hashFile(filename)
|
hashVal = hv2):
|
||||||
|
return False
|
||||||
|
|
||||||
if hv1 != hv2:
|
if hv2 == HashVal():
|
||||||
|
self.notify.info("%s didn't actually redownload." % (url))
|
||||||
|
return False
|
||||||
|
elif hv1 != hv2:
|
||||||
self.notify.info("%s has changed." % (url))
|
self.notify.info("%s has changed." % (url))
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user