6 from subprocess
import *
12 choice = raw_input(
"install setserial yes(y) or none(n) : ")
13 if choice
in [
'y',
'ye',
'yes']:
14 os.system(
'sudo apt-get install setserial')
17 with tempfile.NamedTemporaryFile()
as tf:
20 header =
'#aero_controller\n' 21 upper_string =
'SUBSYSTEM=="tty",ATTRS{idVendor}=="0403",ATTRS{idProduct}=="6001",ATTRS{serial}=="111",MODE="666",SYMLINK+="aero_upper", RUN+="/bin/setserial /dev/aero_upper low_latency"\n' 22 lower_string =
'SUBSYSTEM=="tty",ATTRS{idVendor}=="0403",ATTRS{idProduct}=="6001",ATTRS{serial}=="123",MODE="666",SYMLINK+="aero_lower", RUN+="/bin/setserial /dev/aero_lower low_latency"\n' 24 header_hokuyo =
'#hokuyo urg\n' 25 hokuyo_string =
'SUBSYSTEM=="tty",ATTRS{idVendor}=="15d1",ATTRS{idProduct}=="0000",MODE="666",SYMLINK+="hokuyo"' 27 print(
"Please insert upper USB to PC port")
28 choice = raw_input(
"yes(y) or none(n) : ")
29 if choice
in [
'y',
'yes']:
30 upper = upper_string.split(
',')
34 p1 = subprocess.Popen([
'udevadm',
'info',
'-n',
'/dev/ttyUSB0'], stdout=subprocess.PIPE)
35 p2 = subprocess.Popen([
'grep',
'SERIAL_SHORT'], stdin=p1.stdout, stdout=subprocess.PIPE)
40 out, err = p2.communicate()
41 upper[3] =
"ATTRS{serial}==\"" + out.split(
'=')[1].strip() +
"\"" 44 upper_string = (
','.join(upper))
47 print(
"Please insert lower USB to PC port")
48 choice = raw_input(
"yes(y) or none(n) : ")
49 if choice
in [
'y',
'yes']:
50 lower = lower_string.split(
',')
54 p1 = subprocess.Popen([
'udevadm',
'info',
'-n',
'/dev/ttyUSB0'], stdout=subprocess.PIPE)
55 p2 = subprocess.Popen([
'grep',
'SERIAL_SHORT'], stdin=p1.stdout, stdout=subprocess.PIPE)
60 out, err = p2.communicate()
61 lower[3] =
"ATTRS{serial}==\"" + out.split(
'=')[1].strip() +
"\"" 64 lower_string = (
','.join(lower))
67 print(
"write tempfile")
69 tf.write(upper_string)
70 tf.write(lower_string)
72 tf.write(header_hokuyo)
73 tf.write(hokuyo_string)
76 subprocess.call([
'sudo',
'cp', self.
filename,
'/etc/udev/rules.d/90-aero.rules'])
79 if __name__ ==
"__main__" :