printrun-src/printcore.py

changeset 45
c82943fb205f
parent 15
0bbb006204fc
equal deleted inserted replaced
44:310be640a303 45:c82943fb205f
1 #!/usr/bin/env python 1 #!/usr/bin/env python3
2 2
3 # This file is part of the Printrun suite. 3 # This file is part of the Printrun suite.
4 # 4 #
5 # Printrun is free software: you can redistribute it and/or modify 5 # Printrun is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by 6 # it under the terms of the GNU General Public License as published by
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)]

mercurial