예제 #1
0
파일: inputs.py 프로젝트: thozza/osbuild
    def dispatch(self, method: str, args, _fds):
        if method == "map":
            store = StoreClient(connect_to=args["api"]["store"])
            r = self.map(store, args["origin"], args["refs"], args["target"],
                         args["options"])
            return r, None

        raise host.ProtocolError("Unknown method")
예제 #2
0
파일: devices.py 프로젝트: thozza/osbuild
    def dispatch(self, method: str, args, _fds):
        if method == "open":
            r = self.open(args["dev"], args["parent"], args["tree"],
                          args["options"])
            return r, None
        if method == "close":
            r = self.close()
            return r, None

        raise host.ProtocolError("Unknown method")
예제 #3
0
    def dispatch(self, method: str, args: Any, fds: FdSet):
        ret = None

        if method == "exception":
            raise ValueError("Remote Exception")
        if method == "echo":
            ret = args
        elif method == "echo-fd":
            ret = args
            with tempfile.TemporaryFile("w+") as f:
                with os.fdopen(fds.steal(0)) as d:
                    f.write(d.read())
                f.seek(0)
                fds = [os.dup(f.fileno())]
                self.register_fds(fds)

        elif method == "identify":
            ret = self.id
        elif method == "invalid-fd":
            ret = []
            with tempfile.TemporaryFile("w+") as f:
                valid_fd = os.dup(f.fileno())
            invalid_fd = valid_fd + 10
            fds = [valid_fd, invalid_fd]
            self.register_fds([valid_fd])
        elif method == "check-fds-are-closed":
            while self.fds:
                fd = self.fds.pop()
                try:
                    os.close(fd)
                except OSError as e:
                    if e.errno == errno.EBADF:
                        print(f"fd '{fd}' was closed")
                        continue
                    raise
                raise ValueError(f"fd '{fd}' was not closed")
        elif method == "signal_me_3_times":
            self.emit_signal(0)
            self.emit_signal(1)
            self.emit_signal(2)
        elif method == "signal_me_on_fd":
            with tempfile.TemporaryFile("w+") as f:
                with os.fdopen(fds.steal(0)) as d:
                    f.write(d.read())
                f.seek(0)
                fds = [os.dup(f.fileno())]
                self.register_fds(fds)
                self.emit_signal("that should do it", fds)
        else:
            raise host.ProtocolError("unknown method:", method)

        return ret, fds
예제 #4
0
    def dispatch(self, method: str, args, _fds):
        if method == "mount":
            r = self.mount(args)
            return r, None

        raise host.ProtocolError("Unknown method")