Example #1
0
    def fromFile(self, packageDir, filename, pathname = None, st = None):
        """ Reads the file information from the indicated file.  If st
        is supplied, it is the result of os.stat on the filename. """

        vfs = VirtualFileSystem.getGlobalPtr()

        filename = Filename(filename)
        if pathname is None:
            pathname = Filename(packageDir, filename)

        self.filename = str(filename)
        self.basename = filename.getBasename()

        if st is None:
            st = os.stat(pathname.toOsSpecific())
        self.size = st.st_size
        self.timestamp = int(st.st_mtime)

        self.readHash(pathname)
Example #2
0
    def fromFile(self, packageDir, filename, pathname=None, st=None):
        """ Reads the file information from the indicated file.  If st
        is supplied, it is the result of os.stat on the filename. """

        vfs = VirtualFileSystem.getGlobalPtr()

        filename = Filename(filename)
        if pathname is None:
            pathname = Filename(packageDir, filename)

        self.filename = filename.cStr()
        self.basename = filename.getBasename()

        if st is None:
            st = os.stat(pathname.toOsSpecific())
        self.size = st.st_size
        self.timestamp = st.st_mtime

        self.readHash(pathname)
Example #3
0
def findDataFilename(name, extract=False, executable=False):
    """
    Resolve a filename along Panda's model-path.
    :param name:
    :return: filename or None
    """
    from panda3d.core import Filename, getModelPath
    from panda3d.core import VirtualFileSystem

    logging.debug("findDataFilename: "+ name +" on: \n" + str(getModelPath().getValue()))

    vfs = VirtualFileSystem.getGlobalPtr()
    fileName = Filename(name)
    vfile = vfs.findFile(fileName, getModelPath().getValue())
    if not vfile:
        if extract and name.endswith(".exe"):
            fileName = Filename(name[:-4])
            vfile = vfs.findFile(fileName, getModelPath().getValue())
        if not vfile:
            return None

    fileName = vfile.getFilename()
    if extract:
        # see if the file is embedded in some virtual place OR has the wrong perms
        from panda3d.core import SubfileInfo

        info = SubfileInfo()

        needsCopy = not vfile.getSystemInfo(info) or info.getFilename() != fileName
        if not needsCopy:
            if executable:
                # see if on Linux or OSX and not executable
                try:
                    stat = os.stat(fileName.toOsSpecific())
                    if (stat.st_mode & 0111) == 0:
                        logging.error("Found %s locally, but not marked executable!", fileName)
                        needsCopy = True
                except:
                    needsCopy = True

        if needsCopy:
            # virtual file needs to be copied out
            global _tempDir
            if not _tempDir:
                import tempfile
                _tempDir = os.path.realpath(tempfile.mkdtemp())
                #print "Temp dir:",_tempDir

            xpath = _tempDir + '/' + fileName.getBasename()
            xTarg = Filename.fromOsSpecific(xpath)

            # on Windows, case-sensitivity must be honored for the following to work
            xTarg.makeCanonical()

            print "extracting",fileName,"to",xTarg

            if not xTarg.exists():
                if not vfs.copyFile(fileName, xTarg):
                    raise IOError("extraction failed when copying " + str(fileName) + " to " + str(xTarg))

            fileName = xTarg
            os.chmod(fileName.toOsSpecific(), 0777)

    return fileName