From 131f6410d457fe079b7dd723057e9b3416ba8b1e Mon Sep 17 00:00:00 2001 From: Greg Taylor Date: Sat, 14 Jun 2008 04:18:20 +0000 Subject: [PATCH] Fix some formatting affected by the space conversion. IMPORTANT: Channel list attributes are now stored via Django's bundled version of simplejson instead of cPickle/pickle. Pickle isn't unicode-capable in 2.5 and lower, plus JSON is going to be a lot more accessible for web-stuff. --- commands/comsys.py | 6 +++--- commands/general.py | 4 ++-- commands/info.py | 12 ++++++------ functions_comsys.py | 11 ++++++----- gameconf.py | 2 +- session.py | 8 ++++---- 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/commands/comsys.py b/commands/comsys.py index c7ea03769b..60e3513b67 100644 --- a/commands/comsys.py +++ b/commands/comsys.py @@ -95,7 +95,7 @@ def cmd_comlist(cdat): """ session = cdat['session'] - session.msg("Alias Channel Status") + session.msg("Alias Channel Status") for chan in session.channels_subscribed: if session.channels_subscribed[chan][1]: chan_on = "On" @@ -131,9 +131,9 @@ def cmd_clist(cdat): Lists all available channels on the game. """ session = cdat['session'] - session.msg("** Channel Owner Description") + session.msg("** Channel Owner Description") for chan in functions_comsys.get_all_channels(): - session.msg("%s%s %-13.13s %-15.15s %-45.45s" % + session.msg("%s%s %-13.13s %-15.15s %-45.45s" % ('-', '-', chan.get_name(), chan.get_owner().get_name(), 'No Description')) session.msg("-- End of Channel List --") diff --git a/commands/general.py b/commands/general.py index d3fb7258cd..8465d2340e 100644 --- a/commands/general.py +++ b/commands/general.py @@ -415,9 +415,9 @@ def cmd_who(cdat): # Only those with the see_session_data or superuser status can see # session details. if show_session_data: - retval = "Player Name On For Idle Room Cmds Host\n\r" + retval = "Player Name On For Idle Room Cmds Host\n\r" else: - retval = "Player Name On For Idle\n\r" + retval = "Player Name On For Idle\n\r" for player in session_list: if not player.logged_in: diff --git a/commands/info.py b/commands/info.py index d02d434d04..85e9897fa4 100644 --- a/commands/info.py +++ b/commands/info.py @@ -27,12 +27,12 @@ def cmd_list(cdat): loadvg = os.getloadavg() psize = resource.getpagesize() rusage = resource.getrusage(resource.RUSAGE_SELF) - session.msg("Process ID: %10d %10d bytes per page" % (os.getpid(), psize)) - session.msg("Time used: %10d user %10d sys" % (rusage[0],rusage[1])) - session.msg("Integral mem:%10d shared %10d private%10d stack" % (rusage[3], rusage[4], rusage[5])) - session.msg("Max res mem: %10d pages %10d bytes" % (rusage[2],rusage[2] * psize)) - session.msg("Page faults: %10d hard %10d soft %10d swapouts" % (rusage[7], rusage[6], rusage[8])) - session.msg("Disk I/O: %10d reads %10d writes" % (rusage[9], rusage[10])) + session.msg("Process ID: %10d %10d bytes per page" % (os.getpid(), psize)) + session.msg("Time used: %10d user %10d sys" % (rusage[0],rusage[1])) + session.msg("Integral mem:%10d shared %10d private%10d stack" % (rusage[3], rusage[4], rusage[5])) + session.msg("Max res mem: %10d pages %10d bytes" % (rusage[2],rusage[2] * psize)) + session.msg("Page faults: %10d hard %10d soft %10d swapouts" % (rusage[7], rusage[6], rusage[8])) + session.msg("Disk I/O: %10d reads %10d writes" % (rusage[9], rusage[10])) session.msg("Network I/O: %10d in %10d out" % (rusage[12], rusage[11])) session.msg("Context swi: %10d vol %10d forced %10d sigs" % (rusage[14], rusage[15], rusage[13])) else: diff --git a/functions_comsys.py b/functions_comsys.py index 8465844d5d..3f78344d17 100644 --- a/functions_comsys.py +++ b/functions_comsys.py @@ -1,6 +1,7 @@ -import cPickle as pickle import time, datetime +from django.utils import simplejson + from apps.objects.models import CommChannel, CommChannelMessage import session_mgr import ansi @@ -125,7 +126,7 @@ def plr_set_channel_listening(session, alias, listening): listening: (bool) A True or False value to determine listening status. """ plr_get_cdict(session).get(alias)[1] = listening - plr_pickle_channels(session) + plr_jsondump_channels(session) def plr_set_channel(session, alias, cname, listening): """ @@ -138,15 +139,15 @@ def plr_set_channel(session, alias, cname, listening): listening: (bool) A True or False value to determine listening status. """ plr_get_cdict(session)[alias] = [cname, listening] - plr_pickle_channels(session) + plr_jsondump_channels(session) -def plr_pickle_channels(session): +def plr_jsondump_channels(session): """ Save the player's channel list to the CHANLIST attribute. session: (SessionProtocol) A reference to the player session. """ - session.get_pobject().set_attribute("CHANLIST", pickle.dumps(plr_get_cdict(session))) + session.get_pobject().set_attribute("CHANLIST", simplejson.dumps(plr_get_cdict(session))) def plr_del_channel(session, alias): """ diff --git a/gameconf.py b/gameconf.py index b6aced9a93..b19cf18d33 100644 --- a/gameconf.py +++ b/gameconf.py @@ -1,7 +1,7 @@ import os from traceback import format_exc -from apps.config.models import ConfigValue, ConnectScreen +from apps.config.models import ConfigValue import functions_general """ Handle the setting/retrieving of server config directives. diff --git a/session.py b/session.py index 34ff1d2ffa..ca080b4dbb 100755 --- a/session.py +++ b/session.py @@ -1,6 +1,6 @@ import time, sys from datetime import datetime -import cPickle as pickle +from django.utils import simplejson from twisted.conch.telnet import StatefulTelnetProtocol @@ -68,11 +68,11 @@ class SessionProtocol(StatefulTelnetProtocol): def load_user_channels(self): """ - Un-pickle a user's channel list from their CHANLIST attribute. + Parse JSON dict of a user's channel list from their CHANLIST attribute. """ chan_list = self.get_pobject().get_attribute_value("CHANLIST") if chan_list: - self.channels_subscribed = pickle.loads(chan_list) + self.channels_subscribed = simplejson.loads(chan_list) def lineReceived(self, data): """ @@ -159,7 +159,7 @@ class SessionProtocol(StatefulTelnetProtocol): pobject.set_attribute("Last", "%s" % (time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()),)) pobject.set_attribute("Lastsite", "%s" % (self.address[0],)) - # Load their channel selection from a pickled attribute. + # Load their channel selection from a JSON-encoded string attribute. self.load_user_channels() def msg(self, message):