def test_stbt_control_relay(stbt_control_relay_on_path):  # pylint: disable=unused-argument
    with named_temporary_directory("stbt-control-relay-test.XXXXXX") as tmpdir:
        def t(filename):
            return os.path.join(tmpdir, filename)
        proc = subprocess.Popen(
            ["stbt-control-relay",
             "--input=lircd:" + t("lircd.sock"),
             "file:" + t("one-file"), "file:" + t("another")])
        with scoped_process(proc):
            wait_until(lambda: (
                os.path.exists(t("lircd.sock")) or proc.poll() is not None))
            testremote = uri_to_remote("lirc:%s:stbt" % t("lircd.sock"))

            testremote.press("KEY_UP")
            testremote.press("KEY_DOWN")
            expected = "KEY_UP\nKEY_DOWN\n"

            def filecontains(filename, text):
                try:
                    with open(t(filename)) as f:
                        return text == f.read()
                except OSError:
                    return None

            wait_until(lambda: (
                filecontains("one-file", expected) and
                filecontains("another", expected)))
            assert open(t("one-file")).read() == expected
            assert open(t("another")).read() == expected
Ejemplo n.º 2
0
def main(argv):
    parser = argparse.ArgumentParser(
        epilog=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument("--socket",
                        default="/var/run/lirc/lircd",
                        help="""LIRC socket to read
        remote control presses from (defaults to %(default)s).""")
    parser.add_argument("output",
                        help="""Remote control configuration to
        transmit on. Values are the same as stbt run's --control.""")
    _stbt.logging.argparser_add_verbose_argument(parser)
    args = parser.parse_args(argv[1:])

    signal.signal(signal.SIGTERM, lambda _signo, _stack_frame: sys.exit(0))

    if os.environ.get('LISTEN_FDS') == '1' and \
            os.environ.get('LISTEN_PID') == str(os.getpid()):
        s = socket.fromfd(3, socket.AF_UNIX, socket.SOCK_STREAM)
    else:
        s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        s.bind(args.socket)
        s.listen(5)

    control = uri_to_remote(args.output)

    while True:
        conn, _ = s.accept()
        f = conn.makefile('r', 0)
        while True:
            cmd = f.readline()
            if not cmd:
                break
            cmd = cmd.rstrip("\n")
            m = re.match(r"SEND_ONCE (?P<ctrl>\w+) (?P<key>\w+)", cmd)
            if not m:
                debug("Ignoring invalid command: %s" % cmd)
                continue
            key = m.groupdict()["key"]
            debug("Received %s" % key)
            try:
                control.press(key)
            except Exception as e:  # pylint: disable=broad-except
                debug("Error pressing key %r: %r" % (key, e))
                send_response(conn, cmd, success=False, data=str(e))
                continue
            send_response(conn, cmd, success=True)
def test_stbt_control_relay_with_socket_passing(stbt_control_relay_on_path):  # pylint: disable=unused-argument
    with NamedTemporaryFile(prefix="stbt-control-relay-test-") as tmpfile:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.bind(('127.0.0.1', 0))
        s.listen(5)

        proc = subprocess.Popen(
            ["stbt-control-relay", "-vv", "file:" + tmpfile.name],
            preexec_fn=socket_passing_setup(s))
        with scoped_process(proc):
            testremote = uri_to_remote("lirc:%s:%i:stbt" % s.getsockname())

            testremote.press("KEY_UP")
            testremote.press("KEY_DOWN")
            expected = "KEY_UP\nKEY_DOWN\n"

            assert tmpfile.read() == expected
Ejemplo n.º 4
0
def test_stbt_control_relay_with_socket_passing(stbt_control_relay_on_path):  # pylint: disable=unused-argument
    with NamedTemporaryFile(prefix="stbt-control-relay-test-") as tmpfile:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.bind(('127.0.0.1', 0))
        s.listen(5)

        proc = subprocess.Popen(
            ["stbt-control-relay", "-vv", "file:" + tmpfile.name],
            preexec_fn=socket_passing_setup(s))
        with scoped_process(proc):
            testremote = uri_to_remote("lirc:%s:%i:stbt" % s.getsockname())

            testremote.press("KEY_UP")
            testremote.press("KEY_DOWN")
            expected = "KEY_UP\nKEY_DOWN\n"

            assert tmpfile.read() == expected
def test_stbt_control_relay(stbt_control_relay_on_path):  # pylint: disable=unused-argument
    with named_temporary_directory("stbt-control-relay-test.XXXXXX") as tmpdir:
        def t(filename):
            return os.path.join(tmpdir, filename)
        proc = subprocess.Popen(
            ["stbt-control-relay",
             "--socket", t("lircd.sock"),
             "file:" + t("one-file")])
        with scoped_process(proc):
            wait_until(lambda: (
                os.path.exists(t("lircd.sock")) or proc.poll() is not None))
            testremote = uri_to_remote("lirc:%s:stbt" % t("lircd.sock"))

            testremote.press("KEY_UP")
            testremote.press("KEY_DOWN")
            expected = "KEY_UP\nKEY_DOWN\n"

            assert open(t("one-file")).read() == expected
Ejemplo n.º 6
0
def main(argv):
    parser = argparse.ArgumentParser(
        epilog=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument(
        "--input", default="lircd", help="""The source of remote control
        presses. Values are the same as stbt record's --control-recorder.""")
    parser.add_argument("output", nargs="+", help="""One or more remote control
        configurations. Values are the same as stbt run's --control.""")
    argparser_add_verbose_argument(parser)
    args = parser.parse_args(argv[1:])

    signal.signal(signal.SIGTERM, lambda _signo, _stack_frame: sys.exit(0))

    r = MultiRemote(uri_to_remote(x) for x in args.output)
    listener = uri_to_remote_recorder(args.input)
    for key in listener:
        debug("Received %s" % key)
        try:
            r.press(key)
        except Exception as e:  # pylint: disable=broad-except
            sys.stderr.write("Error pressing key %r: %s\n" % (key, e))
Ejemplo n.º 7
0
def main(argv):
    parser = argparse.ArgumentParser(
        epilog=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument(
        "--socket", default="/var/run/lirc/lircd", help="""LIRC socket to read
        remote control presses from (defaults to %(default)s).""")
    parser.add_argument("output", help="""Remote control configuration to
        transmit on. Values are the same as stbt run's --control.""")
    _stbt.logging.argparser_add_verbose_argument(parser)
    args = parser.parse_args(argv[1:])

    signal.signal(signal.SIGTERM, lambda _signo, _stack_frame: sys.exit(0))

    s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    s.bind(args.socket)
    s.listen(5)

    control = uri_to_remote(args.output)

    while True:
        conn, _ = s.accept()
        for cmd in conn.makefile():
            cmd = cmd.rstrip("\n")
            m = re.match(r"SEND_ONCE (?P<ctrl>\w+) (?P<key>\w+)", cmd)
            if not m:
                debug("Ignoring invalid command: %s" % cmd)
                continue
            key = m.groupdict()["key"]
            debug("Received %s" % key)
            try:
                control.press(key)
            except Exception as e:  # pylint: disable=broad-except
                debug("Error pressing key %r: %r" % (key, e))
                send_response(conn, cmd, success=False, data=str(e))
                continue
            send_response(conn, cmd, success=True)
Ejemplo n.º 8
0
def main(argv):
    parser = argparse.ArgumentParser(
        epilog=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument("--input",
                        default="lircd",
                        help="""The source of remote control
        presses. Values are the same as stbt record's --control-recorder.""")
    parser.add_argument("output",
                        nargs="+",
                        help="""One or more remote control
        configurations. Values are the same as stbt run's --control.""")
    argparser_add_verbose_argument(parser)
    args = parser.parse_args(argv[1:])

    signal.signal(signal.SIGTERM, lambda _signo, _stack_frame: sys.exit(0))

    r = MultiRemote(uri_to_remote(x) for x in args.output)
    listener = uri_to_remote_recorder(args.input)
    for key in listener:
        debug("Received %s" % key)
        try:
            r.press(key)
        except Exception as e:  # pylint: disable=broad-except
            sys.stderr.write("Error pressing key %r: %s\n" % (key, e))