cleanup logging
This commit is contained in:
parent
d414c8424c
commit
56ea58d7f8
|
@ -8,8 +8,6 @@ from time import sleep
|
|||
from .commentmacro.CommentMacroParser import CommentMacroParser
|
||||
from .commentmacro.CommentMacroListener import CommentMacroListener
|
||||
|
||||
logger = logging.getLogger('__main__')
|
||||
|
||||
|
||||
# https://raw.githubusercontent.com/jszheng/py3antlr4book/master/bin/pygrun
|
||||
# this is a python version of TestRig
|
||||
|
@ -57,19 +55,19 @@ class HogDevice():
|
|||
osc = list(self.servers.values())[0] # first configured server
|
||||
else:
|
||||
if (device.nodeType().getText().lower() != 'h'):
|
||||
logger.error("ERROR: Only Hog type devices are supported.")
|
||||
logging.error("ERROR: Only Hog type devices are supported.")
|
||||
return
|
||||
else:
|
||||
try:
|
||||
osc = self.servers[device.number().value]
|
||||
except KeyError:
|
||||
logger.error("ERROR: Net# " + str(device.number().value) +
|
||||
" not found.")
|
||||
logging.error("ERROR: Net# " + str(device.number().value) +
|
||||
" not found.")
|
||||
return
|
||||
try:
|
||||
osc.send(msg)
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
logging.error(e)
|
||||
|
||||
|
||||
class OscCommentMacroListener(CommentMacroListener):
|
||||
|
@ -77,13 +75,13 @@ class OscCommentMacroListener(CommentMacroListener):
|
|||
self.osc = HogDevice(servers)
|
||||
|
||||
def exitWait(self, ctx: CommentMacroParser.WaitContext):
|
||||
logger.info("Waiting " + str(ctx.number().value) + " seconds.")
|
||||
logging.info("Waiting " + str(ctx.number().value) + " seconds.")
|
||||
sleep(ctx.number().value)
|
||||
|
||||
def enterStatement(self, ctx: CommentMacroParser.StatementContext):
|
||||
# print the lisp tree of this macro
|
||||
lisp_tree_str = ctx.toStringTree(recog=ctx.parser)
|
||||
logger.debug(beautify_lisp_string(lisp_tree_str))
|
||||
logging.debug(beautify_lisp_string(lisp_tree_str))
|
||||
|
||||
def enterTarget(self, ctx: CommentMacroParser.TargetContext):
|
||||
ctx.targets = []
|
||||
|
@ -110,70 +108,70 @@ class OscCommentMacroListener(CommentMacroListener):
|
|||
|
||||
def exitMasterGo(self, ctx: CommentMacroParser.MasterGoContext):
|
||||
if ctx.target() is None:
|
||||
logger.info("Main GO")
|
||||
logging.info("Main GO")
|
||||
self.osc.button_press(ctx.device(), "/hog/hardware/maingo")
|
||||
return
|
||||
for i in ctx.target().targets:
|
||||
if isinstance(i, int) is not True:
|
||||
logger.warn("GO MASTER macro targets must be intigers. "
|
||||
+ str(i) + " is not an intigers.")
|
||||
logging.warn("GO MASTER macro targets must be intigers. "
|
||||
+ str(i) + " is not an intigers.")
|
||||
continue
|
||||
if (i < 0):
|
||||
logger.warn("Master "+str(i)+" is not greater than 0.")
|
||||
logging.warn("Master "+str(i)+" is not greater than 0.")
|
||||
continue
|
||||
master = str(i)
|
||||
logger.info("GO on master " + master)
|
||||
logging.info("GO on master " + master)
|
||||
self.osc.button_press(ctx.device(), "/hog/hardware/go/" + master)
|
||||
|
||||
def exitMasterHalt(self, ctx: CommentMacroParser.MasterHaltContext):
|
||||
if ctx.target() is None:
|
||||
logger.info("Main HALT")
|
||||
logging.info("Main HALT")
|
||||
self.osc.button_press(ctx.device(), "/hog/hardware/mainhalt")
|
||||
return
|
||||
for i in ctx.target().targets:
|
||||
if isinstance(i, int) is not True:
|
||||
logger.warn("GO MASTER macro targets must be intigers. "
|
||||
+ str(i) + " is not an intigers.")
|
||||
logging.warn("GO MASTER macro targets must be intigers. "
|
||||
+ str(i) + " is not an intigers.")
|
||||
continue
|
||||
if (i < 0):
|
||||
logger.warn("Master "+str(i)+" is not greater than 0.")
|
||||
logging.warn("Master "+str(i)+" is not greater than 0.")
|
||||
continue
|
||||
master = str(i)
|
||||
logger.info("HALT on master " + master)
|
||||
logging.info("HALT on master " + master)
|
||||
self.osc.button_press(ctx.device(), "/hog/hardware/pause/"+master)
|
||||
|
||||
def exitMasterAssert(self, ctx: CommentMacroParser.MasterAssertContext):
|
||||
if ctx.target()is not None:
|
||||
logger.error("ERROR: limited to asserting current master only.")
|
||||
logging.error("ERROR: limited to asserting current master only.")
|
||||
return
|
||||
logger.info("ASSERT on current master.")
|
||||
logging.info("ASSERT on current master.")
|
||||
self.osc.button_press(ctx.device(), "/hog/hardware/assert")
|
||||
|
||||
def exitMasterRelease(self, ctx: CommentMacroParser.MasterReleaseContext):
|
||||
if ctx.target() is not None:
|
||||
logger.error("ERROR: limited to releasing current master only.")
|
||||
logging.error("ERROR: limited to releasing current master only.")
|
||||
return
|
||||
logger.info("RELEASE on current master.")
|
||||
logging.info("RELEASE on current master.")
|
||||
self.osc.button_press(ctx.device(), "/hog/hardware/release")
|
||||
|
||||
def exitMasterFade(self, ctx: CommentMacroParser.MasterFadeContext):
|
||||
if ctx.target()is None:
|
||||
logger.error("ERROR: limited to fading specified masters only.")
|
||||
logging.error("ERROR: limited to fading specified masters only.")
|
||||
return
|
||||
level = ctx.number().value
|
||||
if (level < 0 or level > 100):
|
||||
logger.error("Level must be between 0 and 100.")
|
||||
logging.error("Level must be between 0 and 100.")
|
||||
return
|
||||
for i in ctx.target().targets:
|
||||
if isinstance(i, int) is not True:
|
||||
logger.warn("FADE MASTER macro targets must be intigers. "
|
||||
+ str(i) + " is not an intigers.")
|
||||
logging.warn("FADE MASTER macro targets must be intigers. "
|
||||
+ str(i) + " is not an intigers.")
|
||||
continue
|
||||
if (i < 0):
|
||||
logger.warn("Master "+str(i)+" is not greater than 0.")
|
||||
logging.warn("Master "+str(i)+" is not greater than 0.")
|
||||
continue
|
||||
master = str(i)
|
||||
logger.info("Fade Master "+master+" to "+str(level)+"%")
|
||||
logging.info("Fade Master "+master+" to "+str(level)+"%")
|
||||
level *= 255 / 100 # percent in Macro, 0>255 in OSC
|
||||
self.osc.send_message(ctx.device(),
|
||||
"/hog/hardware/fader/" + master,
|
||||
|
@ -183,22 +181,22 @@ class OscCommentMacroListener(CommentMacroListener):
|
|||
ctx: CommentMacroParser.FadeGrandMasterContext):
|
||||
level = ctx.number().value
|
||||
if (level < 0 or level > 100):
|
||||
logger.error("Level must be between 0 and 100.")
|
||||
logging.error("Level must be between 0 and 100.")
|
||||
return
|
||||
logger.info("Fading Grand Master to " + str(level) + "%")
|
||||
logging.info("Fading Grand Master to " + str(level) + "%")
|
||||
level *= 255 / 100 # percent in Macro, 0>255 in OSC
|
||||
self.osc.send_message(ctx.device(), "/hog/hardware/fader/0", level)
|
||||
|
||||
def exitMasterChoose(self, ctx: CommentMacroParser.MasterChooseContext):
|
||||
if (ctx.number().value < 0):
|
||||
logger.error("Master must be greater than 0.")
|
||||
logging.error("Master must be greater than 0.")
|
||||
return
|
||||
master = str(ctx.number().value)
|
||||
logger.info("Choose Master " + master)
|
||||
logging.info("Choose Master " + master)
|
||||
self.osc.button_press(ctx.device(), "/hog/hardware/choose/" + master)
|
||||
|
||||
def exitReleaseAll(self, ctx: CommentMacroParser.ReleaseAllContext):
|
||||
logger.info("Release All")
|
||||
logging.info("Release All")
|
||||
self.osc.send_message(ctx.device(), "/hog/hardware/pig",
|
||||
self.osc.buttonDOWN)
|
||||
self.osc.button_press(ctx.device(), "/hog/hardware/release")
|
||||
|
@ -207,59 +205,59 @@ class OscCommentMacroListener(CommentMacroListener):
|
|||
|
||||
def exitListGo(self, ctx: CommentMacroParser.ListGoContext):
|
||||
for i in ctx.target().targets:
|
||||
logger.info("Go on List " + str(i))
|
||||
logging.info("Go on List " + str(i))
|
||||
self.osc.send_message(ctx.device(), "/hog/playback/go/0", i)
|
||||
|
||||
def exitListGoto(self, ctx: CommentMacroParser.ListGotoContext):
|
||||
for i in ctx.target().targets:
|
||||
list = str(i) + "." + str(ctx.number().value)
|
||||
logger.info("Go on List " + str(list))
|
||||
logging.info("Go on List " + str(list))
|
||||
self.osc.send_message(ctx.device(), "/hog/playback/go/0", list)
|
||||
|
||||
def exitListHalt(self, ctx: CommentMacroParser.ListHaltContext):
|
||||
for i in ctx.target().targets:
|
||||
logger.info("Halting List " + str(i))
|
||||
logging.info("Halting List " + str(i))
|
||||
self.osc.send_message(ctx.device(), "/hog/playback/halt/0", i)
|
||||
|
||||
def exitListRelese(self, ctx: CommentMacroParser.ListReleseContext):
|
||||
for i in ctx.target().targets:
|
||||
logger.info("Releasing List " + str(i))
|
||||
logging.info("Releasing List " + str(i))
|
||||
self.osc.send_message(ctx.device(), "/hog/playback/release/0", i)
|
||||
|
||||
def exitSceneGo(self, ctx: CommentMacroParser.SceneGoContext):
|
||||
for i in ctx.target().targets:
|
||||
logger.info("Go on Scene " + str(i))
|
||||
logging.info("Go on Scene " + str(i))
|
||||
self.osc.send_message(ctx.device(), "/hog/playback/go/1", i)
|
||||
|
||||
def exitSceneHalt(self, ctx: CommentMacroParser.SceneHaltContext):
|
||||
for i in ctx.target().targets:
|
||||
logger.info("Halt Scene " + str(i))
|
||||
logging.info("Halt Scene " + str(i))
|
||||
self.osc.send_message(ctx.device(), "/hog/playback/halt/1", i)
|
||||
|
||||
def exitSceneRelease(self, ctx: CommentMacroParser.SceneReleaseContext):
|
||||
for i in ctx.target().targets:
|
||||
logger.info("Release Scene " + str(i))
|
||||
logging.info("Release Scene " + str(i))
|
||||
self.osc.send_message(ctx.device(), "/hog/playback/release/1", i)
|
||||
|
||||
def exitMacroGo(self, ctx: CommentMacroParser.MacroGoContext):
|
||||
for i in ctx.target().targets:
|
||||
logger.info("Go on Macro " + str(i))
|
||||
logging.info("Go on Macro " + str(i))
|
||||
self.osc.send_message(ctx.device(), "/hog/playback/go/2", i)
|
||||
|
||||
def exitMacroHalt(self, ctx: CommentMacroParser.MacroHaltContext):
|
||||
for i in ctx.target().targets:
|
||||
logger.info("Pause Macro " + str(i))
|
||||
logging.info("Pause Macro " + str(i))
|
||||
self.osc.send_message(ctx.device(), "/hog/playback/halt/2", i)
|
||||
|
||||
def exitMacroStop(self, ctx: CommentMacroParser.MacroStopContext):
|
||||
for i in ctx.target().targets:
|
||||
logger.info("Stop Macro " + str(i))
|
||||
logging.info("Stop Macro " + str(i))
|
||||
self.osc.send_message(ctx.device(), "/hog/playback/release/2", i)
|
||||
|
||||
def exitPageNext(self, ctx: CommentMacroParser.PageNextContext):
|
||||
logger.info("Next Page")
|
||||
logging.info("Next Page")
|
||||
self.osc.button_press(ctx.device(), "/hog/hardware/nextpage")
|
||||
|
||||
def exitPagePrev(self, ctx: CommentMacroParser.PagePrevContext):
|
||||
logger.info("Prev Page")
|
||||
logging.info("Prev Page")
|
||||
self.osc.button_press(ctx.device(), "/hog/hardware/backpage")
|
||||
|
|
|
@ -20,13 +20,6 @@ class SyntaxErrorListener(ErrorListener):
|
|||
raise SyntaxError("line "+str(line)+":"+str(column)+" "+msg)
|
||||
|
||||
|
||||
# setup logging
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.setLevel(logging.DEBUG)
|
||||
ch = logging.StreamHandler() # create console handler and
|
||||
ch.setLevel(logging.INFO) # set console log level to INFO
|
||||
logger.addHandler(ch) # add console log handler
|
||||
|
||||
# empty server dictionary
|
||||
servers = {}
|
||||
|
||||
|
@ -44,7 +37,7 @@ for name in config.get('network', 'hogs').split(','):
|
|||
port = server.getint("port", 7001)
|
||||
net = server.getint("net", 1)
|
||||
# osc clients are added to the dictionary with the net # as the key
|
||||
logger.info("Adding Hog device at net# " + str(net))
|
||||
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)
|
||||
|
@ -84,5 +77,5 @@ def comment(text):
|
|||
# walk the tree
|
||||
walker.walk(listener, tree)
|
||||
except SyntaxError as e:
|
||||
logger.debug(e) # antlr internal listener prints the error
|
||||
# # log it to the debug logger anyway
|
||||
logging.debug(e) # antlr internal listener prints the error
|
||||
# # log it to the debug logging anyway
|
||||
|
|
8
bs.py
8
bs.py
|
@ -4,14 +4,20 @@
|
|||
"""Interactive BaconScript shell.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import sys
|
||||
from bacon.script import comment
|
||||
|
||||
|
||||
# setup logging
|
||||
logger = logging.getLogger()
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
# handle user input if run directly
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) > 1:
|
||||
# look for macros passed as arguments
|
||||
logger.debug("found macro at argv[1]")
|
||||
logging.debug("found macro at argv[1]")
|
||||
comment(sys.argv[1])
|
||||
else:
|
||||
# for input history and line editing
|
||||
|
|
Loading…
Reference in New Issue