Browse Source

dealt with printing to a pipe

TODO: make it work properly where users are logged in > 10 times
import/heads/master
Cian Brennan 11 years ago
parent
commit
8bcbfa653f
1 changed files with 38 additions and 26 deletions
  1. +38
    -26
      rbusers.py

+ 38
- 26
rbusers.py View File

@@ -1,24 +1,34 @@
#!/usr/bin/python
import utmp
import sys
import fcntl
import termios
import struct
import os
import pwd
import os
import sys
import curses
users = utmp.UtmpRecord()
logged_users = {}
default_colour = '\033[;0m'
white_text_escape = '\033[;37m'
white_back_escape = '\033[;47m'
red_back_escape = '\033[;41m'
cyan_back_escape = '\033[;46m'
green_back_escape = '\033[;42m'
magenta_back_escape = '\033[;45m'
yellow_back_escape = '\033[;43m'
groups = { 100 : '\033[;31m', 107 : '\033[;36m', \
108 : '\033[;32m', 102 : '\033[;33m', 101 : '\033[;35m' }
title_message = '\033[;31mTotal \033[;0mNumber \033[;33mof \033[;34mUsers \033[;35monline\033[;0m:'
if sys.stdout.encoding is not None :
default_colour = '\033[;0m'
white_text_escape = '\033[;37m'
white_back_escape = '\033[;47m'
red_back_escape = '\033[;41m'
cyan_back_escape = '\033[;46m'
green_back_escape = '\033[;42m'
magenta_back_escape = '\033[;45m'
yellow_back_escape = '\033[;43m'
groups = { 100 : '\033[;31m', 107 : '\033[;36m', \
108 : '\033[;32m', 102 : '\033[;33m', 101 : '\033[;35m' }
title_message = '\033[;31mTotal \033[;0mNumber \033[;33mof \033[;34mUsers \033[;35monline\033[;0m:'
else :
default_colour = ''
white_text_escape = ''
white_back_escape = ''
red_back_escape = ''
cyan_back_escape = ''
green_back_escape = ''
magenta_back_escape = ''
yellow_back_escape = ''
groups = { 100 : '', 107 : '', 108 : '', 102 : '', 101 : '' }
title_message = 'Total Number of Users Online:'
for user in users :
n = user.ut_user
try :
@@ -34,14 +44,14 @@ friends = [ i.rstrip() for i in friends_file.readlines() ]
#http://old.nabble.com/Unable-to-see-os.environ-%27COLUMNS%27--td19487200.html
print '%s%s%s' % (' ' \
, title_message, len(logged_users) )
print '%s%s%s%s%s%s%s' % ( ' ',\
white_back_escape, ' \033[;0m friends ', \
red_back_escape, ' \033[;0m committee ',\
cyan_back_escape, ' \033[;0m associate' )
print '%s%s%s%s%s%s%s' % ( ' ', \
magenta_back_escape, ' \033[;0m society ',\
yellow_back_escape, ' \033[;0m club ',\
green_back_escape, ' \033[;0m guest' )
print '%s%s%s%s%s%s%s%s%s%s%s%s%s' % ( ' ',\
white_back_escape, ' ', default_colour, ' friends ', \
red_back_escape, ' ', default_colour, ' committee ',\
cyan_back_escape, ' ', default_colour, ' associate' )
print '%s%s%s%s%s%s%s%s%s%s%s%s%s' % ( ' ', \
magenta_back_escape, ' ', default_colour, ' society ',\
yellow_back_escape, ' ', default_colour, ' club ',\
green_back_escape, ' ', default_colour, ' guest' )
print
iter = 0
print ' ',
@@ -53,9 +63,11 @@ for user in logged_users.keys() :
else :
try :
group = pwd.getpwnam(user)[3]
print ' %s%s (%d)' % ( groups[group], user.ljust(8), logged_users[user] ),
print ' %s%s (%d)' % ( groups[group], user.ljust(8),\
logged_users[user] ),
except KeyError:
print ' %s%s (%d)' % ( default_colour, user.ljust(8), logged_users[user] ),
print ' %s%s (%d)' % ( default_colour, user.ljust(8),\
logged_users[user] ),
if iter >= 5 :
iter = 0
print


Loading…
Cancel
Save