mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-12-23 04:51:55 +00:00
Standardize log constant naming and declaration placement
This commit is contained in:
parent
1e2ea0ed17
commit
aacdbcb0d1
@ -7,7 +7,8 @@ from tfw.networking.event_handlers.server_connector import ServerUplinkConnector
|
||||
from tfw.components.decorators import RateLimiter
|
||||
|
||||
from tfw.config.logs import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class DirectoryMonitor:
|
||||
@ -64,7 +65,7 @@ class WebideReloadWatchdogEventHandler(FileSystemWatchdogEventHandler):
|
||||
if self.ignore > 0:
|
||||
self.ignore = self.ignore - 1
|
||||
return
|
||||
log.debug(event)
|
||||
LOG.debug(event)
|
||||
key = 'webide'
|
||||
self.uplink.send(key, {'data': {'command': 'reload'}})
|
||||
|
||||
|
@ -3,7 +3,8 @@ from os.path import isdir, exists
|
||||
from tfw.components.directory_monitor import DirectoryMonitor
|
||||
from tfw.event_handler_base import TriggerlessEventHandler
|
||||
from tfw.config.logs import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class DirectoryMonitoringEventHandler(TriggerlessEventHandler):
|
||||
@ -42,7 +43,7 @@ class DirectoryMonitoringEventHandler(TriggerlessEventHandler):
|
||||
message['data'] = self.commands[message['data']['command']](message['data'])
|
||||
return message
|
||||
except KeyError:
|
||||
log.error('IGNORING MESSAGE: Invalid message received: {}'.format(message))
|
||||
LOG.error('IGNORING MESSAGE: Invalid message received: {}'.format(message))
|
||||
|
||||
def pause(self, data):
|
||||
self.monitor.pause()
|
||||
@ -62,7 +63,7 @@ class DirectoryMonitoringEventHandler(TriggerlessEventHandler):
|
||||
self.reload_monitor()
|
||||
return data
|
||||
except EnvironmentError:
|
||||
log.error('Failed to switch directory!')
|
||||
LOG.error('Failed to switch directory!')
|
||||
|
||||
def cleanup(self):
|
||||
self.monitor.stop()
|
||||
|
@ -4,7 +4,8 @@ from tfw.event_handler_base import TriggerlessEventHandler
|
||||
from tfw.components.mixins import SupervisorMixin
|
||||
from tfw.components.directory_monitor import with_monitor_paused
|
||||
from tfw.config.logs import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ProcessManager(SupervisorMixin):
|
||||
@ -32,7 +33,7 @@ class ProcessManagingEventHandler(TriggerlessEventHandler):
|
||||
self.processmanager(data['command'], data['process_name'])
|
||||
return message
|
||||
except KeyError:
|
||||
log.error('IGNORING MESSAGE: Invalid message received: {}'.format(message))
|
||||
LOG.error('IGNORING MESSAGE: Invalid message received: {}'.format(message))
|
||||
except SupervisorFault as fault:
|
||||
message['data']['error'] = fault.faultString
|
||||
message['data']['log'] = self.processmanager.read_log(message['data']['process_name'])
|
||||
|
@ -6,7 +6,8 @@ from collections import Iterable
|
||||
from tfw.event_handler_base import TriggerlessEventHandler
|
||||
from tfw.components.directory_monitor import DirectoryMonitor
|
||||
from tfw.config.logs import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class FileManager:
|
||||
@ -103,13 +104,13 @@ class SourceCodeEventHandler(TriggerlessEventHandler):
|
||||
def write(self, data):
|
||||
self.monitor.ignore = self.monitor.ignore + 1
|
||||
try: self.filemanager.file_contents = data['content']
|
||||
except Exception: log.exception('Error writing file!')
|
||||
except Exception: LOG.exception('Error writing file!')
|
||||
del data['content']
|
||||
return data
|
||||
|
||||
def select(self, data):
|
||||
try: self.filemanager.filename = data['filename']
|
||||
except EnvironmentError: log.exception('Failed to select file "{}"'.format(data['filename']))
|
||||
except EnvironmentError: LOG.exception('Failed to select file "{}"'.format(data['filename']))
|
||||
return data
|
||||
|
||||
def select_dir(self, data):
|
||||
@ -122,12 +123,12 @@ class SourceCodeEventHandler(TriggerlessEventHandler):
|
||||
except IndexError:
|
||||
data['content'] = 'No files in this directory :('
|
||||
except EnvironmentError:
|
||||
log.error('Failed to select directory "{}"'.format(data['directory']))
|
||||
LOG.error('Failed to select directory "{}"'.format(data['directory']))
|
||||
return data
|
||||
|
||||
def exclude(self, data):
|
||||
try: self.filemanager.exclude = list(data['exclude'])
|
||||
except TypeError: log.error('Exclude must be Iterable!')
|
||||
except TypeError: LOG.error('Exclude must be Iterable!')
|
||||
return data
|
||||
|
||||
def attach_fileinfo(self, data):
|
||||
@ -142,7 +143,7 @@ class SourceCodeEventHandler(TriggerlessEventHandler):
|
||||
self.attach_fileinfo(data)
|
||||
return message
|
||||
except KeyError:
|
||||
log.error('IGNORING MESSAGE: Invalid message received: {}'.format(message))
|
||||
LOG.error('IGNORING MESSAGE: Invalid message received: {}'.format(message))
|
||||
|
||||
def cleanup(self):
|
||||
self.monitor.stop()
|
||||
|
@ -3,7 +3,8 @@ from tfw.components.history_monitor import HistoryMonitor
|
||||
from tfw.event_handler_base import TriggerlessEventHandler
|
||||
from tfw.config import tfwenv
|
||||
from tfw.config.logs import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TerminadoEventHandler(TriggerlessEventHandler):
|
||||
@ -22,12 +23,12 @@ class TerminadoEventHandler(TriggerlessEventHandler):
|
||||
return self._historymonitor
|
||||
|
||||
def handle_event(self, key, message):
|
||||
log.debug('TerminadoEventHandler received event: {}'.format(message))
|
||||
LOG.debug('TerminadoEventHandler received event: {}'.format(message))
|
||||
try:
|
||||
message['data'] = self.commands[message['data']['command']](message['data'])
|
||||
return message
|
||||
except KeyError:
|
||||
log.error('IGNORING MESSAGE: Invalid message received: {}'.format(message))
|
||||
LOG.error('IGNORING MESSAGE: Invalid message received: {}'.format(message))
|
||||
|
||||
def write(self, data):
|
||||
self.terminado_server.pty.write(data['shellcmd'])
|
||||
|
@ -4,7 +4,8 @@ from terminado import TermSocket, SingleTermManager
|
||||
|
||||
from tfw.config import tfwenv
|
||||
from tfw.config.logs import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TerminadoMiniServer:
|
||||
@ -41,6 +42,6 @@ class TerminadoMiniServer:
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
log.info('Terminado Mini Server listening on {}'.format(tfwenv.TERMINADO_PORT))
|
||||
LOG.info('Terminado Mini Server listening on {}'.format(tfwenv.TERMINADO_PORT))
|
||||
TerminadoMiniServer('/terminal', tfwenv.TERMINADO_PORT, tfwenv.TERMINADO_WD, ['bash']).listen()
|
||||
IOLoop.instance().start()
|
||||
|
@ -5,7 +5,8 @@ from tfw.networking.zmq_connector_base import ZMQConnectorBase
|
||||
from tfw.networking.serialization import serialize_all
|
||||
from tfw.config import tfwenv
|
||||
from tfw.config.logs import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EventHandlerDownlinkConnector(ZMQConnectorBase):
|
||||
@ -15,7 +16,7 @@ class EventHandlerDownlinkConnector(ZMQConnectorBase):
|
||||
self._zmq_pull_stream = ZMQStream(self._zmq_pull_socket)
|
||||
address = 'tcp://*:{}'.format(tfwenv.RECEIVER_PORT)
|
||||
self._zmq_pull_socket.bind(address)
|
||||
log.debug('Pull socket bound to {}'.format(address))
|
||||
LOG.debug('Pull socket bound to {}'.format(address))
|
||||
|
||||
|
||||
class EventHandlerUplinkConnector(ZMQConnectorBase):
|
||||
@ -24,7 +25,7 @@ class EventHandlerUplinkConnector(ZMQConnectorBase):
|
||||
self._zmq_pub_socket = self._zmq_context.socket(zmq.PUB)
|
||||
address = 'tcp://*:{}'.format(tfwenv.PUBLISHER_PORT)
|
||||
self._zmq_pub_socket.bind(address)
|
||||
log.debug('Pub socket bound to {}'.format(address))
|
||||
LOG.debug('Pub socket bound to {}'.format(address))
|
||||
|
||||
|
||||
class EventHandlerConnector(EventHandlerDownlinkConnector, EventHandlerUplinkConnector):
|
||||
|
@ -6,7 +6,8 @@ from tfw.networking.server.zmq_websocket_handler import ZMQWebSocketProxy
|
||||
from tfw.networking.event_handlers.server_connector import ServerUplinkConnector
|
||||
from tfw.message_sender import MessageSender
|
||||
from tfw.config.logs import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TFWServer:
|
||||
@ -33,7 +34,7 @@ class TFWServer:
|
||||
def make_response(self, message):
|
||||
trigger = message.get('trigger', '')
|
||||
try: self._fsm_manager.trigger(trigger, message)
|
||||
except AttributeError: log.debug('FSM failed to execute nonexistent trigger: "{}"'.format(trigger))
|
||||
except AttributeError: LOG.debug('FSM failed to execute nonexistent trigger: "{}"'.format(trigger))
|
||||
return message
|
||||
|
||||
def proxy_filter(self, message):
|
||||
@ -62,7 +63,7 @@ class FSMManager:
|
||||
|
||||
if all(predicate_results):
|
||||
try: self.fsm.trigger(trigger, message=message)
|
||||
except AttributeError: log.debug('FSM failed to execute nonexistent trigger: "{}"'.format(trigger))
|
||||
except AttributeError: LOG.debug('FSM failed to execute nonexistent trigger: "{}"'.format(trigger))
|
||||
|
||||
def subscribe_predicate(self, trigger, *predicates):
|
||||
self.trigger_predicates[trigger].extend(predicates)
|
||||
|
@ -5,7 +5,8 @@ from tornado.websocket import WebSocketHandler
|
||||
from tfw.networking.serialization import deserialize_all
|
||||
from tfw.networking.server.event_handler_connector import EventHandlerConnector
|
||||
from tfw.config.logs import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ZMQWebSocketHandler(WebSocketHandler):
|
||||
@ -19,7 +20,7 @@ class ZMQWebSocketHandler(WebSocketHandler):
|
||||
ZMQWebSocketHandler.instances.remove(self)
|
||||
|
||||
def open(self, *args, **kwargs):
|
||||
log.debug('WebSocket connection initiated')
|
||||
LOG.debug('WebSocket connection initiated')
|
||||
self._event_handler_connector.register_callback(self.zmq_callback)
|
||||
|
||||
@classmethod
|
||||
@ -27,13 +28,13 @@ class ZMQWebSocketHandler(WebSocketHandler):
|
||||
keyhandlers = {'mirror': cls.mirror}
|
||||
|
||||
key, data = deserialize_all(*msg_parts)
|
||||
log.debug('Received on pull socket: {}'.format(data))
|
||||
LOG.debug('Received on pull socket: {}'.format(data))
|
||||
if key not in keyhandlers:
|
||||
for instance in cls.instances:
|
||||
instance.write_message(data)
|
||||
else:
|
||||
try: keyhandlers[key](data['data'])
|
||||
except KeyError: log.error('Invalid mirror message format! Ignoring.')
|
||||
except KeyError: LOG.error('Invalid mirror message format! Ignoring.')
|
||||
|
||||
@classmethod
|
||||
def mirror(cls, data):
|
||||
@ -41,7 +42,7 @@ class ZMQWebSocketHandler(WebSocketHandler):
|
||||
cls._event_handler_connector.send_message({'data': data}, key)
|
||||
|
||||
def on_message(self, message):
|
||||
log.debug('Received on WebSocket: {}'.format(message))
|
||||
LOG.debug('Received on WebSocket: {}'.format(message))
|
||||
self.send_message(self.make_response(message))
|
||||
|
||||
def make_response(self, message):
|
||||
|
Loading…
Reference in New Issue
Block a user