Added the "raw" switch to examine, to allow for viewing attributes and properties without parsing markup first.
This commit is contained in:
parent
973f606f3f
commit
9c5f662196
5 changed files with 104 additions and 39 deletions
|
|
@ -1416,6 +1416,7 @@ class CmdExamine(ObjManipCommand):
|
||||||
|
|
||||||
Switch:
|
Switch:
|
||||||
player - examine a Player (same as adding *)
|
player - examine a Player (same as adding *)
|
||||||
|
raw - don't parse escape codes for data.
|
||||||
|
|
||||||
The examine command shows detailed game info about an
|
The examine command shows detailed game info about an
|
||||||
object and optionally a specific attribute on it.
|
object and optionally a specific attribute on it.
|
||||||
|
|
@ -1431,11 +1432,19 @@ class CmdExamine(ObjManipCommand):
|
||||||
|
|
||||||
player_mode = False
|
player_mode = False
|
||||||
|
|
||||||
def format_attributes(self, obj, attrname=None, crop=True):
|
def format_attributes(self, obj, attrname=None, crop=True, raw=False):
|
||||||
"""
|
"""
|
||||||
Helper function that returns info about attributes and/or
|
Helper function that returns info about attributes and/or
|
||||||
non-persistent data stored on object
|
non-persistent data stored on object
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
headers = {"persistent":"\n{wPersistent attributes{n:",
|
||||||
|
"nonpersistent":"\n{wNon-persistent attributes{n:"}
|
||||||
|
headers_noansi = {"persistent":"\nPersistent attributes:",
|
||||||
|
"nonpersistent":"\nNon-persistent attributes:"}
|
||||||
|
if raw:
|
||||||
|
headers = headers_noansi
|
||||||
|
|
||||||
if attrname:
|
if attrname:
|
||||||
db_attr = [(attrname, obj.attr(attrname))]
|
db_attr = [(attrname, obj.attr(attrname))]
|
||||||
try:
|
try:
|
||||||
|
|
@ -1443,7 +1452,7 @@ class CmdExamine(ObjManipCommand):
|
||||||
except Exception:
|
except Exception:
|
||||||
ndb_attr = None
|
ndb_attr = None
|
||||||
else:
|
else:
|
||||||
if player_mode:
|
if self.player_mode:
|
||||||
db_attr = [(attr.key, attr.value) for attr in PlayerAttribute.objects.filter(db_obj=obj)]
|
db_attr = [(attr.key, attr.value) for attr in PlayerAttribute.objects.filter(db_obj=obj)]
|
||||||
else:
|
else:
|
||||||
db_attr = [(attr.key, attr.value) for attr in ObjAttribute.objects.filter(db_obj=obj)]
|
db_attr = [(attr.key, attr.value) for attr in ObjAttribute.objects.filter(db_obj=obj)]
|
||||||
|
|
@ -1454,60 +1463,91 @@ class CmdExamine(ObjManipCommand):
|
||||||
string = ""
|
string = ""
|
||||||
if db_attr and db_attr[0]:
|
if db_attr and db_attr[0]:
|
||||||
#self.caller.msg(db_attr)
|
#self.caller.msg(db_attr)
|
||||||
string += "\n{wPersistent attributes{n:"
|
string += headers["persistent"]
|
||||||
for attr, value in db_attr:
|
for attr, value in db_attr:
|
||||||
if crop:
|
if crop:
|
||||||
value = utils.crop(value)
|
value = utils.crop(value)
|
||||||
string += "\n %s = %s" % (attr, value)
|
string += "\n %s = %s" % (attr, value)
|
||||||
if ndb_attr and ndb_attr[0]:
|
if ndb_attr and ndb_attr[0]:
|
||||||
string += "\n{wNon-persistent attributes{n:"
|
string += headers["nonpersistent"]
|
||||||
for attr, value in ndb_attr:
|
for attr, value in ndb_attr:
|
||||||
if crop:
|
if crop:
|
||||||
value = utils.crop(value)
|
value = utils.crop(value)
|
||||||
string += "\n %s = %s" % (attr, value)
|
string += "\n %s = %s" % (attr, value)
|
||||||
return string
|
return string
|
||||||
|
|
||||||
def format_output(self, obj):
|
def format_output(self, obj, raw=False):
|
||||||
"""
|
"""
|
||||||
Helper function that creates a nice report about an object.
|
Helper function that creates a nice report about an object.
|
||||||
|
|
||||||
returns a string.
|
returns a string.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
headers = {"name":"\n{wName/key{n: {c%s{n (%s)",
|
||||||
|
"aliases":"\n{wAliases{n: %s",
|
||||||
|
"player":"\n{wPlayer{n: {c%s{n",
|
||||||
|
"playerperms":"\n{wPlayer Perms{n: %s",
|
||||||
|
"typeclass":"\n{wTypeclass{n: %s (%s)",
|
||||||
|
"location":"\n{wLocation{n: %s",
|
||||||
|
"destination":"\n{wDestination{n: %s",
|
||||||
|
"perms":"\n{wPermissions{n: %s",
|
||||||
|
"locks":"\n{wLocks{n:",
|
||||||
|
"cmdset":"\n{wCurrent Cmdset (including permission checks){n:\n %s",
|
||||||
|
"scripts":"\n{wScripts{n:\n %s",
|
||||||
|
"exits":"\n{wExits{n: ",
|
||||||
|
"characters":"\n{wCharacters{n: ",
|
||||||
|
"contents":"\n{wContents{n: "}
|
||||||
|
headers_noansi = {"name":"\nName/key: %s (%s)",
|
||||||
|
"aliases":"\nAliases: %s",
|
||||||
|
"player":"\nPlayer: %s",
|
||||||
|
"playerperms":"\nPlayer Perms: %s",
|
||||||
|
"typeclass":"\nTypeclass: %s (%s)",
|
||||||
|
"location":"\nLocation: %s",
|
||||||
|
"destination":"\nDestination: %s",
|
||||||
|
"perms":"\nPermissions: %s",
|
||||||
|
"locks":"\nLocks:",
|
||||||
|
"cmdset":"\nCurrent Cmdset (including permission checks):\n %s",
|
||||||
|
"scripts":"\nScripts:\n %s",
|
||||||
|
"exits":"\nExits: ",
|
||||||
|
"characters":"\nCharacters: ",
|
||||||
|
"contents":"\nContents: "}
|
||||||
|
if raw:
|
||||||
|
headers = headers_noansi
|
||||||
|
|
||||||
if hasattr(obj, "has_player") and obj.has_player:
|
if hasattr(obj, "has_player") and obj.has_player:
|
||||||
string = "\n{wName/key{n: {c%s{n (%s)" % (obj.name, obj.dbref)
|
string = headers["name"] % (obj.name, obj.dbref)
|
||||||
else:
|
else:
|
||||||
string = "\n{wName/key{n: {C%s{n (%s)" % (obj.name, obj.dbref)
|
string = headers["name"] % (obj.name, obj.dbref)
|
||||||
if hasattr(obj, "aliases") and obj.aliases:
|
if hasattr(obj, "aliases") and obj.aliases:
|
||||||
string += "\n{wAliases{n: %s" % (", ".join(obj.aliases))
|
string += headers["aliases"] % (", ".join(obj.aliases))
|
||||||
if hasattr(obj, "has_player") and obj.has_player:
|
if hasattr(obj, "has_player") and obj.has_player:
|
||||||
string += "\n{wPlayer{n: {c%s{n" % obj.player.name
|
string += headers["player"] % obj.player.name
|
||||||
perms = obj.player.permissions
|
perms = obj.player.permissions
|
||||||
if obj.player.is_superuser:
|
if obj.player.is_superuser:
|
||||||
perms = ["<Superuser>"]
|
perms = ["<Superuser>"]
|
||||||
elif not perms:
|
elif not perms:
|
||||||
perms = ["<None>"]
|
perms = ["<None>"]
|
||||||
string += "\n{wPlayer Perms{n: %s" % (", ".join(perms))
|
string += headers["perms"] % (", ".join(perms))
|
||||||
string += "\n{wTypeclass{n: %s (%s)" % (obj.typeclass, obj.typeclass_path)
|
string += headers["typeclass"] % (obj.typeclass, obj.typeclass_path)
|
||||||
|
|
||||||
if hasattr(obj, "location"):
|
if hasattr(obj, "location"):
|
||||||
string += "\n{wLocation{n: %s" % obj.location
|
string += headers["location"] % obj.location
|
||||||
if hasattr(obj, "destination") and obj.destination:
|
if hasattr(obj, "destination") and obj.destination:
|
||||||
string += "\n{wDestination{n: %s" % obj.destination
|
string += headers["destination"] % obj.destination
|
||||||
perms = obj.permissions
|
perms = obj.permissions
|
||||||
if perms:
|
if perms:
|
||||||
string += "\n{wPermissions{n: %s" % (", ".join(perms))
|
string += headers["perms"] % (", ".join(perms))
|
||||||
locks = str(obj.locks)
|
locks = str(obj.locks)
|
||||||
if locks:
|
if locks:
|
||||||
string += "\n{wLocks{n:" + utils.fill("; ".join([lock for lock in locks.split(';')]), indent=6)
|
string += headers["locks"] + utils.fill("; ".join([lock for lock in locks.split(';')]), indent=6)
|
||||||
|
|
||||||
if not (len(obj.cmdset.all()) == 1 and obj.cmdset.current.key == "Empty"):
|
if not (len(obj.cmdset.all()) == 1 and obj.cmdset.current.key == "Empty"):
|
||||||
cmdsetstr = "\n".join([utils.fill(cmdset, indent=2) for cmdset in str(obj.cmdset).split("\n")])
|
cmdsetstr = "\n".join([utils.fill(cmdset, indent=2) for cmdset in str(obj.cmdset).split("\n")])
|
||||||
string += "\n{wCurrent Cmdset (including permission checks){n:\n %s" % cmdsetstr
|
string += headers["cmdset"] % cmdsetstr
|
||||||
if hasattr(obj, "scripts") and hasattr(obj.scripts, "all") and obj.scripts.all():
|
if hasattr(obj, "scripts") and hasattr(obj.scripts, "all") and obj.scripts.all():
|
||||||
string += "\n{wScripts{n:\n %s" % obj.scripts
|
string += headers["scripts"] % obj.scripts
|
||||||
# add the attributes
|
# add the attributes
|
||||||
string += self.format_attributes(obj)
|
string += self.format_attributes(obj, raw=raw)
|
||||||
# add the contents
|
# add the contents
|
||||||
exits = []
|
exits = []
|
||||||
pobjs = []
|
pobjs = []
|
||||||
|
|
@ -1521,11 +1561,11 @@ class CmdExamine(ObjManipCommand):
|
||||||
else:
|
else:
|
||||||
things.append(content)
|
things.append(content)
|
||||||
if exits:
|
if exits:
|
||||||
string += "\n{wExits{n: " + ", ".join([exit.name for exit in exits])
|
string += headers["exits"] + ", ".join([exit.name for exit in exits])
|
||||||
if pobjs:
|
if pobjs:
|
||||||
string += "\n{wCharacters{n: " + ", ".join(["{c%s{n" % pobj.name for pobj in pobjs])
|
string += headers["characters"] + ", ".join(["{c%s{n" % pobj.name for pobj in pobjs])
|
||||||
if things:
|
if things:
|
||||||
string += "\n{wContents{n: " + ", ".join([cont.name for cont in obj.contents
|
string += headers["contents"] + ", ".join([cont.name for cont in obj.contents
|
||||||
if cont not in exits and cont not in pobjs])
|
if cont not in exits and cont not in pobjs])
|
||||||
#output info
|
#output info
|
||||||
return "-"*78 + '\n' + string.strip() + "\n" + '-'*78
|
return "-"*78 + '\n' + string.strip() + "\n" + '-'*78
|
||||||
|
|
@ -1534,6 +1574,10 @@ class CmdExamine(ObjManipCommand):
|
||||||
"Process command"
|
"Process command"
|
||||||
caller = self.caller
|
caller = self.caller
|
||||||
|
|
||||||
|
msgdata = None
|
||||||
|
if "raw" in self.switches:
|
||||||
|
msgdata = {"raw":True}
|
||||||
|
|
||||||
if not self.args:
|
if not self.args:
|
||||||
# If no arguments are provided, examine the invoker's location.
|
# If no arguments are provided, examine the invoker's location.
|
||||||
obj = caller.location
|
obj = caller.location
|
||||||
|
|
@ -1541,8 +1585,8 @@ class CmdExamine(ObjManipCommand):
|
||||||
#If we don't have special info access, just look at the object instead.
|
#If we don't have special info access, just look at the object instead.
|
||||||
caller.execute_cmd('look %s' % obj.name)
|
caller.execute_cmd('look %s' % obj.name)
|
||||||
return
|
return
|
||||||
string = self.format_output(obj)
|
string = self.format_output(obj, raw=msgdata)
|
||||||
caller.msg(string.strip())
|
caller.msg(string.strip(), data=msgdata)
|
||||||
return
|
return
|
||||||
|
|
||||||
# we have given a specific target object
|
# we have given a specific target object
|
||||||
|
|
@ -1552,10 +1596,10 @@ class CmdExamine(ObjManipCommand):
|
||||||
obj_name = objdef['name']
|
obj_name = objdef['name']
|
||||||
obj_attrs = objdef['attrs']
|
obj_attrs = objdef['attrs']
|
||||||
|
|
||||||
global player_mode
|
|
||||||
player_mode = "player" in self.switches or obj_name.startswith('*')
|
|
||||||
|
|
||||||
obj = caller.search(obj_name, player=player_mode)
|
self.player_mode = "player" in self.switches or obj_name.startswith('*')
|
||||||
|
|
||||||
|
obj = caller.search(obj_name, player=self.player_mode)
|
||||||
if not obj:
|
if not obj:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
@ -1567,10 +1611,10 @@ class CmdExamine(ObjManipCommand):
|
||||||
if obj_attrs:
|
if obj_attrs:
|
||||||
for attrname in obj_attrs:
|
for attrname in obj_attrs:
|
||||||
# we are only interested in specific attributes
|
# we are only interested in specific attributes
|
||||||
string += self.format_attributes(obj, attrname, crop=False)
|
string += self.format_attributes(obj, attrname, crop=False, raw=msgdata)
|
||||||
else:
|
else:
|
||||||
string += self.format_output(obj)
|
string += self.format_output(obj, raw=msgdata)
|
||||||
caller.msg(string.strip())
|
caller.msg(string.strip(), data=msgdata)
|
||||||
|
|
||||||
|
|
||||||
class CmdFind(MuxCommand):
|
class CmdFind(MuxCommand):
|
||||||
|
|
|
||||||
|
|
@ -573,7 +573,7 @@ class ObjectDB(TypedObject):
|
||||||
# we use a different __getattribute__ to avoid recursive loops.
|
# we use a different __getattribute__ to avoid recursive loops.
|
||||||
|
|
||||||
if object.__getattribute__(self, 'player'):
|
if object.__getattribute__(self, 'player'):
|
||||||
object.__getattribute__(self, 'player').msg(message, from_obj, data)
|
object.__getattribute__(self, 'player').msg(message, from_obj=from_obj, data=data)
|
||||||
|
|
||||||
def emit_to(self, message, from_obj=None, data=None):
|
def emit_to(self, message, from_obj=None, data=None):
|
||||||
"Deprecated. Alias for msg"
|
"Deprecated. Alias for msg"
|
||||||
|
|
|
||||||
|
|
@ -346,4 +346,4 @@ class Session(SessionBase):
|
||||||
self.session_disconnect()
|
self.session_disconnect()
|
||||||
def msg(self, string='', data=None):
|
def msg(self, string='', data=None):
|
||||||
"alias for at_data_out"
|
"alias for at_data_out"
|
||||||
self.at_data_out(string, data)
|
self.at_data_out(string, data=data)
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,17 @@ class TelnetProtocol(StatefulTelnetProtocol, session.Session):
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.lineSend(str(e))
|
self.lineSend(str(e))
|
||||||
return
|
return
|
||||||
self.lineSend(ansi.parse_ansi(string, strip_ansi=not self.telnet_markup))
|
nomarkup = not self.telnet_markup
|
||||||
|
raw = False
|
||||||
|
if type(data) == dict:
|
||||||
|
# check if we want escape codes to go through unparsed.
|
||||||
|
raw = data.get("raw", self.telnet_markup)
|
||||||
|
# check if we want to remove all markup
|
||||||
|
nomarkup = data.get("nomarkup", not self.telnet_markup)
|
||||||
|
if raw:
|
||||||
|
self.lineSend(string)
|
||||||
|
else:
|
||||||
|
self.lineSend(ansi.parse_ansi(string, strip_ansi=nomarkup))
|
||||||
|
|
||||||
def at_data_in(self, string, data=None):
|
def at_data_in(self, string, data=None):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ from django.utils import simplejson
|
||||||
from django.utils.functional import Promise
|
from django.utils.functional import Promise
|
||||||
from django.utils.encoding import force_unicode
|
from django.utils.encoding import force_unicode
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from src.utils import utils, logger
|
from src.utils import utils, logger, ansi
|
||||||
from src.utils.text2html import parse_html
|
from src.utils.text2html import parse_html
|
||||||
from src.server import session
|
from src.server import session
|
||||||
from src.server.sessionhandler import SESSIONS
|
from src.server.sessionhandler import SESSIONS
|
||||||
|
|
@ -223,16 +223,16 @@ class WebClientSession(session.Session):
|
||||||
Show the banner screen.
|
Show the banner screen.
|
||||||
"""
|
"""
|
||||||
# show screen
|
# show screen
|
||||||
|
self.telnet_markup = True
|
||||||
self.execute_cmd('look')
|
self.execute_cmd('look')
|
||||||
|
|
||||||
|
|
||||||
def at_login(self, player):
|
def at_login(self, player):
|
||||||
"""
|
"""
|
||||||
Called after authentication. self.logged_in=True at this point.
|
Called after authentication. self.logged_in=True at this point.
|
||||||
"""
|
"""
|
||||||
if player.has_attribute('telnet_markup'):
|
if player.has_attribute('telnet_markup'):
|
||||||
self.telnet_markup = player.get_attribute("telnet_markup")
|
self.telnet_markup = player.get_attribute("telnet_markup")
|
||||||
else:
|
|
||||||
self.telnet_markup = True
|
|
||||||
|
|
||||||
def at_disconnect(self, reason=None):
|
def at_disconnect(self, reason=None):
|
||||||
"""
|
"""
|
||||||
|
|
@ -260,7 +260,18 @@ class WebClientSession(session.Session):
|
||||||
# string handling is similar to telnet
|
# string handling is similar to telnet
|
||||||
try:
|
try:
|
||||||
string = utils.to_str(string, encoding=self.encoding)
|
string = utils.to_str(string, encoding=self.encoding)
|
||||||
self.client.lineSend(self.suid, parse_html(string))
|
|
||||||
|
nomarkup = not self.telnet_markup
|
||||||
|
raw = False
|
||||||
|
if type(data) == dict:
|
||||||
|
# check if we want escape codes to go through unparsed.
|
||||||
|
raw = data.get("raw", self.telnet_markup)
|
||||||
|
# check if we want to remove all markup
|
||||||
|
nomarkup = data.get("nomarkup", not self.telnet_markup)
|
||||||
|
if raw:
|
||||||
|
self.client.lineSend(self.suid, string)
|
||||||
|
else:
|
||||||
|
self.client.lineSend(self.suid, parse_html(ansi.parse_ansi(string, strip_ansi=nomarkup)))
|
||||||
return
|
return
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
logger.log_trace()
|
logger.log_trace()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue