Commit c942bc6e authored by D1plo1d's avatar D1plo1d

Refactoring pronsole logging so that prontserve can send useful errors over websockets

parent 03295e11
This diff is collapsed.
...@@ -196,11 +196,10 @@ class ConstructSocketHandler(tornado.websocket.WebSocketHandler): ...@@ -196,11 +196,10 @@ class ConstructSocketHandler(tornado.websocket.WebSocketHandler):
try: try:
if cmd == "set": cmd = "construct_set" if cmd == "set": cmd = "construct_set"
response = getattr(prontserve, "do_%s"%cmd)(*args, **kwargs) response = getattr(prontserve, "do_%s"%cmd)(*args, **kwargs)
print response self.write_message({"ack": response})
if response is not None: self.write_message(response) except Exception as ex:
except:
print traceback.format_exc() print traceback.format_exc()
self.write_message({"error": "bad command."}) self.write_message({"error": str(ex)})
else: else:
self.write_message({"error": "%s command does not exist."%cmd}) self.write_message({"error": "%s command does not exist."%cmd})
...@@ -253,6 +252,7 @@ class EventEmitter(object): ...@@ -253,6 +252,7 @@ class EventEmitter(object):
class Prontserve(pronsole.pronsole, EventEmitter): class Prontserve(pronsole.pronsole, EventEmitter):
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.initializing = True
pronsole.pronsole.__init__(self) pronsole.pronsole.__init__(self)
EventEmitter.__init__(self) EventEmitter.__init__(self)
self.settings.sensor_names = {'T': 'extruder', 'B': 'bed'} self.settings.sensor_names = {'T': 'extruder', 'B': 'bed'}
...@@ -273,6 +273,7 @@ class Prontserve(pronsole.pronsole, EventEmitter): ...@@ -273,6 +273,7 @@ class Prontserve(pronsole.pronsole, EventEmitter):
self._sensor_update_received = True self._sensor_update_received = True
self.init_mdns() self.init_mdns()
self.jobs.listeners.add(self) self.jobs.listeners.add(self)
self.initializing = False
def init_mdns(self): def init_mdns(self):
sdRef = pybonjour.DNSServiceRegister(name = None, sdRef = pybonjour.DNSServiceRegister(name = None,
...@@ -458,6 +459,11 @@ class Prontserve(pronsole.pronsole, EventEmitter): ...@@ -458,6 +459,11 @@ class Prontserve(pronsole.pronsole, EventEmitter):
print msg print msg
self.fire("log", {'msg': msg, 'level': "debug"}) self.fire("log", {'msg': msg, 'level': "debug"})
def logError(self, *msg):
print u"".join(unicode(i) for i in msg)
if self.initializing == False:
raise Exception(u"".join(unicode(i) for i in msg))
def write_prompt(self): def write_prompt(self):
None None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment