X-Git-Url: http://git.treefish.org/~alex/mtxbot.git/blobdiff_plain/b07be8cb62cc873d0c069c6410fdb0275620f66e..68e819a04d93ac687e72ec02cc24f8b78bebb055:/src/mtxbot.py?ds=inline diff --git a/src/mtxbot.py b/src/mtxbot.py index 0843f7d..722c8db 100755 --- a/src/mtxbot.py +++ b/src/mtxbot.py @@ -16,10 +16,10 @@ assert sys.version_info >= (3, 5) from presence import Presence def handleInterrupt(sig, frame): - global stopped + global stop if os.getpid() == mainPid: logging.info( "Got stop signal." ) - stopped = True + stop = True for presence in presences: presence.stop() @@ -52,7 +52,7 @@ logging.basicConfig(format='[%(asctime)s] %(levelname)s: %(message)s', mainPid = os.getpid() signal.signal(signal.SIGINT, handleInterrupt) -stopped = False +stop = False if len(sys.argv) != 2: print("Usage: %s " % sys.argv[0]) @@ -61,18 +61,20 @@ if len(sys.argv) != 2: with open(sys.argv[1]) as configFile: config = json.load(configFile) -while not stopped: +fifo_dir = os.getenv('MTXBOT_FIFO_DIR', '/run/mtxbot') + +while not stop: presences = [] - for entry in os.listdir(config['paths']['fifodir']): - if stat.S_ISFIFO(os.stat(entry).st_mode): + for entry in os.listdir(fifo_dir): + fullpath = "%s/%s" % (fifo_dir, entry) + if stat.S_ISFIFO(os.stat(fullpath).st_mode): logging.info("Creating presence for %s..." % entry) - presences.append( Presence( entry, "%s/%s" % - (config['paths']['fifodir'], entry) ) ) + presences.append( Presence(entry, fullpath) ) if len(presences) == 0: logging.error("No fifos could be found!") break asyncio.run(main()) - if not stopped: + if not stop: logging.warning("Main loop exited!") logging.info("Restarting after grace period...") time.sleep(3.0)