From 9dc385a32aa3a47fecf97eef3935868a102769dc Mon Sep 17 00:00:00 2001 From: nemunaire Date: Wed, 20 May 2015 06:12:50 +0200 Subject: [PATCH] New argument: --socketfile that create a socket for internal communication --- nemubot/__init__.py | 4 ++-- nemubot/__main__.py | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/nemubot/__init__.py b/nemubot/__init__.py index 668dd6c..7b3d21f 100644 --- a/nemubot/__init__.py +++ b/nemubot/__init__.py @@ -38,8 +38,8 @@ def requires_version(min=None, max=None): "but this is nemubot v%s." % (str(max), __version__)) -def attach(pid): - print("TODO, attach to %d" % pid) +def attach(socketfile): + print("TODO: Attach to Unix socket at: %s" % socketfile) return 0 diff --git a/nemubot/__main__.py b/nemubot/__main__.py index 7db715b..456dc3a 100644 --- a/nemubot/__main__.py +++ b/nemubot/__main__.py @@ -43,6 +43,9 @@ def main(): parser.add_argument("-P", "--pidfile", default="./nemubot.pid", help="Path to the file where store PID") + parser.add_argument("-S", "--socketfile", default="./nemubot.sock", + help="path where open the socket for internal communication") + parser.add_argument("-l", "--logfile", default="./nemubot.log", help="Path to store logs") @@ -66,6 +69,7 @@ def main(): # Resolve relatives paths args.data_path = os.path.abspath(os.path.expanduser(args.data_path)) args.pidfile = os.path.abspath(os.path.expanduser(args.pidfile)) + args.socketfile = os.path.abspath(os.path.expanduser(args.socketfile)) args.logfile = os.path.abspath(os.path.expanduser(args.logfile)) args.files = [ x for x in map(os.path.abspath, args.files)] args.modules_path = [ x for x in map(os.path.abspath, args.modules_path)] @@ -185,6 +189,11 @@ def main(): # Here we go! context.start() + if args.socketfile: + from nemubot.server.socket import SocketListener + context.add_server(SocketListener(context.add_server, "master_socket", + sock_location=args.socketfile)) + # context can change when performing an hotswap, always join the latest context oldcontext = None while oldcontext != context: