def __init__(self, command: CommandInterface = None, *, current_node: GraphType = None) -> None: """An interactive client that resolves calls through the gives client Exposes the command graph API in such a way that it can be traversed directly on this object. The command resolution for this object is done via the command interface. Parameters ---------- command: CommandInterface The object that is used to resolve command graph calls, as well as navigate the command graph. current_node: CommandGraphNode The current node that is pointed to in the command graph. If not specified, the command graph root is used. """ if command is None: command = IPCCommandInterface(Client(find_sockfile())) self._command = command if current_node is None: self._current_node = CommandGraphRoot() # type: GraphType else: self._current_node = current_node
def run_cmd(opts) -> None: if opts.socket is None: socket = ipc.find_sockfile() else: socket = opts.socket client = ipc.Client(socket) root = graph.CommandGraphRoot() cmd = [opts.cmd] if opts.args: cmd.extend(opts.args) proc = subprocess.Popen(cmd) match_args = {"net_wm_pid": proc.pid} rule_args = {"float": opts.float, "intrusive": opts.intrusive, "group": opts.group, "break_on_match": not opts.dont_break} cmd = root.call("add_rule") _, rule_id = client.send((root.selectors, cmd.name, (match_args, rule_args), {})) def remove_rule() -> None: cmd = root.call("remove_rule") client.send((root.selectors, cmd.name, (rule_id,), {})) atexit.register(remove_rule) proc.wait()
def main(): opts = parse_args() lines = opts.lines seconds = opts.seconds force_start = opts.force_start if opts.socket is None: socket = ipc.find_sockfile() else: socket = opts.socket client = ipc.Client(socket) try: if not opts.raw: curses.wrapper(get_stats, client, limit=lines, seconds=seconds, force_start=force_start) else: raw_stats(client, limit=lines, force_start=force_start) except TraceNotStarted: print("tracemalloc not started on qtile, start by setting " "PYTHONTRACEMALLOC=1 before starting qtile") print("or force start tracemalloc now, but you'll lose early traces") exit(1) except TraceCantStart: print("Can't start tracemalloc on qtile, check the logs") except KeyboardInterrupt: exit(-1)
def top(opts): if not ENABLED: raise Exception('Could not import tracemalloc') lines = opts.lines seconds = opts.seconds force_start = opts.force_start if opts.socket is None: socket = ipc.find_sockfile() else: socket = opts.socket c = client.InteractiveCommandClient( interface.IPCCommandInterface(ipc.Client(socket), ), ) try: if not opts.raw: curses.wrapper(get_stats, c, limit=lines, seconds=seconds, force_start=force_start) else: raw_stats(c, limit=lines, force_start=force_start) except TraceNotStarted: print("tracemalloc not started on qtile, start by setting " "PYTHONTRACEMALLOC=1 before starting qtile") print("or force start tracemalloc now, but you'll lose early traces") sys.exit(1) except TraceCantStart: print("Can't start tracemalloc on qtile, check the logs") except KeyboardInterrupt: sys.exit(1) except curses.error: print("Terminal too small for curses interface.") raw_stats(c, limit=lines, force_start=force_start)
def main() -> None: "Runs tool according to specified arguments." description = 'Simple tool to expose qtile.command functionality to shell.' epilog = textwrap.dedent('''\ Examples: qtile-cmd qtile-cmd -o cmd qtile-cmd -o cmd -f prev_layout -i qtile-cmd -o cmd -f prev_layout -a 3 # prev_layout on group 3 qtile-cmd -o group 3 -f focus_back''') fmt = argparse.RawDescriptionHelpFormatter parser = argparse.ArgumentParser(description=description, epilog=epilog, formatter_class=fmt) parser.add_argument('--object', '-o', dest='obj_spec', nargs='+', help='Specify path to object (space separated). ' 'If no --function flag display available commands. ' 'Use `cmd` to specify root command.') parser.add_argument('--function', '-f', default="help", help='Select function to execute.') parser.add_argument('--args', '-a', nargs='+', default=[], help='Set arguments supplied to function.') parser.add_argument( '--info', '-i', action='store_true', help= 'With both --object and --function args prints documentation for function.' ) parser.add_argument("--socket", "-s", help='Path of the Qtile IPC socket.') args = parser.parse_args() if args.obj_spec: sock_file = args.socket or find_sockfile() ipc_client = Client(sock_file) cmd_object = IPCCommandInterface(ipc_client) cmd_client = InteractiveCommandClient(cmd_object) obj = get_object(cmd_client, args.obj_spec) if args.function == "help": print_commands("-o " + " ".join(args.obj_spec), obj) elif args.info: print(get_formated_info(obj, args.function, args=True, short=False)) else: ret = run_function(obj, args.function, args.args) if ret is not None: pprint.pprint(ret) else: print_base_objects() sys.exit(1)
def main() -> None: opts = parse_args() if opts.socket is None: socket = ipc.find_sockfile() else: socket = opts.socket client = ipc.Client(socket) root = command_graph.CommandGraphRoot() proc = subprocess.Popen(opts.cmd) match_args = {"net_wm_pid": proc.pid} rule_args = { "float": opts.float, "intrusive": opts.intrusive, "group": opts.group, "break_on_match": not opts.dont_break } cmd = root.navigate("add_rule", None) assert isinstance(cmd, command_graph.CommandGraphCall) _, rule_id = client.send( (root.selectors, cmd.name, (match_args, rule_args), {})) def remove_rule(): cmd = root.navigate("remove_rule", None) assert isinstance(cmd, command_graph.CommandGraphCall) client.send((root.selectors, cmd.name, (rule_id, ), {})) atexit.register(remove_rule) proc.wait()
def __init__(self, command: CommandInterface = None, *, current_node: CommandGraphNode | None = None) -> None: """A client that resolves calls through the command object interface Exposes a similar API to the command graph, but performs resolution of objects. Any navigation done on the command graph is resolved at the point it is invoked. This command resolution is done via the command interface. Parameters ---------- command: CommandInterface The object that is used to resolve command graph calls, as well as navigate the command graph. current_node: CommandGraphNode The current node that is pointed to in the command graph. If not specified, the command graph root is used. """ if command is None: command = IPCCommandInterface(Client(find_sockfile())) self._command = command self._current_node = current_node if current_node is not None else CommandGraphRoot( )
def cmd_obj(args) -> None: "Runs tool according to specified arguments." if args.obj_spec: sock_file = args.socket or find_sockfile() ipc_client = Client(sock_file) cmd_object = IPCCommandInterface(ipc_client) cmd_client = CommandClient(cmd_object) obj = get_object(cmd_client, args.obj_spec) if args.function == "help": try: print_commands("-o " + " ".join(args.obj_spec), obj) except CommandError: if len(args.obj_spec) == 1: print( f"{args.obj_spec} object needs a specified identifier e.g. '-o bar top'." ) sys.exit(1) else: raise elif args.info: print( args.function + get_formated_info(obj, args.function, args=True, short=False)) else: ret = run_function(obj, args.function, args.args) if ret is not None: pprint.pprint(ret) else: print_base_objects() sys.exit(1)
def _prepare_socket_path( self, socket_path: Optional[str] = None, ) -> str: if socket_path is None: socket_path = ipc.find_sockfile(self.core.display_name) if os.path.exists(socket_path): os.unlink(socket_path) return socket_path
def qshell(args) -> None: if args.socket is None: socket = ipc.find_sockfile() else: socket = args.socket client = ipc.Client(socket, is_json=args.is_json) cmd_object = interface.IPCCommandInterface(client) qsh = sh.QSh(cmd_object) if args.command is not None: qsh.process_line(args.command) else: qsh.loop()
def main() -> None: import argparse parser = argparse.ArgumentParser() parser.add_argument( '--version', action='version', version='%(prog)s 0.3', ) parser.add_argument( "-s", "--socket", action="store", type=str, default=None, help='Use specified socket to connect to qtile.' ) parser.add_argument( "-r", "--run", action="store", type=str, default=None, dest="pyfile", help='The full path to python file with the \"main\" function to call.' ) parser.add_argument( "-c", "--command", action="store", type=str, default=None, help='Run the specified qshell command and exit.' ) parser.add_argument( "-j", "--json", action="store_true", default=False, dest="is_json", help='Use json in order to communicate with qtile server.' ) args = parser.parse_args() if args.socket is None: socket = ipc.find_sockfile() else: socket = args.socket client = ipc.Client(socket, is_json=args.is_json) cmd_object = command_interface.IPCCommandInterface(client) qsh = sh.QSh(cmd_object) if args.pyfile is None: if args.command is not None: qsh.process_line(args.command) else: qsh.loop() else: print(qsh.process_line("run_external({})".format(args.pyfile)))
def _prepare_socket_path(self, socket_path: Optional[str] = None) -> str: if socket_path is None: # Dots might appear in the host part of the display name # during remote X sessions. Let's strip the host part first display_name = self.qtile.core.display_name display_number = display_name.partition(":")[2] if "." not in display_number: display_name += ".0" socket_path = ipc.find_sockfile(display_name) if os.path.exists(socket_path): os.unlink(socket_path) return socket_path
def qshell(args) -> None: if args.socket is None: socket = ipc.find_sockfile() else: socket = args.socket client = ipc.Client(socket, is_json=args.is_json) cmd_object = command_interface.IPCCommandInterface(client) qsh = sh.QSh(cmd_object) if args.pyfile is None: if args.command is not None: qsh.process_line(args.command) else: qsh.loop() else: print(qsh.process_line("run_external({})".format(args.pyfile)))
def __init__(self, kore: base.Core, config, *, fname: str = None, no_spawn=False, state=None) -> None: """Manages a qtile session :param kore: The core backend to use for the session. :param config: The configuration to use for the qtile instance. :param fname: The file name to use as the qtile socket file. :param no_spawn: If the instance has already been started, then don't re-run the startup once hook. :param state: The state to restart the qtile instance with. """ eventloop = asyncio.new_event_loop() asyncio.set_event_loop(eventloop) self.qtile = Qtile(kore, config, eventloop, no_spawn=no_spawn, state=state) if fname is None: # Dots might appear in the host part of the display name # during remote X sessions. Let's strip the host part first display_name = kore.display_name display_number = display_name.partition(":")[2] if "." not in display_number: display_name += ".0" fname = ipc.find_sockfile(display_name) if os.path.exists(fname): os.unlink(fname) self.server = ipc.Server(fname, self.qtile.server.call, eventloop)
def cmd_obj(args) -> None: "Runs tool according to specified arguments." if args.obj_spec: sock_file = args.socket or find_sockfile() ipc_client = Client(sock_file) cmd_object = IPCCommandInterface(ipc_client) cmd_client = InteractiveCommandClient(cmd_object) obj = get_object(cmd_client, args.obj_spec) if args.function == "help": print_commands("-o " + " ".join(args.obj_spec), obj) elif args.info: print(get_formated_info(obj, args.function, args=True, short=False)) else: ret = run_function(obj, args.function, args.args) if ret is not None: pprint.pprint(ret) else: print_base_objects() sys.exit(1)
def qtile(self): if self._qtile is None and qtile_support is True: self._qtile = CommandClient( command=IPCCommandInterface(Client(find_sockfile()))) return self._qtile
# SOFTWARE. import nest_asyncio nest_asyncio.apply() from typing import List # noqa: F401 import os import sys import subprocess from libqtile.config import Key, Screen, Group, Drag, Click, Match from libqtile.lazy import lazy from libqtile import layout, hook, bar, widget from libqtile.ipc import find_sockfile, Client from libqtile.command_client import InteractiveCommandClient from libqtile.command_interface import IPCCommandInterface client = InteractiveCommandClient(IPCCommandInterface(Client(find_sockfile()))) from helper import run from controls import next_keyboard from apperance import widget_defaults, extension_defaults from apperance import top_bar, bottom_bar from debug_logging import logger # This has to be run this before screens are defined, so that it correctly picks up the order and resulotion # run("xrandr --output DVI-D-1 --mode 1600x1200 --left-of HDMI-2 --output HDMI-2 --mode 2560x1080 --output HDMI-1 --mode 1920x1080 --right-of HDMI-2") mod = "mod4" alt = 'mod1' username = "******" def bring_group_to_front(group_name):
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) socket_path = ipc.find_sockfile() ipc_client = ipc.Client(socket_path) cmd_object = command.interface.IPCCommandInterface(ipc_client) self.qsh = sh.QSh(cmd_object)
from libqtile.ipc import find_sockfile, Client as IPCClient from libqtile.command_client import InteractiveCommandClient from libqtile.command_interface import IPCCommandInterface if __name__ == '__main__': client = InteractiveCommandClient( IPCCommandInterface(IPCClient(find_sockfile()))) # does not work: print(client.display_kb()) # print(getattr(client, 'display_kb')())
def __init__(self): self.color = 0 self.client = InteractiveCommandClient( IPCCommandInterface(IPCClient(find_sockfile())))