add log
command to bitbotctl
This commit is contained in:
parent
e31ad590cc
commit
c0c12d7394
1 changed files with 27 additions and 3 deletions
30
bitbotctl
30
bitbotctl
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import argparse, os
|
import argparse, os, sys
|
||||||
|
|
||||||
directory = os.path.dirname(os.path.realpath(__file__))
|
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",
|
help="Location of the sqlite3 database file",
|
||||||
default=os.path.join(directory, "databases", "bot.db"))
|
default=os.path.join(directory, "databases", "bot.db"))
|
||||||
|
|
||||||
|
arg_parser.add_argument("command")
|
||||||
|
|
||||||
args = arg_parser.parse_args()
|
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
|
import json, socket
|
||||||
|
|
||||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
sock.connect("%s.sock" % args.database)
|
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""
|
read_buffer = b""
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue