6 import roslib; roslib.load_manifest(PKG)
15 from std_msgs.msg
import String
16 from std_srvs.srv
import Empty,EmptyResponse
18 from optparse
import OptionParser
19 from webui
import config
26 active_user_file = config.ACTIVE_USER_FILE
28 INACTIVITY_LOGOUT = 120
34 user_file = open(active_user_file,
"r") 35 active_user = user_file.read().strip() 37 mod_time = os.stat(active_user_file).st_mtime 40 return active_user, mod_time
43 while not rospy.is_shutdown():
48 rospy.logdebug(
"got user presence: %s" % msg.data)
53 rospy.loginfo(
"removing active user")
55 if config.get_robot_type().startswith(
"texas"):
56 if os.path.exists(config.VALID_USER_COOKIE_FILE):
57 cookie = open(config.VALID_USER_COOKIE_FILE).read()
59 req = urllib2.Request(config.gLobby +
"/lobby/lobby/disconnect.py?robot_name=" + config.get_robot_name())
60 req.headers[
'Cookie'] = cookie
63 response = urllib2.urlopen(req)
65 rospy.logwarn(
"error contacting lobby: %s" % e)
67 os.remove(config.VALID_USER_COOKIE_FILE)
69 if os.path.exists(active_user_file):
70 os.remove(active_user_file)
84 for user
in users.keys():
85 last_ping = users[user]
86 if user == active_user:
88 last_ping = max(last_ping, mod_time)
89 rospy.logdebug(
"active user %s being considered; now: %f, last_ping: %f, mod_time: %f" % (user, time.time(), last_ping, mod_time))
90 if time.time() - last_ping < INACTIVITY_LOGOUT:
91 online_users.append(user)
93 if user == active_user:
100 out.data =
"%s:%s" % (
','.join(online_users), active_user)
101 if active_user
and online_users != []:
102 publisher.publish(out)
103 rospy.logdebug(
"publishing online users: %s" % out)
105 if __name__ ==
'__main__':
107 rospy.init_node(NAME, anonymous=
True)
108 publisher = rospy.Publisher(
"users_online", String)
109 subscriber = rospy.Subscriber(
"presence", String, callback)
111 except KeyboardInterrupt, e: