-
Notifications
You must be signed in to change notification settings - Fork 94
/
autorun.py
74 lines (66 loc) · 2.52 KB
/
autorun.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/python3
# File name : motor.py
# Description : Control Motors
# Website : www.adeept.com
# E-mail : support@adeept.com
# Author : William
# Date : 2018/10/12
import os
import sys
def search(path,name):
for root, dirs, files in os.walk(path):
if name in dirs or name in files:
flag = 1
root = str(root)
dirs = str(dirs)
return os.path.join(root, dirs)
return -1
def replace_num(file,initial,new_num):
newline=""
str_num=str(new_num)
with open(file,"r") as f:
for line in f.readlines():
if(line.find(initial) == 0):
line = (str_num+'\n')
newline += line
with open(file,"w") as f:
f.writelines(newline)
path_get = str(search('//home/pi/','server.py'))
path_get=path_get[:-15]
if path_get != -1:
while 1:
command_select = input('Do you want to autostart the sound version or the Test version(without OpenCV)?\nInput "1" to select sound version.\nInput "2" to select Test version(without OpenCV).')
if command_select == '1' or command_select == '2':
break
else:
continue
else:
print('Cannot find the programe for this robot, you need to setup the programe first.')
if command_select == '1':
try:
try:
os.system('sudo rm -rf //home/pi/.config/autostart')
except:
pass
os.system('sudo mkdir //home/pi/.config/autostart')
os.system('sudo touch //home/pi/.config/autostart/car.desktop')
with open("//home/pi/.config/autostart/car.desktop",'w') as file_to_write:
file_to_write.write("[Desktop Entry]\n Name=Car\n Comment=Car\n Exec=sudo python3 %sserver.py\n Icon=false\n Terminal=false\n MutipleArgs=false\n Type=Application\n Catagories=Application;Development;\n StartupNotify=true"%path_get)
print('The sound version will start when boot')
except:
pass
elif command_select == '2':
try:
try:
os.system('sudo rm -rf //home/pi/.config/autostart')
except:
pass
os.system('sudo mkdir //home/pi/.config/autostart')
os.system('sudo touch //home/pi/.config/autostart/car.desktop')
with open("//home/pi/.config/autostart/car.desktop",'w') as file_to_write:
file_to_write.write("[Desktop Entry]\n Name=Car\n Comment=Car\n Exec=sudo python3 %sserverTest.py\n Icon=false\n Terminal=false\n MutipleArgs=false\n Type=Application\n Catagories=Application;Development;\n StartupNotify=true"%path_get)
print('The Test version(without OpenCV) will start when boot')
except:
pass
#path_get=str(path_get)
#print(path_get[:-15])