delay loading config file
This commit is contained in:
parent
9532b1c003
commit
457e53109c
|
@ -31,8 +31,8 @@ def beautify_lisp_string(in_string):
|
|||
|
||||
|
||||
class OscCommentMacroListener(CommentMacroListener):
|
||||
def __init__(self, servers):
|
||||
self.osc = HogNet(servers)
|
||||
def __init__(self):
|
||||
self.osc = None
|
||||
|
||||
def exitWait(self, ctx: CommentMacroParser.WaitContext):
|
||||
logging.info("Waiting " + str(ctx.number().value) + " seconds.")
|
||||
|
|
|
@ -3,7 +3,7 @@ from pythonosc import osc_message_builder
|
|||
from time import sleep
|
||||
|
||||
|
||||
class HogNet():
|
||||
class HogNet:
|
||||
# button state constants
|
||||
buttonDOWN = 1
|
||||
buttonUP = 0
|
||||
|
|
|
@ -20,41 +20,35 @@ class SyntaxErrorListener(ErrorListener):
|
|||
raise SyntaxError("line "+str(line)+":"+str(column)+" "+msg)
|
||||
|
||||
|
||||
# empty server dictionary
|
||||
servers = {}
|
||||
def loadConfig(file='server.cfg'):
|
||||
# empty server dictionary
|
||||
servers = {}
|
||||
|
||||
# open config file
|
||||
config = configparser.ConfigParser(allow_no_value=True)
|
||||
config.read('server.cfg')
|
||||
# open config file
|
||||
config = configparser.ConfigParser(allow_no_value=True)
|
||||
config.read(file)
|
||||
|
||||
# set up each hog device
|
||||
for name in config.get('network', 'hogs').split(','):
|
||||
try:
|
||||
# move to config section
|
||||
server = config[name.strip().strip('\"')]
|
||||
# read settings
|
||||
ip = server.get("ip", "10.0.0.100")
|
||||
port = server.getint("port", 7001)
|
||||
net = server.getint("net", 1)
|
||||
# osc clients are added to the dictionary with the net # as the key
|
||||
logging.info("Adding Hog device at net# " + str(net))
|
||||
servers[net] = udp_client.SimpleUDPClient(ip, port)
|
||||
except KeyError as e:
|
||||
print('Error configuring net#', net, e)
|
||||
continue
|
||||
|
||||
|
||||
# clear temp variables off the stack
|
||||
try:
|
||||
del ip, port, net
|
||||
del server, config
|
||||
except NameError as e:
|
||||
print('failed to release memory', e)
|
||||
# set up each hog device
|
||||
for name in config.get('network', 'hogs').split(','):
|
||||
try:
|
||||
# move to config section
|
||||
server = config[name.strip().strip('\"')]
|
||||
# read settings
|
||||
ip = server.get("ip", "10.0.0.100")
|
||||
port = server.getint("port", 7001)
|
||||
net = server.getint("net", 1)
|
||||
# osc clients are added to the dictionary with the net # as the key
|
||||
logging.info("Adding Hog device at net# " + str(net))
|
||||
servers[net] = udp_client.SimpleUDPClient(ip, port)
|
||||
except KeyError as e:
|
||||
print('Error configuring net#', net, e)
|
||||
continue
|
||||
return servers
|
||||
|
||||
|
||||
# init reusable walker and listener
|
||||
walker = ParseTreeWalker()
|
||||
listener = OscCommentMacroListener(servers)
|
||||
listener = OscCommentMacroListener()
|
||||
|
||||
|
||||
# main handler for processing input
|
||||
|
@ -78,4 +72,4 @@ def comment(text):
|
|||
walker.walk(listener, tree)
|
||||
except SyntaxError as e:
|
||||
logging.debug(e) # antlr internal listener prints the error
|
||||
# # log it to the debug logging anyway
|
||||
# # log it to the debug logging anyway
|
||||
|
|
6
bs.py
6
bs.py
|
@ -6,13 +6,17 @@
|
|||
|
||||
import logging
|
||||
import sys
|
||||
from bacon.script import comment
|
||||
from bacon.script import comment, listener
|
||||
from bacon.script import loadConfig as loadBsConfig
|
||||
from bacon.hog4 import HogNet
|
||||
|
||||
|
||||
# setup logging
|
||||
logger = logging.getLogger()
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
listener.osc = HogNet(loadBsConfig('server.cfg'))
|
||||
|
||||
# handle user input if run directly
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) > 1:
|
||||
|
|
Loading…
Reference in New Issue