diff --git a/auxilary.py b/auxilary.py index 91962bb..a6f4e2c 100644 --- a/auxilary.py +++ b/auxilary.py @@ -50,12 +50,14 @@ class CountdownTimer(Thread): def __del__(self): self.stop() -def waitForPath(path, timeout=30): +def waitForPath(path, logger=None, timeout=30): for i in range(0, timeout): if os.path.exists(path): return time.sleep(1) - raise FileNotFoundError('Could not find {} after {} seconds'.format(path, timeout)) + if logger: + logger.error('Could not find %s after %s seconds', path, timeout) + raise SystemExit # we shouldn't need this if we are disabling the usb hub globally and nuking any past connections #~ def freeBusyPath(path, logger=None): diff --git a/listeners.py b/listeners.py index d431553..425a469 100644 --- a/listeners.py +++ b/listeners.py @@ -23,7 +23,7 @@ class KeypadListener(Thread): devPath = '/dev/input/by-id/usb-04d9_1203-event-kbd' - waitForPath(devPath) + waitForPath(devPath, logger) self._dev = InputDevice(devPath) self._dev.grab() @@ -109,7 +109,7 @@ class KeypadListener(Thread): self._dev.ungrab() logger.debug('Released keypad device') except IOError: - logger.debug('Failed to release keypad device') + logger.error('Failed to release keypad device') except AttributeError: pass diff --git a/sharedLogging.py b/sharedLogging.py index 2392cd6..d97edbd 100644 --- a/sharedLogging.py +++ b/sharedLogging.py @@ -2,6 +2,15 @@ import logging, os from subprocess import run, PIPE, CalledProcessError from logging.handlers import TimedRotatingFileHandler +""" +Logger conventions +- CRITICAL: for things that cause crashes. sends email +- ERROR: for things that cause startup/shutdown issues +- WARNING: for recoverable issues that may cause future problems +- INFO: state changes and sensor readings +- DEBUG: all extraneous crap +""" + # formats console output depending on whether we have gluster def _formatConsole(gluster = False): c = '' if gluster else '[CONSOLE ONLY] ' @@ -33,7 +42,7 @@ class GlusterFSHandler(TimedRotatingFileHandler): if not os.path.exists(logdest): os.mkdir(logdest) elif os.path.isfile(logdest): - logger.critical('%s is present but is a file (vs a directory). ' \ + logger.error('%s is present but is a file (vs a directory). ' \ 'Please (re)move this file to prevent data loss', logdest) raise SystemExit @@ -62,10 +71,8 @@ class GlusterFSHandler(TimedRotatingFileHandler): try: run(cmd, check=True, stdout=PIPE, stderr=PIPE) except CalledProcessError as e: - # we assume that this will only get thrown when the logger is not - # active, so use fallback to get the explicit mount errors stderr = e.stderr.decode('ascii').rstrip() - logger.critical(stderr) + logger.error(stderr) raise SystemExit def close(self): diff --git a/stateMachine.py b/stateMachine.py index 6978491..fb4727e 100644 --- a/stateMachine.py +++ b/stateMachine.py @@ -37,7 +37,7 @@ class State: self.sound = sound def entry(self): - logger.debug('entering ' + self.name) + logger.info('entering ' + self.name) if self.sound: self.sound.play() self.stateMachine.LED.blink = self.blinkLED @@ -46,7 +46,7 @@ class State: c() def exit(self): - logger.debug('exiting ' + self.name) + logger.info('exiting ' + self.name) if self.sound: self.sound.stop() for c in self.exitCallbacks: @@ -169,7 +169,7 @@ class StateMachine: secretTable[secret]() logger.debug('Secret pipe listener received: \"%s\"', secret) elif logger: - logger.error('Secret pipe listener received invalid secret') + logger.debug('Secret pipe listener received invalid secret') self.secretListener = PipeListener( callback = secretCallback, @@ -206,13 +206,13 @@ class StateMachine: def __del__(self): if hasattr(self, 'LED'): - self.LED.__del__() + self.LED.__del__() if hasattr(self, 'soundLib'): self.soundLib.__del__() - if hasattr(self, 'pipeListener'): - self.pipeListener.__del__() + if hasattr(self, 'secretListener'): + self.secretListener.__del__() if hasattr(self, 'keypadListener'): self.keypadListener.__del__() diff --git a/stream.py b/stream.py index 1f10d9e..2a6bac2 100644 --- a/stream.py +++ b/stream.py @@ -1,11 +1,13 @@ -# this entire module is lovingly based on the gst-launch tool kindly provided -# by the gstreamer wizards themselves...with unecessary crap cut out +""" +this entire module is lovingly based on the gst-launch tool kindly provided +by the gstreamer wizards themselves...with unecessary crap cut out -# we make the following assumptions here and optimize as such -# - all streams are "live" -# - will not need EOS (no mp4s) -# - will not require SIGINT (this entire program won't understand them anyways) -# - no tags or TOCs +we make the following assumptions here and optimize as such +- all streams are "live" +- will not need EOS (no mp4s) +- will not require SIGINT (this entire program won't understand them anyways) +- no tags or TOCs +""" from auxilary import async, waitForPath from threading import Thread diff --git a/webInterface.py b/webInterface.py index 0fddd6d..6ee387f 100644 --- a/webInterface.py +++ b/webInterface.py @@ -45,7 +45,7 @@ def initWebInterface(stateMachine): try: check_output(['pidof', 'janus']) except CalledProcessError: - logger.critical('Janus not running. Aborting') + logger.error('Janus not running. Aborting') raise SystemExit app = Flask(__name__)