printrun-src/calibrateextruder.py

changeset 45
c82943fb205f
parent 15
0bbb006204fc
--- a/printrun-src/calibrateextruder.py	Tue Jan 19 20:44:16 2021 +0100
+++ b/printrun-src/calibrateextruder.py	Tue Jan 19 20:45:09 2021 +0100
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # This file is part of the Printrun suite.
 #
 # Printrun is free software: you can redistribute it and/or modify
@@ -41,7 +41,7 @@
 def float_input(prompt=''):
     f = None
     while f is None:
-        s = raw_input(prompt)
+        s = input(prompt)
         try:
             f = float(s)
         except ValueError:
@@ -56,7 +56,7 @@
             sys.stdout.write(s)
             sys.stdout.flush()
             time.sleep(1.0 / 5)
-    print
+    print()
 def w(s):
     sys.stdout.write(s)
     sys.stdout.flush()
@@ -75,9 +75,9 @@
             time.sleep(1.5)
             f = True
         curtemp = gettemp(p)
-        if curtemp: w(u"\rHeating extruder up.. %3d \xb0C" % curtemp)
-    if s: print
-    else: print "\nReady."
+        if curtemp: w("\rHeating extruder up.. %3d \xb0C" % curtemp)
+    if s: print()
+    else: print("\nReady.")
 
 def gettemp(p):
     try: p.logl
@@ -89,14 +89,14 @@
         if 'T:' in line:
             try:
                 setattr(p, 'temp', int(line.split('T:')[1].split()[0]))
-            except: print line
+            except: print(line)
     p.logl = len(p.log)
     return p.temp
 if not os.path.exists(port):
     port = 0
 
 # Parse options
-help = u"""
+help = """
 %s [ -l DISTANCE ] [ -s STEPS ] [ -t TEMP ] [ -p PORT ]
         -l      --length        Length of filament to extrude for each calibration step (default: %d mm)
         -s      --steps         Initial amount of steps to use (default: %d steps)
@@ -106,13 +106,13 @@
 """[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:
-    print str(err)
-    print help
+except getopt.GetoptError as err:
+    print(str(err))
+    print(help)
     sys.exit(2)
 for o, a in opts:
     if o in ('-h', '--help'):
-        print help
+        print(help)
         sys.exit()
     elif o in ('-l', '--length'):
         n = float(a)
@@ -121,17 +121,17 @@
     elif o in ('-t', '--temp'):
         temp = int(a)
         if temp >= tempmax:
-            print (u'%d \xb0C? Are you insane?'.encode('utf-8') % temp) + (" That's over nine thousand!" if temp > 9000 else '')
+            print(('%d \xb0C? Are you insane?'.encode('utf-8') % temp) + (" That's over nine thousand!" if temp > 9000 else ''))
             sys.exit(255)
     elif o in ('-p', '--port'):
         port = a
 
 # Show initial parameters
-print "Initial parameters"
-print "Steps per mm:    %3d steps" % k
-print "Length extruded: %3d mm" % n
-print
-print "Serial port:     %s" % (port if port else 'auto')
+print("Initial parameters")
+print("Steps per mm:    %3d steps" % k)
+print("Length extruded: %3d mm" % n)
+print()
+print("Serial port:     %s" % (port if port else 'auto'))
 
 p = None
 try:
@@ -140,12 +140,12 @@
     try:
         p = printcore(port, 115200)
     except:
-        print 'Error.'
+        print('Error.')
         raise
     while not p.online:
         time.sleep(1)
         w('.')
-    print " connected."
+    print(" connected.")
 
     heatup(p, temp)
 
@@ -160,8 +160,8 @@
         if n != m:
             k = (n / m) * k
             p.send_now("M92 E%d" % int(round(k)))  # Set new step count
-            print "Steps per mm:    %3d steps" % k  # Tell user
-    print 'Calibration completed.'  # Yay!
+            print("Steps per mm:    %3d steps" % k)  # Tell user
+    print('Calibration completed.')  # Yay!
 except KeyboardInterrupt:
     pass
 finally:

mercurial