prettytable to EvTable and whitespace edits

This commit is contained in:
BlauFeuer 2017-02-21 17:44:25 -05:00 committed by Griatch
parent bd7388c03d
commit 541d54ecc1

View file

@ -23,7 +23,7 @@ from builtins import range
import time import time
from django.conf import settings from django.conf import settings
from evennia.server.sessionhandler import SESSIONS from evennia.server.sessionhandler import SESSIONS
from evennia.utils import utils, create, search, prettytable, evtable from evennia.utils import utils, create, search, evtable
COMMAND_DEFAULT_CLASS = utils.class_from_module(settings.COMMAND_DEFAULT_CLASS) COMMAND_DEFAULT_CLASS = utils.class_from_module(settings.COMMAND_DEFAULT_CLASS)
@ -356,20 +356,18 @@ class CmdSessions(COMMAND_DEFAULT_CLASS):
"""Implement function""" """Implement function"""
player = self.player player = self.player
sessions = player.sessions.all() sessions = player.sessions.all()
table = evtable.EvTable("|wsessid",
table = prettytable.PrettyTable(["|wsessid", "|wprotocol",
"|wprotocol", "|whost",
"|whost", "|wpuppet/character",
"|wpuppet/character", "|wlocation")
"|wlocation"])
for sess in sorted(sessions, key=lambda x: x.sessid): for sess in sorted(sessions, key=lambda x: x.sessid):
char = player.get_puppet(sess) char = player.get_puppet(sess)
table.add_row([str(sess.sessid), str(sess.protocol_key), table.add_row(str(sess.sessid), str(sess.protocol_key),
type(sess.address) == tuple and sess.address[0] or sess.address, type(sess.address) == tuple and sess.address[0] or sess.address,
char and str(char) or "None", char and str(char) or "None",
char and str(char.location) or "N/A"]) char and str(char.location) or "N/A")
string = "|wYour current session(s):|n\n%s" % table self.msg("|wYour current session(s):|n\n%s" % table)
self.msg(string)
class CmdWho(COMMAND_DEFAULT_CLASS): class CmdWho(COMMAND_DEFAULT_CLASS):
@ -409,14 +407,14 @@ class CmdWho(COMMAND_DEFAULT_CLASS):
nplayers = (SESSIONS.player_count()) nplayers = (SESSIONS.player_count())
if show_session_data: if show_session_data:
# privileged info # privileged info
table = prettytable.PrettyTable(["|wPlayer Name", table = evtable.EvTable("|wPlayer Name",
"|wOn for", "|wOn for",
"|wIdle", "|wIdle",
"|wPuppeting", "|wPuppeting",
"|wRoom", "|wRoom",
"|wCmds", "|wCmds",
"|wProtocol", "|wProtocol",
"|wHost"]) "|wHost")
for session in session_list: for session in session_list:
if not session.logged_in: if not session.logged_in:
continue continue
@ -425,31 +423,29 @@ class CmdWho(COMMAND_DEFAULT_CLASS):
player = session.get_player() player = session.get_player()
puppet = session.get_puppet() puppet = session.get_puppet()
location = puppet.location.key if puppet and puppet.location else "None" location = puppet.location.key if puppet and puppet.location else "None"
table.add_row([utils.crop(player.name, width=25), table.add_row(utils.crop(player.name, width=25),
utils.time_format(delta_conn, 0), utils.time_format(delta_conn, 0),
utils.time_format(delta_cmd, 1), utils.time_format(delta_cmd, 1),
utils.crop(puppet.key if puppet else "None", width=25), utils.crop(puppet.key if puppet else "None", width=25),
utils.crop(location, width=25), utils.crop(location, width=25),
session.cmd_total, session.cmd_total,
session.protocol_key, session.protocol_key,
isinstance(session.address, tuple) and session.address[0] or session.address]) isinstance(session.address, tuple) and session.address[0] or session.address)
else: else:
# unprivileged # unprivileged
table = prettytable.PrettyTable(["|wPlayer name", "|wOn for", "|wIdle"]) table = evtable.EvTable("|wPlayer name", "|wOn for", "|wIdle")
for session in session_list: for session in session_list:
if not session.logged_in: if not session.logged_in:
continue continue
delta_cmd = time.time() - session.cmd_last_visible delta_cmd = time.time() - session.cmd_last_visible
delta_conn = time.time() - session.conn_time delta_conn = time.time() - session.conn_time
player = session.get_player() player = session.get_player()
table.add_row([utils.crop(player.key, width=25), table.add_row(utils.crop(player.key, width=25),
utils.time_format(delta_conn, 0), utils.time_format(delta_conn, 0),
utils.time_format(delta_cmd, 1)]) utils.time_format(delta_cmd, 1))
is_one = nplayers == 1 is_one = nplayers == 1
string = "|wPlayers:|n\n%s\n%s unique account%s logged in." \ self.msg("|wPlayers:|n\n%s\n%s unique account%s logged in."
% (table, "One" if is_one else nplayers, "" if is_one else "s") % (table, "One" if is_one else nplayers, "" if is_one else "s"))
self.msg(string)
class CmdOption(COMMAND_DEFAULT_CLASS): class CmdOption(COMMAND_DEFAULT_CLASS):
@ -524,7 +520,6 @@ class CmdOption(COMMAND_DEFAULT_CLASS):
changed = "|y*|n" if key in saved_options and flags[key] != saved_options[key] else "" changed = "|y*|n" if key in saved_options and flags[key] != saved_options[key] else ""
row.append("%s%s" % (saved, changed)) row.append("%s%s" % (saved, changed))
table.add_row(*row) table.add_row(*row)
self.msg("|wClient settings (%s):|n\n%s|n" % (self.session.protocol_key, table)) self.msg("|wClient settings (%s):|n\n%s|n" % (self.session.protocol_key, table))
return return
@ -599,10 +594,9 @@ class CmdOption(COMMAND_DEFAULT_CLASS):
for key in optiondict: for key in optiondict:
self.player.attributes.get("_saved_protocol_flags", {}).pop(key, None) self.player.attributes.get("_saved_protocol_flags", {}).pop(key, None)
self.msg("|gCleared saved %s." % key) self.msg("|gCleared saved %s." % key)
self.session.update_flags(**optiondict) self.session.update_flags(**optiondict)
class CmdPassword(COMMAND_DEFAULT_CLASS): class CmdPassword(COMMAND_DEFAULT_CLASS):
""" """
change your password change your password