users.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 import subprocess
00004 import threading
00005 import time
00006 import roslib
00007 
00008 class Users(roslib.message.Message):
00009   __slots__ = ('users',)
00010   def __init__(self, users):
00011     self.users = users
00012 
00013 class UsersThread(threading.Thread):
00014   def __init__(self):
00015     threading.Thread.__init__(self)
00016 
00017     self.callback = None
00018 
00019   def setCallback(self, callback):
00020     self.callback = callback
00021 
00022   def getUsers(self):
00023     p = subprocess.Popen(['users'], stdout=subprocess.PIPE)
00024     line = p.stdout.readline().strip()
00025     parts = line.split()
00026     users = {}
00027     map(users.__setitem__, parts, [])
00028     users = users.keys()
00029     users.sort()
00030     users = tuple(users)
00031 
00032     return users
00033 
00034   def run(self):
00035     lastusers = ()
00036     while 1:
00037       try:
00038         users = self.getUsers()
00039         if users != lastusers:
00040           lastusers = users
00041           self.callback(Users(users))
00042       except:
00043         pass
00044       time.sleep(3)
00045 
00046 


rosweb
Author(s): Scott Hassan, Rob Wheeler, Nate Koenig
autogenerated on Wed Apr 23 2014 10:35:54