Commit b54c8ba8 authored by Guillaume Seguin's avatar Guillaume Seguin

Merge branch 'logging'

parents e47bc618 f34a8c91
......@@ -22,7 +22,6 @@ from select import error as SelectError
from threading import Thread, Lock
from Queue import Queue, Empty as QueueEmpty
import time
import sys
import platform
import os
import traceback
......@@ -35,6 +34,9 @@ from printrun.GCodeAnalyzer import GCodeAnalyzer
from printrun.printrun_utils import install_locale, decode_utf8
install_locale('pronterface')
import logging
logging.basicConfig(format = "%(levelname)s: %(message)s")
def locked(f):
@wraps(f)
def inner(*args, **kw):
......@@ -163,11 +165,11 @@ class printcore():
self.printer_tcp.settimeout(self.timeout)
self.printer = self.printer_tcp.makefile()
except socket.error as e:
print _("Could not connect to %s:%s:") % (hostname, port)
logging.error(_("Could not connect to %s:%s:") % (hostname, port) +
"\n" + _("Socket error %s:") % e.errno +
"\n" + e.strerror)
self.printer = None
self.printer_tcp = None
print _("Socket error %s:") % e.errno,
print e.strerror
return
else:
disable_hup(self.port)
......@@ -177,9 +179,9 @@ class printcore():
baudrate = self.baud,
timeout = 0.25)
except SerialException as e:
print _("Could not connect to %s at baudrate %s:") % (self.port, self.baud)
logging.error(_("Could not connect to %s at baudrate %s:") % (self.port, self.baud) +
"\n" + _("Serial error: %s") % e)
self.printer = None
print _("Serial error: %s") % e
return
self.stop_read_thread = False
self.read_thread = Thread(target = self._listen)
......@@ -208,25 +210,25 @@ class printcore():
if self.recvcb:
try: self.recvcb(line)
except: pass
if self.loud: print "RECV:", line.rstrip()
if self.loud: logging.info("RECV: %s" % line.rstrip())
return line
except SelectError as e:
if 'Bad file descriptor' in e.args[1]:
print _(u"Can't read from printer (disconnected?) (SelectError {0}): {1}").format(e.errno, decode_utf8(e.strerror))
logging.error(_(u"Can't read from printer (disconnected?) (SelectError {0}): {1}").format(e.errno, decode_utf8(e.strerror)))
return None
else:
print _(u"SelectError ({0}): {1}").format(e.errno, decode_utf8(e.strerror))
logging.error(_(u"SelectError ({0}): {1}").format(e.errno, decode_utf8(e.strerror)))
raise
except SerialException as e:
print _(u"Can't read from printer (disconnected?) (SerialException): {0}").format(decode_utf8(str(e)))
logging.error(_(u"Can't read from printer (disconnected?) (SerialException): {0}").format(decode_utf8(str(e))))
return None
except socket.error as e:
print _(u"Can't read from printer (disconnected?) (Socket error {0}): {1}").format(e.errno, decode_utf8(e.strerror))
logging.error(_(u"Can't read from printer (disconnected?) (Socket error {0}): {1}").format(e.errno, decode_utf8(e.strerror)))
return None
except OSError as e:
if e.errno == errno.EAGAIN: # Not a real error, no data was available
return ""
print _(u"Can't read from printer (disconnected?) (OS Error {0}): {1}").format(e.errno, e.strerror)
logging.error(_(u"Can't read from printer (disconnected?) (OS Error {0}): {1}").format(e.errno, e.strerror))
return None
def _listen_can_continue(self):
......@@ -435,7 +437,7 @@ class printcore():
else:
self.priqueue.put_nowait(command)
else:
print "Not connected to printer."
logging.error(_("Not connected to printer."))
def send_now(self, command, wait = 0):
"""Sends a command to the printer ahead of the command queue, without a
......@@ -443,7 +445,7 @@ class printcore():
if self.online:
self.priqueue.put_nowait(command)
else:
print "Not connected to printer."
logging.error(_("Not connected to printer."))
def _print(self, resuming = False):
self._stop_sender()
......@@ -452,8 +454,8 @@ class printcore():
#callback for printing started
try: self.startcb(resuming)
except:
print "Print start callback failed with:"
traceback.print_exc(file = sys.stdout)
logging.error(_("Print start callback failed with:") +
"\n" + traceback.format_exc())
while self.printing and self.printer and self.online:
self._sendnext()
self.sentlines = {}
......@@ -463,11 +465,11 @@ class printcore():
#callback for printing done
try: self.endcb()
except:
print "Print end callback failed with:"
traceback.print_exc(file = sys.stdout)
logging.error(_("Print end callback failed with:") +
"\n" + traceback.format_exc())
except:
print "Print thread died due to the following error:"
traceback.print_exc(file = sys.stdout)
logging.error(_("Print thread died due to the following error:") +
"\n" + traceback.format_exc())
finally:
self.print_thread = None
self._start_sender()
......@@ -554,10 +556,10 @@ class printcore():
# run the command through the analyzer
try: self.analyzer.Analyze(command)
except:
print "Warning: could not analyze command %s:" % command
traceback.print_exc(file = sys.stdout)
logging.error(_("Warning: could not analyze command %s:") % command +
"\n" + traceback.format_exc())
if self.loud:
print "SENT:", command
logging.info("SENT: %s" % command)
if self.sendcb:
try: self.sendcb(command)
except: pass
......@@ -566,11 +568,11 @@ class printcore():
if self.printer_tcp: self.printer.flush()
self.writefailures = 0
except socket.error as e:
print _(u"Can't write to printer (disconnected?) (Socket error {0}): {1}").format(e.errno, decode_utf8(e.strerror))
logging.error(_(u"Can't write to printer (disconnected?) (Socket error {0}): {1}").format(e.errno, decode_utf8(e.strerror)))
self.writefailures += 1
except SerialException as e:
print _(u"Can't write to printer (disconnected?) (SerialException): {0}").format(decode_utf8(str(e)))
logging.error(_(u"Can't write to printer (disconnected?) (SerialException): {0}").format(decode_utf8(str(e))))
self.writefailures += 1
except RuntimeError as e:
print _(u"Socket connection broken, disconnected. ({0}): {1}").format(e.errno, decode_utf8(e.strerror))
logging.error(_(u"Socket connection broken, disconnected. ({0}): {1}").format(e.errno, decode_utf8(e.strerror)))
self.writefailures += 1
......@@ -25,6 +25,7 @@ import codecs
import shlex
import argparse
import locale
import logging
from . import printcore
from printrun.printrun_utils import install_locale
......@@ -402,7 +403,7 @@ class pronsole(cmd.Cmd):
print u"".join(unicode(i) for i in msg)
def logError(self, *msg):
print u"".join(unicode(i) for i in msg)
logging.error(u"".join(unicode(i) for i in msg))
def promptf(self):
"""A function to generate prompts so that we can do dynamic prompts. """
......@@ -558,6 +559,7 @@ class pronsole(cmd.Cmd):
if macro_def.strip() == "":
self.logError("Empty macro - cancelled")
return
macro = None
pycode = "def macro(self,*arg):\n"
if "\n" not in macro_def.strip():
pycode += self.compile_macro_line(" " + macro_def.strip())
......@@ -1345,7 +1347,7 @@ class pronsole(cmd.Cmd):
try:
while True:
self.p.send_now("M105")
if(self.sdprinting):
if self.sdprinting:
self.p.send_now("M27")
time.sleep(interval)
#print (self.tempreadings.replace("\r", "").replace("T", "Hotend").replace("B", "Bed").replace("\n", "").replace("ok ", ""))
......@@ -1551,4 +1553,3 @@ class pronsole(cmd.Cmd):
readline.set_completer(self.old_completer)
except ImportError:
pass
......@@ -27,6 +27,9 @@ import cStringIO as StringIO
import subprocess
import shlex
import glob
import logging
from . import pronsole
from . import printcore
from printrun.printrun_utils import install_locale, RemainingTimeEstimator
install_locale('pronterface')
......@@ -34,7 +37,7 @@ install_locale('pronterface')
try:
import wx
except:
print _("WX is not installed. This program requires WX to run.")
logging.error(_("WX is not installed. This program requires WX to run."))
raise
from printrun.pronterface_widgets import SpecialButton, MacroEditor, \
......@@ -49,8 +52,6 @@ if os.name == "nt":
from printrun.printrun_utils import iconfile, configfile
from printrun.gui import MainWindow
from printrun.excluder import Excluder
from . import pronsole
from . import printcore
from pronsole import dosify, wxSetting, HiddenSetting, StringSetting, SpinSetting, FloatSpinSetting, BooleanSetting, StaticTextSetting
from printrun import gcoder
......@@ -213,7 +214,7 @@ class PronterWindow(MainWindow, pronsole.pronsole):
self.settings._add(BooleanSetting("lockbox", False, _("Display interface lock checkbox"), _("Display a checkbox that, when check, locks most of Pronterface"), "UI"))
self.settings._add(BooleanSetting("lockonstart", False, _("Lock interface upon print start"), _("If lock checkbox is enabled, lock the interface when starting a print"), "UI"))
self.settings._add(HiddenSetting("last_bed_temperature", 0.0))
self.settings._add(HiddenSetting("last_file_path", ""))
self.settings._add(HiddenSetting("last_file_path", u""))
self.settings._add(HiddenSetting("last_temperature", 0.0))
self.settings._add(HiddenSetting("last_extrusion", 5.0))
self.settings._add(HiddenSetting("default_extrusion", 5.0))
......@@ -298,10 +299,10 @@ class PronterWindow(MainWindow, pronsole.pronsole):
rco.write(_("# I moved all your custom buttons into .pronsolerc.\n# Please don't add them here any more.\n# Backup of your old buttons is in custombtn.old\n"))
rco.close()
except IOError, x:
print str(x)
logging.error(str(x))
else:
print _("Note!!! You have specified custom buttons in both custombtn.txt and .pronsolerc")
print _("Ignoring custombtn.txt. Remove all current buttons to revert to custombtn.txt")
logging.warning(_("Note!!! You have specified custom buttons in both custombtn.txt and .pronsolerc"))
logging.warning(_("Ignoring custombtn.txt. Remove all current buttons to revert to custombtn.txt"))
except:
pass
......@@ -1475,7 +1476,7 @@ Printrun. If not, see <http://www.gnu.org/licenses/>."""
wx.CallAfter(self.gviz.Refresh)
if self.p.online:
if self.p.writefailures >= 4:
print _("Disconnecting after 4 failed writes.")
logging.error(_("Disconnecting after 4 failed writes."))
self.status_thread = None
self.disconnect()
return
......@@ -1605,7 +1606,7 @@ Printrun. If not, see <http://www.gnu.org/licenses/>."""
if config:
fpath = os.path.join(self.slic3r_configpath, cat, config)
pararray += ["--load", fpath]
print "Slicing: " + " ".join(pararray)
print _("Slicing ") + " ".join(pararray)
self.skeinp = subprocess.Popen(pararray, stderr = subprocess.STDOUT, stdout = subprocess.PIPE)
while True:
o = self.skeinp.stdout.read(1)
......@@ -1614,7 +1615,7 @@ Printrun. If not, see <http://www.gnu.org/licenses/>."""
self.skeinp.wait()
self.stopsf = 1
except:
print _("Failed to execute slicing software: ")
logging.error(_("Failed to execute slicing software: "))
self.stopsf = 1
traceback.print_exc(file = sys.stdout)
......@@ -1835,10 +1836,10 @@ Printrun. If not, see <http://www.gnu.org/licenses/>."""
except SerialException as e:
# Currently, there is no errno, but it should be there in the future
if e.errno == 2:
print _("Error: You are trying to connect to a non-existing port.")
logging.error(_("Error: You are trying to connect to a non-existing port."))
elif e.errno == 8:
print _("Error: You don't have permission to open %s.") % port
print _("You might need to add yourself to the dialout group.")
logging.error(_("Error: You don't have permission to open %s.") % port)
logging.error(_("You might need to add yourself to the dialout group."))
else:
traceback.print_exc()
# Kill the scope anyway
......
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