Skip to content

Commit

Permalink
Bear: Derive from LogPrinter
Browse files Browse the repository at this point in the history
So we can use its logging facilities.
  • Loading branch information
sils committed Apr 15, 2015
1 parent 18e8fe8 commit 665c302
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions coalib/bears/Bear.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

from coalib.misc.i18n import _
from coalib.output.printers.LOG_LEVEL import LOG_LEVEL
from coalib.processes.communication.LogMessage import LogMessage
from coalib.output.printers.LogPrinter import LogPrinter
from coalib.settings.FunctionMetadata import FunctionMetadata
from coalib.settings.Section import Section


class Bear:
class Bear(LogPrinter):
"""
A bear contains the actual subroutine that is responsible for checking
source code for certain specifications. However it can actually do
Expand Down Expand Up @@ -39,13 +39,16 @@ def __init__(self,
section,
message_queue,
TIMEOUT=0):
LogPrinter.__init__(self)

if not isinstance(section, Section):
raise TypeError("section has to be of type Section.")
if not hasattr(message_queue, "put") and message_queue is not None:
raise TypeError("message_queue has to be a Queue or None.")

self.section = section
self.message_queue = message_queue
print(type(self.message_queue))
self.TIMEOUT = TIMEOUT

def set_up(self):
Expand All @@ -54,26 +57,12 @@ def set_up(self):
def tear_down(self):
pass

def debug(self, *args, delimiter=' '):
self.__send_msg(LOG_LEVEL.DEBUG, delimiter, *args)

def warn(self, *args, delimiter=' '):
self.__send_msg(LOG_LEVEL.WARNING, delimiter, *args)

def err(self, *args, delimiter=' '):
self.__send_msg(LOG_LEVEL.ERROR, delimiter, *args)

def __send_msg(self, log_level, delimiter, *args):
if self.message_queue is None:
return

if len(args) == 0:
return
def _print(self, output, **kwargs):
self.log(LOG_LEVEL.DEBUG, output)

self.message_queue.put(LogMessage(log_level,
*args,
delimiter=delimiter),
timeout=self.TIMEOUT)
def log_message(self, log_message, timestamp=None, **kwargs):
if self.message_queue is not None:
self.message_queue.put(log_message)

def run(self, *args, dependency_results=None, **kwargs):
raise NotImplementedError
Expand Down

1 comment on commit 665c302

@fneu
Copy link
Contributor

@fneu fneu commented on 665c302 Apr 15, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

Please sign in to comment.