43 " -h, --help\t\t\tPrint this help message and exit\n" |
43 " -h, --help\t\t\tPrint this help message and exit\n" |
44 |
44 |
45 try: |
45 try: |
46 opts, args = getopt.getopt(sys.argv[1:], "b:svVh", |
46 opts, args = getopt.getopt(sys.argv[1:], "b:svVh", |
47 ["baud=", "statusreport", "verbose", "version", "help"]) |
47 ["baud=", "statusreport", "verbose", "version", "help"]) |
48 except getopt.GetoptError, err: |
48 except getopt.GetoptError as err: |
49 print str(err) |
49 print(str(err)) |
50 print usage |
50 print(usage) |
51 sys.exit(2) |
51 sys.exit(2) |
52 for o, a in opts: |
52 for o, a in opts: |
53 if o in ('-h', '--help'): |
53 if o in ('-h', '--help'): |
54 print usage |
54 print(usage) |
55 sys.exit(0) |
55 sys.exit(0) |
56 elif o in ('-V','--version'): |
56 elif o in ('-V','--version'): |
57 print "printrun "+printcore_version |
57 print("printrun "+printcore_version) |
58 sys.exit(0) |
58 sys.exit(0) |
59 elif o in ('-b','--baud'): |
59 elif o in ('-b','--baud'): |
60 try: |
60 try: |
61 baud = int(a) |
61 baud = int(a) |
62 except ValueError: |
62 except ValueError: |
63 print "ValueError:" |
63 print("ValueError:") |
64 print "\tInvalid BAUD_RATE value '%s'" % a |
64 print("\tInvalid BAUD_RATE value '%s'" % a) |
65 print "\tBAUD_RATE must be an integer\n" |
65 print("\tBAUD_RATE must be an integer\n") |
66 # FIXME: This should output a more apropiate error message when |
66 # FIXME: This should output a more apropiate error message when |
67 # not a good baud rate is passed as an argument |
67 # not a good baud rate is passed as an argument |
68 # i.e: when baud <= 1000 or > 225000 |
68 # i.e: when baud <= 1000 or > 225000 |
69 print usage |
69 print(usage) |
70 sys.exit(2) |
70 sys.exit(2) |
71 elif o in ('-v', '--verbose'): |
71 elif o in ('-v', '--verbose'): |
72 loud = True |
72 loud = True |
73 elif o in ('-s', '--statusreport'): |
73 elif o in ('-s', '--statusreport'): |
74 statusreport = True |
74 statusreport = True |
75 |
75 |
76 if len(args) <= 1: |
76 if len(args) <= 1: |
77 print "Error: Port or gcode file were not specified.\n" |
77 print("Error: Port or gcode file were not specified.\n") |
78 print usage |
78 print(usage) |
79 sys.exit(2) |
79 sys.exit(2) |
80 elif len(args) > 1: |
80 elif len(args) > 1: |
81 port = args[-2] |
81 port = args[-2] |
82 filename = args[-1] |
82 filename = args[-1] |
83 print "Printing: %s on %s with baudrate %d" % (filename, port, baud) |
83 print("Printing: %s on %s with baudrate %d" % (filename, port, baud)) |
84 |
84 |
85 p = printcore(port, baud) |
85 p = printcore(port, baud) |
86 p.loud = loud |
86 p.loud = loud |
87 time.sleep(2) |
87 time.sleep(2) |
88 gcode = [i.strip() for i in open(filename)] |
88 gcode = [i.strip() for i in open(filename)] |