Exemplo n.º 1
0
    def start(self, config_class, no_spawn=False, state=None):
        rpipe, wpipe = multiprocessing.Pipe()

        def run_qtile():
            try:
                os.environ.pop("DISPLAY", None)
                os.environ.pop("WAYLAND_DISPLAY", None)
                kore = self.backend.create()
                os.environ.update(self.backend.env)
                init_log(self.log_level, log_path=None, log_color=False)
                Qtile(
                    kore,
                    config_class(),
                    socket_path=self.sockfile,
                    no_spawn=no_spawn,
                    state=state,
                ).loop()
            except Exception:
                wpipe.send(traceback.format_exc())

        self.proc = multiprocessing.Process(target=run_qtile)
        self.proc.start()

        # First, wait for socket to appear
        if can_connect_qtile(self.sockfile, ok=lambda: not rpipe.poll()):
            ipc_client = ipc.Client(self.sockfile)
            ipc_command = command.interface.IPCCommandInterface(ipc_client)
            self.c = command.client.InteractiveCommandClient(ipc_command)
            self.backend.configure(self)
            return
        if rpipe.poll(0.1):
            error = rpipe.recv()
            raise AssertionError("Error launching qtile, traceback:\n%s" % error)
        raise AssertionError("Error launching qtile")
Exemplo n.º 2
0
    def start(self, config_class):
        rpipe, wpipe = multiprocessing.Pipe()

        def run_qtile():
            try:
                kore = xcore.XCore(display_name=self.display)
                init_log(self.log_level, log_path=None, log_color=False)
                q = SessionManager(kore, config_class(), fname=self.sockfile)
                q.loop()
            except Exception:
                wpipe.send(traceback.format_exc())

        self.proc = multiprocessing.Process(target=run_qtile)
        self.proc.start()

        # First, wait for socket to appear
        if can_connect_qtile(self.sockfile, ok=lambda: not rpipe.poll()):
            ipc_client = ipc.Client(self.sockfile)
            ipc_command = command_interface.IPCCommandInterface(ipc_client)
            self.c = command_client.InteractiveCommandClient(ipc_command)
            return
        if rpipe.poll(sleep_time):
            error = rpipe.recv()
            raise AssertionError("Error launching Qtile, traceback:\n%s" %
                                 error)
        raise AssertionError("Error launching Qtile")
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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()
Exemplo n.º 6
0
    def start(self, config_class):
        rpipe, wpipe = multiprocessing.Pipe()

        def run_qtile():
            llvl = logging.DEBUG if pytest.config.getoption(
                "--debuglog") else logging.INFO
            kore = xcore.XCore()
            try:
                init_log(llvl, log_path=None, log_color=False)
                q = QtileManager(kore, config_class(), self.display,
                                 self.sockfile)
                q.loop()
            except Exception:
                wpipe.send(traceback.format_exc())

        self.proc = multiprocessing.Process(target=run_qtile)
        self.proc.start()

        # First, wait for socket to appear
        if can_connect_qtile(self.sockfile):
            ipc_client = ipc.Client(self.sockfile)
            ipc_command = command_interface.IPCCommandInterface(ipc_client)
            self.c = command_client.InteractiveCommandClient(ipc_command)
            return
        if rpipe.poll(sleep_time):
            error = rpipe.recv()
            raise AssertionError("Error launching Qtile, traceback:\n%s" %
                                 error)
        raise AssertionError("Error launching Qtile")
Exemplo n.º 7
0
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()
Exemplo n.º 8
0
def can_connect_qtile(socket_path):
    ipc_client = ipc.Client(socket_path)
    ipc_command = command_interface.IPCCommandInterface(ipc_client)
    client = command_client.InteractiveCommandClient(ipc_command)
    val = client.status()
    if val == 'OK':
        return True
    return False
Exemplo n.º 9
0
 def send(self, fname, data, q):
     c = ipc.Client(fname)
     while 1:
         try:
             d = c.send(data)
         except socket.error:
             continue
         q.put(d)
         return
Exemplo n.º 10
0
def test_do_cd(qtile):
    client = ipc.Client(qtile.sockfile)
    command = IPCCommandInterface(client)
    sh = QSh(command)
    assert sh.do_cd("layout") == 'layout'
    assert sh.do_cd("0") == 'layout[0]'
    assert sh.do_cd("..") == '/'
    assert sh.do_cd("layout") == 'layout'
    assert sh.do_cd("0/wibble") == 'No such path.'
