New argument: --socketfile that create a socket for internal communication

This commit is contained in:
nemunaire 2015-05-20 06:12:50 +02:00
parent 0b14207c88
commit c0fed51fde
2 changed files with 11 additions and 2 deletions

View File

@ -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

View File

@ -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: