From efb48078c72c557a4e5a52a651c5c24fad09d837 Mon Sep 17 00:00:00 2001 From: Leonardo Barcaroli Date: Mon, 18 Feb 2019 12:20:55 +0100 Subject: [PATCH] Added checkin/out subcommands to cli. --- bot_z/cli.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ bot_z/zdaemon.py | 26 ++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/bot_z/cli.py b/bot_z/cli.py index 0ce1581..7aef71c 100644 --- a/bot_z/cli.py +++ b/bot_z/cli.py @@ -310,6 +310,50 @@ def logout_command(ctx: click.Context, name: T.Optional[str], force: bool) -> No logger.info("Logout sent.") +@cli.command("checkin") +@click.option("-n", "--name", default=None, help="The instance to interact with.") +@click.option( + "-f", + "--force", + is_flag=True, + default=False, + help="Force logout, bypass login check.", +) +@click.pass_context +def checkin_command(ctx: click.Context, name: T.Optional[str], force: bool) -> None: + """ + Checks in on a logged in client. + """ + logger.debug("Sending the check in command down the pipe: %s", ctx.obj["fifo"]) + name = _check_name(ctx.obj["lifo"], name) + logging.info("Checking in on instance: %s", name) + with open(ctx.obj["fifo"], "w") as fifo: + fifo.write(cmd_marshal(name=name, cmd="checkin", force=force)) + logger.info("Check in sent.") + + +@cli.command("checkout") +@click.option("-n", "--name", default=None, help="The instance to interact with.") +@click.option( + "-f", + "--force", + is_flag=True, + default=False, + help="Force logout, bypass login check.", +) +@click.pass_context +def checkout_command(ctx: click.Context, name: T.Optional[str], force: bool) -> None: + """ + Checks out on a logged in client and checked in client. + """ + logger.debug("Sending the check out command down the pipe: %s", ctx.obj["fifo"]) + name = _check_name(ctx.obj["lifo"], name) + logging.info("Checking out on instance: %s", name) + with open(ctx.obj["fifo"], "w") as fifo: + fifo.write(cmd_marshal(name=name, cmd="checkout", force=force)) + logger.info("Check out sent.") + + @cli.command("reload") @click.option("-n", "--name", default=None, help="The instance to interact with.") @click.pass_context diff --git a/bot_z/zdaemon.py b/bot_z/zdaemon.py index ea30edc..d86ada2 100644 --- a/bot_z/zdaemon.py +++ b/bot_z/zdaemon.py @@ -126,6 +126,24 @@ def operator_logout(op: Operator, force: bool) -> None: logger.info("Logout done.") +def operator_checkin(op: Operator, force: bool) -> None: + """ + Instructs the operator to perform the check in. + """ + logger.debug("Performing check in...") + op.checkin() + logger.info("Check in done.") + + +def operator_checkout(op: Operator, force: bool) -> None: + """ + Instructs the operator to perform the check out. + """ + logger.debug("Performing check out...") + op.checkout() + logger.info("Check out done.") + + def daemon_process( fifo_path: str, working_dir: str, @@ -184,6 +202,8 @@ def daemon_process( "status": operator_status, "login": operator_login, "logout": operator_logout, + "checkin": operator_checkin, + "checkout": operator_checkout, } logger.debug("command map defined") @@ -240,6 +260,12 @@ def listen_client( elif cmd["cmd"] == "logout": logger.debug("Received command: logout") cmd_map["logout"](op, cmd["force"]) + elif cmd["cmd"] == "checkin": + logger.debug("Received command: checkin") + cmd_map["checkin"](op, cmd["force"]) + elif cmd["cmd"] == "checkout": + logger.debug("Received command: checkout") + cmd_map["checkout"](op, cmd["force"]) def listen_commands(