diff options
| author | 2019-10-11 15:31:22 +0100 | |
|---|---|---|
| committer | 2019-10-11 15:31:22 +0100 | |
| commit | c0c12d7394bf6bcbe35bbf7a91d9a8279bb833e5 (patch) | |
| tree | b0674d9abc6a84a78f118781c3a8a46bcf5585df | |
| parent | first version of bitbotctl - shows INFO logging (diff) | |
| signature | ||
add `log` command to bitbotctl
| -rwxr-xr-x | bitbotctl | 30 |
1 files changed, 27 insertions, 3 deletions
@@ -1,5 +1,5 @@ #!/usr/bin/env python3 -import argparse, os +import argparse, os, sys directory = os.path.dirname(os.path.realpath(__file__)) @@ -10,14 +10,38 @@ arg_parser.add_argument("--database", "-d", help="Location of the sqlite3 database file", default=os.path.join(directory, "databases", "bot.db")) +arg_parser.add_argument("command") + +args = arg_parser.parse_args() + +def _die(s): + sys.stderr.write("%s\n" % s) + sys.exit(1) + +if args.command == "log": + arg_parser.add_argument("--level", "-l", help="Log level", + default="INFO") +else: + _die("Unknown command '%s'" % args.command) + args = arg_parser.parse_args() +sock_location = "%s.sock" % args.database +if not os.path.exists(sock_location): + _die("Failed to connect to BitBot instance") + import json, socket sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.connect("%s.sock" % args.database) -sock.send(b"0 version 0\n") -sock.send(b"1 log info\n") + +def _send(s): + sock.send(("%s\n" % s).encode("utf8")) + +_send("0 version 0") + +if args.command == "log": + _send("1 log %s" % args.level) read_buffer = b"" |
