diff --git a/calibrateextruder.py b/calibrateextruder.py index c3d5349ea..696e5df5b 100644 --- a/calibrateextruder.py +++ b/calibrateextruder.py @@ -106,7 +106,7 @@ def gettemp(p): """[1:-1].encode('utf-8') % (sys.argv[0], n, k, temp, tempmax, port if port else 'auto') try: opts, args = getopt.getopt(sys.argv[1:], "hl:s:t:p:", ["help", "length=", "steps=", "temp=", "port="]) -except getopt.GetoptError, err: +except getopt.GetoptError as err: print str(err) print help sys.exit(2) diff --git a/plater.py b/plater.py index 67f61b6c5..4fff6f5b9 100755 --- a/plater.py +++ b/plater.py @@ -37,7 +37,7 @@ try: opts, args = getopt.getopt(sys.argv[1:], "hV", ["help", "version"]) - except getopt.GetoptError, err: + except getopt.GetoptError as err: print str(err) print usage sys.exit(2) diff --git a/printcore.py b/printcore.py index 8a5998ff2..07640f273 100755 --- a/printcore.py +++ b/printcore.py @@ -45,7 +45,7 @@ try: opts, args = getopt.getopt(sys.argv[1:], "b:svVh", ["baud=", "statusreport", "verbose", "version", "help"]) - except getopt.GetoptError, err: + except getopt.GetoptError as err: print str(err) print usage sys.exit(2) diff --git a/printrun/gcoder.py b/printrun/gcoder.py index fddec626a..c850228b9 100755 --- a/printrun/gcoder.py +++ b/printrun/gcoder.py @@ -59,7 +59,7 @@ def __getattr__(self, name): import gcoder_line Line = gcoder_line.GLine LightLine = gcoder_line.GLightLine -except Exception, e: +except Exception as e: logging.warning("Memory-efficient GCoder implementation unavailable: %s" % e) Line = PyLine LightLine = PyLightLine diff --git a/printrun/power/__init__.py b/printrun/power/__init__.py index 1a01547e7..c34f25300 100644 --- a/printrun/power/__init__.py +++ b/printrun/power/__init__.py @@ -65,7 +65,7 @@ def deinhibit_sleep(): return inhibit_sleep_handler.UnInhibit(inhibit_sleep_token) inhibit_sleep_token = None - except Exception, e: + except Exception as e: logging.warning("Could not setup DBus for sleep inhibition: %s" % e) def inhibit_sleep(reason): @@ -107,7 +107,7 @@ def set_nice(nice, p = None): set_nice(i, p) high_priority_nice = i break - except psutil.AccessDenied, e: + except psutil.AccessDenied as e: pass set_nice(orig_nice, p) @@ -132,7 +132,7 @@ def powerset_print_start(reason): def powerset_print_stop(): reset_priority() deinhibit_sleep() -except ImportError, e: +except ImportError as e: logging.warning("psutil unavailable, could not import power utils:" + str(e)) def powerset_print_start(reason): diff --git a/printrun/printcore.py b/printrun/printcore.py index b240c8220..8ddd87ae9 100644 --- a/printrun/printcore.py +++ b/printrun/printcore.py @@ -449,7 +449,7 @@ def pause(self): # might be calling it from the thread itself try: self.print_thread.join() - except RuntimeError, e: + except RuntimeError as e: if e.message == "cannot join current thread": pass else: diff --git a/printrun/pronsole.py b/printrun/pronsole.py index e77d384e4..3cf1e558e 100644 --- a/printrun/pronsole.py +++ b/printrun/pronsole.py @@ -557,7 +557,7 @@ def set(self, var, str): self.save_in_rc("set " + var, "set %s %s" % (var, value)) except AttributeError: logging.debug(_("Unknown variable '%s'") % var) - except ValueError, ve: + except ValueError as ve: if hasattr(ve, "from_validator"): self.logError(_("Bad value %s for variable '%s': %s") % (str, var, ve.args[0])) else: @@ -675,7 +675,7 @@ def save_in_rc(self, key, definition): # self.log("Saved '"+key+"' to '"+self.rc_filename+"'") # else: # self.log("Removed '"+key+"' from '"+self.rc_filename+"'") - except Exception, e: + except Exception as e: self.logError("Saving failed for ", key + ":", str(e)) finally: del rci, rco @@ -962,7 +962,7 @@ def do_slice(self, l): blocking = True) self.log(_("Loading sliced file.")) self.do_load(l[0].replace(".stl", "_export.gcode")) - except Exception, e: + except Exception as e: self.logError(_("Slicing failed: %s") % e) def complete_slice(self, text, line, begidx, endidx): diff --git a/printrun/pronterface.py b/printrun/pronterface.py index 0a9eb7e0f..0d7fc0598 100644 --- a/printrun/pronterface.py +++ b/printrun/pronterface.py @@ -209,7 +209,7 @@ def __init__(self, app, filename = None, size = winsize): rco = open("custombtn.txt", "w") 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: + except IOError as x: logging.error(str(x)) else: logging.warning(_("Note!!! You have specified custom buttons in both custombtn.txt and .pronsolerc")) @@ -405,7 +405,7 @@ def do_settemp(self, l = ""): self.logError(_("Printer is not online.")) else: self.logError(_("You cannot set negative temperatures. To turn the hotend off entirely, set its temperature to 0.")) - except Exception, x: + except Exception as x: self.logError(_("You must enter a temperature. (%s)") % (repr(x),)) def do_bedtemp(self, l = ""): @@ -425,7 +425,7 @@ def do_bedtemp(self, l = ""): self.logError(_("Printer is not online.")) else: self.logError(_("You cannot set negative temperatures. To turn the bed off entirely, set its temperature to 0.")) - except Exception, x: + except Exception as x: self.logError(_("You must enter a temperature. (%s)") % (repr(x),)) def do_setspeed(self, l = ""): @@ -440,7 +440,7 @@ def do_setspeed(self, l = ""): self.log(_("Setting print speed factor to %d%%.") % speed) else: self.logError(_("Printer is not online.")) - except Exception, x: + except Exception as x: self.logError(_("You must enter a speed. (%s)") % (repr(x),)) def do_setflow(self, l = ""): @@ -455,7 +455,7 @@ def do_setflow(self, l = ""): self.log(_("Setting print flow factor to %d%%.") % flow) else: self.logError(_("Printer is not online.")) - except Exception, x: + except Exception as x: self.logError(_("You must enter a flow. (%s)") % (repr(x),)) def setbedgui(self, f): diff --git a/printrun/serialWrapper.py b/printrun/serialWrapper.py index d77009e17..3c89d537c 100644 --- a/printrun/serialWrapper.py +++ b/printrun/serialWrapper.py @@ -41,7 +41,7 @@ def set_special_baudrate(port, baudrate): # set serial_struct res = FCNTL.ioctl(port.fd, TCSETS2, buf) - except IOError, e: + except IOError as e: raise ValueError('Failed to set custom baud rate (%s): %s' % (baudrate, e)) # We need to change the function inside the serialposix module otherwise, it won't diff --git a/printrun/stlplater.py b/printrun/stlplater.py index 5bb2fc2e2..3a4830fc1 100644 --- a/printrun/stlplater.py +++ b/printrun/stlplater.py @@ -478,7 +478,7 @@ def autoplate(self, event = None): if self.simarrange_path: try: self.autoplate_simarrange() - except Exception, e: + except Exception as e: logging.warning(_("Failed to use simarrange for plating, " "falling back to the standard method. " "The error was: ") + e) diff --git a/pronsole.py b/pronsole.py index c18db96fc..cff897840 100755 --- a/pronsole.py +++ b/pronsole.py @@ -36,7 +36,7 @@ try: opts, args = getopt.getopt(sys.argv[1:], "hVvc:e:", ["help", "version", "verbose", "conf=", "config=", "execute="]) - except getopt.GetoptError, err: + except getopt.GetoptError as err: print str(err) print usage sys.exit(2) diff --git a/pronterface.py b/pronterface.py index 150822c26..92707add0 100755 --- a/pronterface.py +++ b/pronterface.py @@ -53,7 +53,7 @@ try: opts, args = getopt.getopt(sys.argv[1:], "hVvac:e:", ["help", "version", "verbose", "autoconnect", "conf=", "config=", "execute="]) - except getopt.GetoptError, err: + except getopt.GetoptError as err: print str(err) print usage sys.exit(2) diff --git a/setup.py b/setup.py index 197435f1f..a6a74a04f 100755 --- a/setup.py +++ b/setup.py @@ -25,7 +25,7 @@ from Cython.Build import cythonize extensions = cythonize("printrun/gcoder_line.pyx") from Cython.Distutils import build_ext -except ImportError, e: +except ImportError as e: print "WARNING: Failed to cythonize: %s" % e # Debug helper: uncomment these: # import traceback