コード例 #1
0
    def getTags(self, filename=None):
        def _getMaterialTags(filename):
            return material.peekMetadata(filename)

        if self._matFileCache is None:
            # Init cache
            self.loadCache()
            self._matFileCache = filecache.updateFileCache(
                self.materials, 'mhmat', _getMaterialTags, self._matFileCache,
                False)

        result = set()
        # TODO move most of this (duplicated) logic inside a class in filecache

        if filename:
            fileId = getpath.canonicalPath(filename)
            if fileId not in self._matFileCache:
                # Lazily update cache
                self._matFileCache = filecache.updateFileCache(
                    self.materials + [os.path.dirname(fileId)], 'mhmat',
                    _getMaterialTags, self._matFileCache, False)

            if fileId in self._matFileCache:
                metadata = self._matFileCache[fileId]
                if metadata is not None:
                    mtime, name, tags = metadata

                    if mtime < os.path.getmtime(fileId):
                        # Queried file was updated, update stale cache
                        self._matFileCache = filecache.updateFileCache(
                            self.materials + [os.path.dirname(fileId)],
                            'mhmat', _getMaterialTags, self._matFileCache,
                            False)
                        metadata = self._matFileCache[fileId]
                        mtime, name, tags = metadata

                    result = result.union(tags)
            else:
                log.warning(
                    'Could not get tags for material file %s. Does not exist in Material library.',
                    filename)
            return result
        else:
            for (path, values) in self._matFileCache.items():
                _, name, tags = values
                result = result.union(tags)
        return result
コード例 #2
0
    def getTags(self, filename=None):
        import filecache
        def _getSkeletonTags(filename):
            return skeleton.peekMetadata(filename)

        if self._skelFileCache is None:
            # Init cache
            self.loadCache()
            self._skelFileCache = filecache.updateFileCache(self.paths, 'mhmat', _getSkeletonTags,self._skelFileCache, False)

        # TODO move most of this (duplicated) logic inside a class in filecache
        result = set()

        if filename:
            fileId = getpath.canonicalPath(filename)
            if fileId not in self._skelFileCache:
                # Lazily update cache
                self._skelFileCache = filecache.updateFileCache(self.paths + [os.path.dirname(fileId)], 'json', _getSkeletonTags,self._skelFileCache, False)

            if fileId in self._skelFileCache:
                metadata = self._skelFileCache[fileId]
                if metadata is not None:
                    mtime, name, desc, tags = metadata

                    if mtime < os.path.getmtime(fileId):
                        # Queried file was updated, update stale cache
                        self._skelFileCache = filecache.updateFileCache(self.paths + [os.path.dirname(fileId)], 'json', _getSkeletonTags,self._skelFileCache, False)
                        metadata = self._skelFileCache[fileId]
                        mtime, name, desc, tags = metadata

                    result = result.union(tags)
            else:
                log.warning('Could not get tags for material file %s. Does not exist in Material library.', filename)
            return result
        else:
            for (path, values) in self._skelFileCache.items():
                _, name, desc, tags = values
                result = result.union(tags)
        return result
コード例 #3
0
ファイル: proxy.py プロジェクト: orezpraw/unnaturalcode
def updateProxyFileCache(paths, fileExts, cache=None, proxytype="Clothes"):
    """
    Update cache of proxy files in the specified paths. If no cache is given as
    parameter, a new cache is created.
    This cache contains per canonical filename (key) the UUID and tags of that
    proxy file.
    Cache entries are invalidated if their modification time has changed, or no
    longer exist on disk.
    """
    import filecache

    if proxytype == 'Proxymeshes':
        fileExts = ['.mhpxy', '.proxy']
    else:
        fileExts = ['.mhpxy', '.mhclo']

    return filecache.updateFileCache(paths, fileExts, peekMetadata, cache)
コード例 #4
0
ファイル: proxy.py プロジェクト: solsane/unnaturalcode
def updateProxyFileCache(paths, fileExts, cache=None, proxytype="Clothes"):
    """
    Update cache of proxy files in the specified paths. If no cache is given as
    parameter, a new cache is created.
    This cache contains per canonical filename (key) the UUID and tags of that
    proxy file.
    Cache entries are invalidated if their modification time has changed, or no
    longer exist on disk.
    """
    import filecache

    if proxytype == 'Proxymeshes':
        fileExts = ['.mhpxy', '.proxy']
    else:
        fileExts = ['.mhpxy', '.mhclo']

    return filecache.updateFileCache(paths, fileExts, peekMetadata, cache)