mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
defer packageDir until it is known
This commit is contained in:
parent
8f83de634f
commit
1f4cbbb0e8
@ -58,15 +58,13 @@ class PackageInfo:
|
|||||||
self.solo = solo
|
self.solo = solo
|
||||||
self.asMirror = asMirror
|
self.asMirror = asMirror
|
||||||
|
|
||||||
self.packageDir = Filename(host.hostDir, self.packageName)
|
# This will be active while we are in the middle of a download
|
||||||
if self.packageVersion:
|
# cycle.
|
||||||
self.packageDir = Filename(self.packageDir, self.packageVersion)
|
self.http = None
|
||||||
|
|
||||||
if self.asMirror:
|
# This will be filled in when the host's contents.xml file is
|
||||||
# The server directory contains the platform name, though
|
# read.
|
||||||
# the client directory doesn't.
|
self.packageDir = None
|
||||||
if self.platform:
|
|
||||||
self.packageDir = Filename(self.packageDir, self.platform)
|
|
||||||
|
|
||||||
# These will be filled in by HostInfo when the package is read
|
# These will be filled in by HostInfo when the package is read
|
||||||
# from contents.xml.
|
# from contents.xml.
|
||||||
@ -96,6 +94,30 @@ class PackageInfo:
|
|||||||
# meaning it's been added to the paths and all.
|
# meaning it's been added to the paths and all.
|
||||||
self.installed = False
|
self.installed = False
|
||||||
|
|
||||||
|
def getPackageDir(self):
|
||||||
|
""" Returns the directory in which this package is installed.
|
||||||
|
This may not be known until the host's contents.xml file has
|
||||||
|
been downloaded, which informs us of the host's own install
|
||||||
|
directory. """
|
||||||
|
|
||||||
|
if not self.packageDir:
|
||||||
|
if not self.host.hasContentsFile:
|
||||||
|
if not self.host.readContentsFile():
|
||||||
|
self.host.downloadContentsFile(self.http)
|
||||||
|
|
||||||
|
# Derive the packageDir from the hostDir.
|
||||||
|
self.packageDir = Filename(self.host.hostDir, self.packageName)
|
||||||
|
if self.packageVersion:
|
||||||
|
self.packageDir = Filename(self.packageDir, self.packageVersion)
|
||||||
|
|
||||||
|
if self.asMirror:
|
||||||
|
# The server directory contains the platform name, though
|
||||||
|
# the client directory doesn't.
|
||||||
|
if self.platform:
|
||||||
|
self.packageDir = Filename(self.packageDir, self.platform)
|
||||||
|
|
||||||
|
return self.packageDir
|
||||||
|
|
||||||
def getDownloadEffort(self):
|
def getDownloadEffort(self):
|
||||||
""" Returns the relative amount of effort it will take to
|
""" Returns the relative amount of effort it will take to
|
||||||
download this package. The units are meaningless, except
|
download this package. The units are meaningless, except
|
||||||
@ -146,8 +168,8 @@ class PackageInfo:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
if not self.hasDescFile:
|
if not self.hasDescFile:
|
||||||
filename = Filename(self.packageDir, self.descFileBasename)
|
filename = Filename(self.getPackageDir(), self.descFileBasename)
|
||||||
if self.descFile.quickVerify(self.packageDir, pathname = filename):
|
if self.descFile.quickVerify(self.getPackageDir(), pathname = filename):
|
||||||
if self.__readDescFile():
|
if self.__readDescFile():
|
||||||
# Successfully read. We don't need to call
|
# Successfully read. We don't need to call
|
||||||
# checkArchiveStatus again, since readDescFile()
|
# checkArchiveStatus again, since readDescFile()
|
||||||
@ -192,7 +214,7 @@ class PackageInfo:
|
|||||||
|
|
||||||
assert token == self.stepComplete
|
assert token == self.stepComplete
|
||||||
|
|
||||||
filename = Filename(self.packageDir, self.descFileBasename)
|
filename = Filename(self.getPackageDir(), self.descFileBasename)
|
||||||
# Now that we've written the desc file, make it read-only.
|
# Now that we've written the desc file, make it read-only.
|
||||||
os.chmod(filename.toOsSpecific(), 0444)
|
os.chmod(filename.toOsSpecific(), 0444)
|
||||||
|
|
||||||
@ -221,7 +243,7 @@ class PackageInfo:
|
|||||||
self.hasPackage = True
|
self.hasPackage = True
|
||||||
return True
|
return True
|
||||||
|
|
||||||
filename = Filename(self.packageDir, self.descFileBasename)
|
filename = Filename(self.getPackageDir(), self.descFileBasename)
|
||||||
|
|
||||||
if not hasattr(PandaModules, 'TiXmlDocument'):
|
if not hasattr(PandaModules, 'TiXmlDocument'):
|
||||||
return False
|
return False
|
||||||
@ -332,12 +354,12 @@ class PackageInfo:
|
|||||||
# If the uncompressed archive file is good, that's all we'll
|
# If the uncompressed archive file is good, that's all we'll
|
||||||
# need to do.
|
# need to do.
|
||||||
self.uncompressedArchive.actualFile = None
|
self.uncompressedArchive.actualFile = None
|
||||||
if self.uncompressedArchive.quickVerify(self.packageDir):
|
if self.uncompressedArchive.quickVerify(self.getPackageDir()):
|
||||||
self.installPlans = [planA]
|
self.installPlans = [planA]
|
||||||
return
|
return
|
||||||
|
|
||||||
# Maybe the compressed archive file is good.
|
# Maybe the compressed archive file is good.
|
||||||
if self.compressedArchive.quickVerify(self.packageDir):
|
if self.compressedArchive.quickVerify(self.getPackageDir()):
|
||||||
uncompressSize = self.uncompressedArchive.size
|
uncompressSize = self.uncompressedArchive.size
|
||||||
step = self.InstallStep(self.__uncompressArchive, uncompressSize, self.uncompressFactor)
|
step = self.InstallStep(self.__uncompressArchive, uncompressSize, self.uncompressFactor)
|
||||||
planA = [step] + planA
|
planA = [step] + planA
|
||||||
@ -362,11 +384,11 @@ class PackageInfo:
|
|||||||
# Now look for patches. Start with the md5 hash from the
|
# Now look for patches. Start with the md5 hash from the
|
||||||
# uncompressedArchive file we have on disk, and see if we can
|
# uncompressedArchive file we have on disk, and see if we can
|
||||||
# find a patch chain from this file to our target.
|
# find a patch chain from this file to our target.
|
||||||
pathname = Filename(self.packageDir, self.uncompressedArchive.filename)
|
pathname = Filename(self.getPackageDir(), self.uncompressedArchive.filename)
|
||||||
fileSpec = self.uncompressedArchive.actualFile
|
fileSpec = self.uncompressedArchive.actualFile
|
||||||
if fileSpec is None and pathname.exists():
|
if fileSpec is None and pathname.exists():
|
||||||
fileSpec = FileSpec()
|
fileSpec = FileSpec()
|
||||||
fileSpec.fromFile(self.packageDir, self.uncompressedArchive.filename)
|
fileSpec.fromFile(self.getPackageDir(), self.uncompressedArchive.filename)
|
||||||
plan = None
|
plan = None
|
||||||
if fileSpec:
|
if fileSpec:
|
||||||
plan = self.__findPatchChain(fileSpec)
|
plan = self.__findPatchChain(fileSpec)
|
||||||
@ -410,7 +432,7 @@ class PackageInfo:
|
|||||||
|
|
||||||
# Get a list of all of the files in the directory, so we can
|
# Get a list of all of the files in the directory, so we can
|
||||||
# remove files that don't belong.
|
# remove files that don't belong.
|
||||||
contents = self.__scanDirectoryRecursively(self.packageDir)
|
contents = self.__scanDirectoryRecursively(self.getPackageDir())
|
||||||
self.__removeFileFromList(contents, self.descFileBasename)
|
self.__removeFileFromList(contents, self.descFileBasename)
|
||||||
self.__removeFileFromList(contents, self.compressedArchive.filename)
|
self.__removeFileFromList(contents, self.compressedArchive.filename)
|
||||||
if not self.asMirror:
|
if not self.asMirror:
|
||||||
@ -425,25 +447,25 @@ class PackageInfo:
|
|||||||
# something (e.g. case insensitivity).
|
# something (e.g. case insensitivity).
|
||||||
for filename in contents:
|
for filename in contents:
|
||||||
print "Removing %s" % (filename)
|
print "Removing %s" % (filename)
|
||||||
pathname = Filename(self.packageDir, filename)
|
pathname = Filename(self.getPackageDir(), filename)
|
||||||
pathname.unlink()
|
pathname.unlink()
|
||||||
|
|
||||||
if self.asMirror:
|
if self.asMirror:
|
||||||
return self.compressedArchive.quickVerify(self.packageDir)
|
return self.compressedArchive.quickVerify(self.getPackageDir())
|
||||||
|
|
||||||
allExtractsOk = True
|
allExtractsOk = True
|
||||||
if not self.uncompressedArchive.quickVerify(self.packageDir):
|
if not self.uncompressedArchive.quickVerify(self.getPackageDir()):
|
||||||
#print "File is incorrect: %s" % (self.uncompressedArchive.filename)
|
#print "File is incorrect: %s" % (self.uncompressedArchive.filename)
|
||||||
allExtractsOk = False
|
allExtractsOk = False
|
||||||
|
|
||||||
if allExtractsOk:
|
if allExtractsOk:
|
||||||
# OK, the uncompressed archive is good; that means there
|
# OK, the uncompressed archive is good; that means there
|
||||||
# shouldn't be a compressed archive file here.
|
# shouldn't be a compressed archive file here.
|
||||||
pathname = Filename(self.packageDir, self.compressedArchive.filename)
|
pathname = Filename(self.getPackageDir(), self.compressedArchive.filename)
|
||||||
pathname.unlink()
|
pathname.unlink()
|
||||||
|
|
||||||
for file in self.extracts:
|
for file in self.extracts:
|
||||||
if not file.quickVerify(self.packageDir):
|
if not file.quickVerify(self.getPackageDir()):
|
||||||
#print "File is incorrect: %s" % (file.filename)
|
#print "File is incorrect: %s" % (file.filename)
|
||||||
allExtractsOk = False
|
allExtractsOk = False
|
||||||
break
|
break
|
||||||
@ -537,7 +559,7 @@ class PackageInfo:
|
|||||||
|
|
||||||
from direct.p3d.PatchMaker import PatchMaker
|
from direct.p3d.PatchMaker import PatchMaker
|
||||||
|
|
||||||
patchMaker = PatchMaker(self.packageDir)
|
patchMaker = PatchMaker(self.getPackageDir())
|
||||||
patchChain = patchMaker.getPatchChainToCurrent(self.descFileBasename, fileSpec)
|
patchChain = patchMaker.getPatchChainToCurrent(self.descFileBasename, fileSpec)
|
||||||
if patchChain is None:
|
if patchChain is None:
|
||||||
# No path.
|
# No path.
|
||||||
@ -613,7 +635,7 @@ class PackageInfo:
|
|||||||
|
|
||||||
if not filename:
|
if not filename:
|
||||||
filename = fileSpec.filename
|
filename = fileSpec.filename
|
||||||
targetPathname = Filename(self.packageDir, filename)
|
targetPathname = Filename(self.getPackageDir(), filename)
|
||||||
targetPathname.setBinary()
|
targetPathname.setBinary()
|
||||||
|
|
||||||
channel = self.http.makeChannel(False)
|
channel = self.http.makeChannel(False)
|
||||||
@ -661,7 +683,7 @@ class PackageInfo:
|
|||||||
if not channel.isValid():
|
if not channel.isValid():
|
||||||
print "Failed to download %s" % (url)
|
print "Failed to download %s" % (url)
|
||||||
|
|
||||||
elif not fileSpec.fullVerify(self.packageDir, pathname = targetPathname):
|
elif not fileSpec.fullVerify(self.getPackageDir(), pathname = targetPathname):
|
||||||
print "After downloading, %s incorrect" % (Filename(fileSpec.filename).getBasename())
|
print "After downloading, %s incorrect" % (Filename(fileSpec.filename).getBasename())
|
||||||
else:
|
else:
|
||||||
# Success!
|
# Success!
|
||||||
@ -687,8 +709,8 @@ class PackageInfo:
|
|||||||
operation. Returns one of stepComplete, stepFailed, or
|
operation. Returns one of stepComplete, stepFailed, or
|
||||||
restartDownload. """
|
restartDownload. """
|
||||||
|
|
||||||
origPathname = Filename(self.packageDir, self.uncompressedArchive.filename)
|
origPathname = Filename(self.getPackageDir(), self.uncompressedArchive.filename)
|
||||||
patchPathname = Filename(self.packageDir, patchfile.file.filename)
|
patchPathname = Filename(self.getPackageDir(), patchfile.file.filename)
|
||||||
result = Filename.temporary('', 'patch_')
|
result = Filename.temporary('', 'patch_')
|
||||||
print "Patching %s with %s" % (origPathname, patchPathname)
|
print "Patching %s with %s" % (origPathname, patchPathname)
|
||||||
|
|
||||||
@ -721,8 +743,8 @@ class PackageInfo:
|
|||||||
archive. Returns one of stepComplete, stepFailed, or
|
archive. Returns one of stepComplete, stepFailed, or
|
||||||
restartDownload. """
|
restartDownload. """
|
||||||
|
|
||||||
sourcePathname = Filename(self.packageDir, self.compressedArchive.filename)
|
sourcePathname = Filename(self.getPackageDir(), self.compressedArchive.filename)
|
||||||
targetPathname = Filename(self.packageDir, self.uncompressedArchive.filename)
|
targetPathname = Filename(self.getPackageDir(), self.uncompressedArchive.filename)
|
||||||
targetPathname.unlink()
|
targetPathname.unlink()
|
||||||
print "Uncompressing %s to %s" % (sourcePathname, targetPathname)
|
print "Uncompressing %s to %s" % (sourcePathname, targetPathname)
|
||||||
decompressor = Decompressor()
|
decompressor = Decompressor()
|
||||||
@ -741,7 +763,7 @@ class PackageInfo:
|
|||||||
step.bytesDone = totalBytes
|
step.bytesDone = totalBytes
|
||||||
self.__updateStepProgress(step)
|
self.__updateStepProgress(step)
|
||||||
|
|
||||||
if not self.uncompressedArchive.quickVerify(self.packageDir):
|
if not self.uncompressedArchive.quickVerify(self.getPackageDir()):
|
||||||
print "after uncompressing, %s still incorrect" % (
|
print "after uncompressing, %s still incorrect" % (
|
||||||
self.uncompressedArchive.filename)
|
self.uncompressedArchive.filename)
|
||||||
return self.stepFailed
|
return self.stepFailed
|
||||||
@ -763,7 +785,7 @@ class PackageInfo:
|
|||||||
self.hasPackage = True
|
self.hasPackage = True
|
||||||
return self.stepComplete
|
return self.stepComplete
|
||||||
|
|
||||||
mfPathname = Filename(self.packageDir, self.uncompressedArchive.filename)
|
mfPathname = Filename(self.getPackageDir(), self.uncompressedArchive.filename)
|
||||||
print "Unpacking %s" % (mfPathname)
|
print "Unpacking %s" % (mfPathname)
|
||||||
mf = Multifile()
|
mf = Multifile()
|
||||||
if not mf.openRead(mfPathname):
|
if not mf.openRead(mfPathname):
|
||||||
@ -779,14 +801,14 @@ class PackageInfo:
|
|||||||
allExtractsOk = False
|
allExtractsOk = False
|
||||||
continue
|
continue
|
||||||
|
|
||||||
targetPathname = Filename(self.packageDir, file.filename)
|
targetPathname = Filename(self.getPackageDir(), file.filename)
|
||||||
targetPathname.unlink()
|
targetPathname.unlink()
|
||||||
if not mf.extractSubfile(i, targetPathname):
|
if not mf.extractSubfile(i, targetPathname):
|
||||||
print "Couldn't extract: %s" % (file.filename)
|
print "Couldn't extract: %s" % (file.filename)
|
||||||
allExtractsOk = False
|
allExtractsOk = False
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not file.quickVerify(self.packageDir):
|
if not file.quickVerify(self.getPackageDir()):
|
||||||
print "After extracting, still incorrect: %s" % (file.filename)
|
print "After extracting, still incorrect: %s" % (file.filename)
|
||||||
allExtractsOk = False
|
allExtractsOk = False
|
||||||
continue
|
continue
|
||||||
@ -814,14 +836,14 @@ class PackageInfo:
|
|||||||
return True
|
return True
|
||||||
assert self not in appRunner.installedPackages
|
assert self not in appRunner.installedPackages
|
||||||
|
|
||||||
mfPathname = Filename(self.packageDir, self.uncompressedArchive.filename)
|
mfPathname = Filename(self.getPackageDir(), self.uncompressedArchive.filename)
|
||||||
mf = Multifile()
|
mf = Multifile()
|
||||||
if not mf.openRead(mfPathname):
|
if not mf.openRead(mfPathname):
|
||||||
print "Couldn't open %s" % (mfPathname)
|
print "Couldn't open %s" % (mfPathname)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# We mount it under its actual location on disk.
|
# We mount it under its actual location on disk.
|
||||||
root = self.packageDir.cStr()
|
root = self.getPackageDir().cStr()
|
||||||
|
|
||||||
vfs = VirtualFileSystem.getGlobalPtr()
|
vfs = VirtualFileSystem.getGlobalPtr()
|
||||||
vfs.mount(mf, root, vfs.MFReadOnly)
|
vfs.mount(mf, root, vfs.MFReadOnly)
|
||||||
@ -830,7 +852,7 @@ class PackageInfo:
|
|||||||
# there. We have to take a bit of care to check if it's
|
# there. We have to take a bit of care to check if it's
|
||||||
# already there, since there can be some ambiguity in
|
# already there, since there can be some ambiguity in
|
||||||
# os-specific path strings.
|
# os-specific path strings.
|
||||||
osRoot = self.packageDir.toOsSpecific()
|
osRoot = self.getPackageDir().toOsSpecific()
|
||||||
foundOnPath = False
|
foundOnPath = False
|
||||||
for p in sys.path:
|
for p in sys.path:
|
||||||
if osRoot == p:
|
if osRoot == p:
|
||||||
@ -849,7 +871,7 @@ class PackageInfo:
|
|||||||
# Put it on the model-path, too. We do this indiscriminantly,
|
# Put it on the model-path, too. We do this indiscriminantly,
|
||||||
# because the Panda3D runtime won't be adding things to the
|
# because the Panda3D runtime won't be adding things to the
|
||||||
# model-path, so it shouldn't be already there.
|
# model-path, so it shouldn't be already there.
|
||||||
getModelPath().appendDirectory(self.packageDir)
|
getModelPath().appendDirectory(self.getPackageDir())
|
||||||
|
|
||||||
# Set the environment variable to reference the package root.
|
# Set the environment variable to reference the package root.
|
||||||
envvar = '%s_ROOT' % (self.packageName.upper())
|
envvar = '%s_ROOT' % (self.packageName.upper())
|
||||||
@ -857,7 +879,7 @@ class PackageInfo:
|
|||||||
|
|
||||||
# Now that the environment variable is set, read all of the
|
# Now that the environment variable is set, read all of the
|
||||||
# prc files in the package.
|
# prc files in the package.
|
||||||
appRunner.loadMultifilePrcFiles(mf, self.packageDir)
|
appRunner.loadMultifilePrcFiles(mf, self.getPackageDir())
|
||||||
|
|
||||||
# Also, find any toplevel Python packages, and add these as
|
# Also, find any toplevel Python packages, and add these as
|
||||||
# shared packages. This will allow different packages
|
# shared packages. This will allow different packages
|
||||||
|
Loading…
x
Reference in New Issue
Block a user