Ejemplo n.º 1
0
    def localpath(self, storageid, itempath):

        try:
            storage = self.storagemanager.storage(storageid)

        except KeyError:
            return None

        if storage.islocal() and storage.contains(itempath):
            return storage.localpath(itempath)

        if self.cache.contains(storageid, itempath):
            return self.cache.pathto(storageid, itempath)

        return None
Ejemplo n.º 2
0
    def load(self, storageid, itempath):

        # assuming that checking cache is very cheap operation, do it first
        if self.cache.contains(storageid, itempath):
            return self.cache.pathto(storageid, itempath)

        storage = self.storagemanager.storage(storageid)

        if storage.islocal():

            if storage.contains(itempath):
                return {"state": "OK"}
            else:
                raise LookupError("Item %s not found in storage %s " % (itempath, storageid))

        else:

            if storage.contains(itempath):
                cachepath = self.cache.pathto(storageid, itempath)
                ensuredir(os.path.split(cachepath)[0])
                storage.loaditem(itempath, cachepath)
                return {"state": "OK", "out": "Item %s loaded from %s to %s" % (itempath, storageid, cachepath)}

            raise LookupError("Item %s not found in storage %s " % (itempath, storageid))