#!/usr/bin/env python
#
# $Id: wcc_status.py,v 1.3 2001/11/03 11:05:22 doughellmann Exp $
#
# Copyright 2001 Doug Hellmann.
#
#
# All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose and without fee is hereby
# granted, provided that the above copyright notice appear in all
# copies and that both that copyright notice and this permission
# notice appear in supporting documentation, and that the name of Doug
# Hellmann not be used in advertising or publicity pertaining to
# distribution of the software without specific, written prior
# permission.
#
# DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
# NO EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
"""Class to get status information from a WIMD connection.
"""
__rcs_info__ = {
#
# Creation Information
#
'module_name' : '$RCSfile: wcc_status.py,v $',
'rcs_id' : '$Id: wcc_status.py,v 1.3 2001/11/03 11:05:22 doughellmann Exp $',
'creator' : 'Doug Hellmann <doug@hellfly.net>',
'project' : 'PmwContribD',
'created' : 'Sun, 01-Apr-2001 13:22:49 EDT',
#
# Current Information
#
'author' : '$Author: doughellmann $',
'version' : '$Revision: 1.3 $',
'date' : '$Date: 2001/11/03 11:05:22 $',
}
#
# Import system modules
#
import string
#
# Import Local modules
#
import Table
import wcc_protocol
#
# Module
#
class WackyStatusDataSource(Table.ColumnDataSource):
def __init__(self, statusSource, columnNum):
self._column_num = columnNum
self._status_source = statusSource
Table.ColumnDataSource.__init__(self)
self.data = self._status_source
return
def __call__(self, row):
return self(row)
def __getitem__(self, i):
return self.data[i][self._column_num]
class WackyStatusInfo(Table.ColumnDataSource):
"""
Fields:
nickname
uid
dispensation
email
"""
def __init__(self, wackyConnection):
self._wimd = wackyConnection
self.update()
return
def __storeUpdate(self, stat_data, user_info_data):
self._last_stat = stat_data
self._last_user_info = user_info_data
#print 'stat_data=', stat_data
#print 'user_info_data=', user_info_data
emails = map(lambda x: x[2], user_info_data)
try:
self.data = map(lambda x, y: x + (y,), stat_data, emails)
except TypeError:
self.data = []
except IndexError:
print 'Could not update status!!!'
raise
self._name_map = {}
self._uid_map = {}
for rec in self.data:
self._name_map[rec[0]] = rec
self._uid_map[rec[1]] = rec
return
def update(self):
"""
Update the status information for users on the server.
"""
try:
data = self._wimd.stat()
except AttributeError:
pass
else:
try:
user_info = map(lambda x, i=self._wimd.info: i(x[1]), data)
except IndexError:
user_info = ()
self.__storeUpdate(data, user_info)
return
def setUserStatus(self, uid, status):
#print 'Set the status of %s to %s' % (uid, status)
new_user_info = self._last_user_info
new_stat = []
for stat_record in self._last_stat:
if stat_record[1] == uid:
stat_record = ( stat_record[0], stat_record[1], status )
new_stat.append(stat_record)
self.__storeUpdate(new_stat, new_user_info)
return
def infoFromName(self, name):
return self._name_map[name]
def uidFromName(self, name):
try:
rec = self.infoFromName(name)
except KeyError:
return None
return rec[1]
def nameFromUid(self, uid):
uid = str(uid)
try:
rec = self._uid_map[uid]
except KeyError:
return None
return rec[0]
def columns(self, table):
"""
Given a table widget, add columns for the status
information managed by the WackyStatusInfo.
"""
if not self.data:
return
for colnum, title, width, alignment in (
(0, 'User', 100, 'w'),
(1, 'UID', 50, 'e'),
(2, 'Status', 100, 'e'),
):
table.addcolumn( Table.Column(
title=title,
datasource=WackyStatusDataSource(self, colnum),
width=width,
rowheight=15,
cellalignment=alignment,
))
return
|