Exemplo n.º 11
0
def test_ls(qtile):
    client = ipc.Client(qtile.sockfile)
    command = IPCCommandInterface(client)
    sh = QSh(command)
    assert sh.do_ls("") == "bar/     group/   layout/  screen/  widget/  window/"
    assert sh.do_ls("layout") == "group/   window/  screen/  0/     "

    assert sh.do_cd("layout") == "layout"
    assert sh.do_ls("") == "group/   window/  screen/  0/     "
    assert sh.do_ls("screen") == "layout/  window/  bar/   "
Exemplo n.º 12
0
def test_do_cd(manager):
    client = ipc.Client(manager.sockfile)
    command = IPCCommandInterface(client)
    sh = QSh(command)
    assert sh.do_cd("layout") == 'layout'
    assert sh.do_cd("../layout/0") == 'layout[0]'
    assert sh.do_cd("..") == '/'
    assert sh.do_cd("layout") == 'layout'
    assert sh.do_cd("../layout0/wibble") == 'No such path.'
    assert sh.do_cd(None) == '/'
Exemplo n.º 13
0
def can_connect_qtile(socket_path, *, ok=None):
    if ok is not None and not ok():
        raise AssertionError()

    ipc_client = ipc.Client(socket_path)
    ipc_command = command.interface.IPCCommandInterface(ipc_client)
    client = command.client.InteractiveCommandClient(ipc_command)
    val = client.status()
    if val == "OK":
        return True
    return False
Exemplo n.º 14
0
def test_ls(manager):
    client = ipc.Client(manager.sockfile)
    command = IPCCommandInterface(client)
    sh = QSh(command)
    assert sh.do_ls(None) == "bar/     group/   layout/  screen/  widget/  window/"
    assert sh.do_ls("") == "bar/     group/   layout/  screen/  widget/  window/"
    assert sh.do_ls("layout") == "layout/group/   layout/window/  layout/screen/  layout[0]/    "

    assert sh.do_cd("layout") == "layout"
    assert sh.do_ls(None) == "group/   window/  screen/"
    assert sh.do_ls("screen") == "screen/layout/  screen/window/  screen/bar/   "
Exemplo n.º 15
0
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()
Exemplo n.º 16
0
def test_columnize(manager):
    client = ipc.Client(manager.sockfile)
    command = IPCCommandInterface(client)
    sh = QSh(command)
    assert sh.columnize(["one", "two"]) == "one  two"

    sh.termwidth = 1
    assert sh.columnize(["one", "two"], update_termwidth=False) == "one\ntwo"

    sh.termwidth = 15
    v = sh.columnize(["one", "two", "three", "four", "five"], update_termwidth=False)
    assert v == 'one    two  \nthree  four \nfive '
Exemplo n.º 17
0
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)))
Exemplo n.º 18
0
def test_call(manager):
    client = ipc.Client(manager.sockfile)
    command = IPCCommandInterface(client)
    sh = QSh(command)
    assert sh.process_line("status()") == "OK"

    v = sh.process_line("nonexistent()")
    assert v == "Command does not exist: nonexistent"

    v = sh.process_line("status(((")
    assert v == "Invalid command: status((("

    v = sh.process_line("status(1)")
    assert v.startswith("Caught command exception")
Exemplo n.º 19
0
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)))
Exemplo n.º 20
0
def test_complete(manager):
    client = ipc.Client(manager.sockfile)
    command = IPCCommandInterface(client)
    sh = QSh(command)
    assert sh._complete("c", "c") == [
        "cd",
        "commands",
        "critical",
    ]

    assert sh._complete("cd l", "l") == ["layout/"]
    assert sh._complete("cd layout/", "layout/") == [
        "layout/" + x for x in ["group", "window", "screen", "0"]
    ]
    assert sh._complete("cd layout/", "layout/g") == ["layout/group/"]
Exemplo n.º 21
0
def test_help(manager):
    client = ipc.Client(manager.sockfile)
    command = IPCCommandInterface(client)
    sh = QSh(command)
    assert sh.do_help("nonexistent").startswith("No such command")
    assert sh.do_help("help")
Exemplo n.º 22
0
 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)