14 print "Content-type: text/html"    19 ros_distro = 
"ROS_DISTRO"     21 form = cgi.FieldStorage()
    22 message = form.getvalue(
"action", 
"NO_ACTION")
    26     v = popen2.popen4(fun)
    32     run = 
"su applications -c \"" + command + 
"\""    34     child = pexpect.spawn(run)
    35     result = child.expect([
"ssword:", 
"(yes/no)?"])
    36     child.sendline(
"willow")
    38     for i 
in child.readlines():
    44 if (message == 
"GET_STATE"):
    46     active_user = 
"(UNKNOWN)"    49     for i 
in run(
"robot users --no-plist").split(
"\n"):
    50         if (i.find(
"Active User:") != -1):
    51             active_user = i.split(
":")[1].strip()
    52         if (i.find(
"Message:") != -1):
    53             message = i.split(
":")[1].strip()
    54         if (i.find(
"*") != -1):
    55             dead_users = dead_users + i[i.find(
"*") + 1:i.find(
"(")].strip() + 
","    61     if (active_user == 
"applications"):
    63     elif (active_user == 
"" or active_user == 
"None"):
    67         print "USER:", active_user
    69             print "MESSAGE:", message 
    82 elif (message == 
"STOP_ROBOT"):
    83     print "STOPPING_ROBOT"    84     result = 
run_as_robot(
"yes | robot claim -m 'stopping the robot' ; yes | robot stop ; yes | robot release")
    87 elif (message == 
"START_ROBOT"):
    88     print "STARTING_APP_MAN"    89     print run_as_robot(
"yes | robot claim -m 'running applications platform'")
    90     print run_as_robot(
". /opt/ros/" + ros_distro + 
"/setup.bash ; . ~/.bashrc ; export ROS_ENV_LOADER=/opt/ros/" + ros_distro + 
"/env.sh ; nohup roslaunch pr2_app_manager whole_pr2_apps.launch > ~/run.txt &")
    98             s.connect((
'localhost', 11311))
   106     print "REJECT_COMMAND"   107     print "action = STOP_ROBOT,START_ROBOT,GET_STATE" def run_as_robot(command)