Commit 5778ff00 authored by Guillaume Seguin's avatar Guillaume Seguin

Cleanup printcore's main

parent f8151b52
...@@ -324,14 +324,15 @@ class printcore(): ...@@ -324,14 +324,15 @@ class printcore():
if __name__ == '__main__': if __name__ == '__main__':
baud = 115200 baud = 115200
loud = False loud = False
statusreport=False statusreport = False
try: try:
opts, args=getopt.getopt(sys.argv[1:], "h,b:,v,s",["help","baud","verbose","statusreport"]) opts, args = getopt.getopt(sys.argv[1:], "h,b:,v,s",
["help", "baud", "verbose", "statusreport"])
except getopt.GetoptError,err: except getopt.GetoptError,err:
print str(err) print str(err)
print help print help
sys.exit(2) sys.exit(2)
for o,a in opts: for o, a in opts:
if o in ('-h', '--help'): if o in ('-h', '--help'):
# FIXME: Fix help # FIXME: Fix help
print "Opts are: --help , -b --baud = baudrate, -v --verbose, -s --statusreport" print "Opts are: --help , -b --baud = baudrate, -v --verbose, -s --statusreport"
...@@ -339,22 +340,21 @@ if __name__ == '__main__': ...@@ -339,22 +340,21 @@ if __name__ == '__main__':
if o in ('-b', '--baud'): if o in ('-b', '--baud'):
baud = int(a) baud = int(a)
if o in ('-v','--verbose'): if o in ('-v','--verbose'):
loud=True loud = True
elif o in ('-s','--statusreport'): elif o in ('-s','--statusreport'):
statusreport=True statusreport = True
if len (args) > 1:
if len(args)>1: port = args[-2]
port=args[-2] filename = args[-1]
filename=args[-1] print "Printing: %s on %s with baudrate %d" % (filename, port, baud)
print "Printing: "+filename + " on "+port + " with baudrate "+str(baud)
else: else:
print "Usage: python [-h|-b|-v|-s] printcore.py /dev/tty[USB|ACM]x filename.gcode" print "Usage: python [-h|-b|-v|-s] printcore.py /dev/tty[USB|ACM]x filename.gcode"
sys.exit(2) sys.exit(2)
p=printcore(port,baud) p = printcore(port, baud)
p.loud = loud p.loud = loud
time.sleep(2) time.sleep(2)
gcode=[i.replace("\n","") for i in open(filename)] gcode = [i.replace("\n","") for i in open(filename)]
p.startprint(gcode) p.startprint(gcode)
try: try:
...@@ -362,10 +362,10 @@ if __name__ == '__main__': ...@@ -362,10 +362,10 @@ if __name__ == '__main__':
p.loud=False p.loud=False
sys.stdout.write("Progress: 00.0%") sys.stdout.write("Progress: 00.0%")
sys.stdout.flush() sys.stdout.flush()
while(p.printing): while p.printing:
time.sleep(1) time.sleep(1)
if statusreport: if statusreport:
sys.stdout.write("\b\b\b\b%02.1f%%" % (100*float(p.queueindex)/len(p.mainqueue),) ) sys.stdout.write("\b\b\b\b%02.1f%%" % (100 * float(p.queueindex) / len(p.mainqueue),) )
sys.stdout.flush() sys.stdout.flush()
p.disconnect() p.disconnect()
sys.exit(0) sys.exit(0)
......
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