-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstart.py
executable file
·41 lines (37 loc) · 1.26 KB
/
start.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/python
import subprocess
import os
from read_mail import save_file
import sys
import time
from daemon import Daemon
class CncDaemon(Daemon):
def run(self):
prog = os.path.abspath("/home/pi/x-cnc/x-cnc")
output = open("/home/pi/x-cnc/log","w")
while True:
sys.stdout.write("Start")
file_gcode = save_file()
for file_name in file_gcode:
op = file_name.split("_")[1].split(".")[0]
sys.stdout.write("Option to do: " + str(op) + "\n")
sys.stdout.write("Arquivo sendo processado: " + file_name + "\n")
subprocess.Popen([prog,file_name,"1",op], stdout=output)
time.sleep(100)
output.close()
if __name__ == "__main__":
daemon = CncDaemon('/tmp/cnc.pid')
if len(sys.argv) == 2:
if 'start' == sys.argv[1]:
daemon.start()
elif 'stop' == sys.argv[1]:
daemon.stop()
elif 'restart' == sys.argv[1]:
daemon.restart()
else:
print "Unknown command"
sys.exit(2)
sys.exit(0)
else:
print "usage: %s start|stop|restart" % sys.argv[0]
sys.exit(2)