示例#1
0
    def sync_resource(self, res_name, file_path):
        digest = sha256sum(file_path)

        if not self.rpc_call("has_resource", digest):
            msg = "Transfering %s to machine %s as '%s'" % (file_path,
                                                            self.get_id(),
                                                            res_name)
            logging.debug(msg)

            remote_path = self.copy_file_to_machine(file_path)
            self.rpc_call("add_resource_to_cache",
                           "file", remote_path, res_name)
        return digest
示例#2
0
    def add_file_entry(self, filepath, entry_name):
        entry_hash = sha256sum(filepath)

        if entry_hash in self._index["entries"]:
            raise ResourceCacheError("File already in cache")

        entry_path = "%s/%s" % (self._root, entry_hash)
        if os.path.exists(entry_path):
            os.remove(entry_path)

        shutil.move(filepath, entry_path)

        entry = {"name": entry_name,
                 "path": entry_path,
                 "last_used": int(time.time()),
                 "digest": entry_hash,
                 "type": "file"}
        self._index["entries"][entry_hash] = entry

        self._save_index()

        return entry_hash