コード例 #1
0
ファイル: command_interface.py プロジェクト: zfenj/qtile
    def has_item(self, node: CommandGraphNode, object_type: str,
                 item: str) -> bool:
        """Check if the given item exists

        Resolves the available commands for the given command node of the given
        command type.  Performs the resolution of the items through the given
        IPC client.

        Parameters
        ----------
        node : CommandGraphNode
            The node to check for items
        object_type : str
            The type of object to check for items.
        command : str
            The name of the item to check for

        Returns
        -------
        bool
            True if the item is resolved on the given node
        """
        items_call = node.call("items")
        _, items = self.execute(items_call, (object_type, ), {})
        return items is not None and item in items
コード例 #2
0
ファイル: command_interface.py プロジェクト: yoryo33/qtile
    def has_command(self, node: CommandGraphNode, command: str) -> bool:
        """Check if the given command exists

        Resolves the allowed commands over the IPC interface, and returns a
        boolean indicating of the given command is valid.

        Parameters
        ----------
        node : CommandGraphNode
            The node to check for commands
        command : str
            The name of the command to check for

        Returns
        -------
        bool
            True if the command is resolved on the given node
        """
        cmd_call = node.call("commands")
        commands = self.execute(cmd_call, (), {})
        return command in commands
コード例 #3
0
    def _find_node(self, src: command_graph.CommandGraphNode,
                   *paths: str) -> Optional[command_graph.CommandGraphNode]:
        """Find an object in the command graph

        Return the object in the command graph at the specified path relative
        to the given node.
        """
        if len(paths) == 0:
            return src

        path, *next_path = paths

        next_node = None
        if path == "..":
            next_node = src.parent or src
        else:
            attrs, items = self._inspect(src)
            for transformation in [str, int]:
                try:
                    transformed_path = transformation(path)
                except ValueError:
                    continue

                if attrs is not None and transformed_path in attrs:
                    nav_node = src.navigate(transformed_path, None)
                    next_node = nav_node
                    break
                elif items is not None and transformed_path in items:
                    assert isinstance(src, command_graph.CommandGraphObject)
                    nav_node = src.parent.navigate(src.object_type,
                                                   transformed_path)
                    next_node = nav_node
                    break

        if next_node:
            return self._find_node(next_node, *next_path)
        else:
            return None