Made examine command more verbose about the cmdset stack and just which cmdsets go into the currently merged set. This meant a change to merged sets where they store their component sets as a variable "merged_from".

This commit is contained in:
Griatch 2014-01-20 22:46:30 +01:00
parent 1cabcae771
commit c321ccb332
5 changed files with 44 additions and 20 deletions

View file

@ -229,11 +229,14 @@ def get_and_merge_cmdsets(caller, session, player, obj,
cmdsets = yield sorted(tempmergers.values(), key=lambda x: x.priority) cmdsets = yield sorted(tempmergers.values(), key=lambda x: x.priority)
# Merge all command sets into one, beginning with the lowest-prio one # Merge all command sets into one, beginning with the lowest-prio one
cmdset = cmdsets.pop(0) cmdset = cmdsets[0]
for merging_cmdset in cmdsets: for merging_cmdset in cmdsets[1:]:
#print "<%s(%s,%s)> onto <%s(%s,%s)>" % (merging_cmdset.key, merging_cmdset.priority, merging_cmdset.mergetype, #print "<%s(%s,%s)> onto <%s(%s,%s)>" % (merging_cmdset.key, merging_cmdset.priority, merging_cmdset.mergetype,
# cmdset.key, cmdset.priority, cmdset.mergetype) # cmdset.key, cmdset.priority, cmdset.mergetype)
cmdset = yield merging_cmdset + cmdset cmdset = yield merging_cmdset + cmdset
# store the full sets for diagnosis
cmdset.merged_from = cmdsets
# cache
_CMDSET_MERGE_CACHE[mergehash] = cmdset _CMDSET_MERGE_CACHE[mergehash] = cmdset
else: else:
cmdset = None cmdset = None

View file

@ -153,6 +153,10 @@ class CmdSet(object):
self.system_commands = [] self.system_commands = []
self.actual_mergetype = self.mergetype self.actual_mergetype = self.mergetype
self.cmdsetobj = cmdsetobj self.cmdsetobj = cmdsetobj
# this is set only on merged sets, in cmdhandler.py, in order to
# track, list and debug mergers correctly.
self.merged_from = []
# initialize system # initialize system
self.at_cmdset_creation() self.at_cmdset_creation()
self._contains_cache = {} self._contains_cache = {}

View file

@ -1663,7 +1663,7 @@ class CmdExamine(ObjManipCommand):
string += "\n{wLocation{n: %s" % obj.location string += "\n{wLocation{n: %s" % obj.location
if obj.location: if obj.location:
string += " (#%s)" % obj.location.id string += " (#%s)" % obj.location.id
if hasattr(obj, "destination"): if hasattr(obj, "destination") and obj.destination:
string += "\n{wDestination{n: %s" % obj.destination string += "\n{wDestination{n: %s" % obj.destination
if obj.destination: if obj.destination:
string += " (#%s)" % obj.destination.id string += " (#%s)" % obj.destination.id
@ -1686,26 +1686,39 @@ class CmdExamine(ObjManipCommand):
string += "\n{wLocks{n:%s" % locks_string string += "\n{wLocks{n:%s" % locks_string
if not (len(obj.cmdset.all()) == 1 and obj.cmdset.current.key == "_EMPTY_CMDSET"): if not (len(obj.cmdset.all()) == 1 and obj.cmdset.current.key == "_EMPTY_CMDSET"):
# list the current cmdsets stored_cmdsets = obj.cmdset.all()
all_cmdsets = (obj.cmdset.all() + stored_cmdsets.sort(key=lambda x: x.priority, reverse=True)
(hasattr(obj, "player") and obj.player and string += "\n{wStored Cmdset(s){n:\n %s" % ("\n ".join("%s [%s] (%s, prio %s)" % \
obj.player and obj.player.cmdset.all() or [])) (cmdset.path, cmdset.key, cmdset.mergetype, cmdset.priority)
for cmdset in stored_cmdsets if cmdset.key != "_EMPTY_CMDSET"))
# this gets all components of the currently merged set
all_cmdsets = [(cmdset.key, cmdset) for cmdset in avail_cmdset.merged_from]
# we always at least try to add player- and session sets since these are ignored
# if we merge on the object level.
if hasattr(obj, "player") and obj.player:
all_cmdsets.extend([(cmdset.key, cmdset) for cmdset in obj.player.cmdset.all()])
if obj.sessid:
all_cmdsets.extend([(cmdset.key, cmdset) for cmdset in obj.player.get_session(obj.sessid).cmdset.all()])
else:
try: try:
# we have to protect this since many objects don't have player/sessions. # we have to protect this since many objects don't have sessions.
all_cmdsets += obj.player.get_session(obj.sessid).cmdset.all() all_cmdsets.extend([(cmdset.key, cmdset) for cmdset in obj.get_session(obj.sessid).cmdset.all()])
except (TypeError, AttributeError): except (TypeError, AttributeError):
pass pass
all_cmdsets = [cmdset for cmdset in dict(all_cmdsets).values()]
all_cmdsets.sort(key=lambda x: x.priority, reverse=True) all_cmdsets.sort(key=lambda x: x.priority, reverse=True)
string += "\n{wStored Cmdset(s){n:\n %s" % ("\n ".join("%s [%s] (prio %s)" % \ string += "\n{wMerged Cmdset(s){n:\n %s" % ("\n ".join("%s [%s] (%s, prio %s)" % \
(cmdset.path, cmdset.key, cmdset.priority) (cmdset.path, cmdset.key, cmdset.mergetype, cmdset.priority)
for cmdset in all_cmdsets)) for cmdset in all_cmdsets))
# list the commands available to this object # list the commands available to this object
avail_cmdset = sorted([cmd.key for cmd in avail_cmdset avail_cmdset = sorted([cmd.key for cmd in avail_cmdset
if cmd.access(obj, "cmd")]) if cmd.access(obj, "cmd")])
cmdsetstr = utils.fill(", ".join(avail_cmdset), indent=2) cmdsetstr = utils.fill(", ".join(avail_cmdset), indent=2)
string += "\n{wCommands available to %s (all cmdsets + exits and external cmds){n:\n %s" % (obj.key, cmdsetstr) string += "\n{wCommands available to %s (result of Merged CmdSets){n:\n %s" % (obj.key, 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 += "\n{wScripts{n:\n %s" % obj.scripts
@ -1759,7 +1772,7 @@ class CmdExamine(ObjManipCommand):
caller.execute_cmd('look %s' % obj.name) caller.execute_cmd('look %s' % obj.name)
return return
# using callback for printing result whenever function returns. # using callback for printing result whenever function returns.
get_and_merge_cmdsets(obj, self.session, self.player, obj, "session").addCallback(get_cmdset_callback) get_and_merge_cmdsets(obj, self.session, self.player, obj, "object").addCallback(get_cmdset_callback)
else: else:
self.msg("You need to supply a target to examine.") self.msg("You need to supply a target to examine.")
return return
@ -1794,8 +1807,14 @@ class CmdExamine(ObjManipCommand):
# we are only interested in specific attributes # we are only interested in specific attributes
caller.msg(self.format_attributes(obj, attrname, crop=False)) caller.msg(self.format_attributes(obj, attrname, crop=False))
else: else:
if obj.sessid:
mergemode = "session"
elif self.player_mode:
mergemode = "player"
else:
mergemode = "object"
# using callback to print results whenever function returns. # using callback to print results whenever function returns.
get_and_merge_cmdsets(obj, self.session, self.player, obj, "session").addCallback(get_cmdset_callback) get_and_merge_cmdsets(obj, self.session, self.player, obj, mergemode).addCallback(get_cmdset_callback)
class CmdFind(MuxCommand): class CmdFind(MuxCommand):

View file

@ -9,7 +9,7 @@ class SessionCmdSet(CmdSet):
Sets up the unlogged cmdset. Sets up the unlogged cmdset.
""" """
key = "DefaultSession" key = "DefaultSession"
priority = 0 priority = -7
def at_cmdset_creation(self): def at_cmdset_creation(self):
"Populate the cmdset" "Populate the cmdset"

View file

@ -44,7 +44,6 @@ class ChannelCommand(command.Command):
is_channel = True is_channel = True
key = "general" key = "general"
help_category = "Channel Names" help_category = "Channel Names"
locks = "cmd:all()"
obj = None obj = None
def parse(self): def parse(self):
@ -129,7 +128,6 @@ class ChannelHandler(object):
help_category="Channel names", help_category="Channel names",
obj=channel, obj=channel,
is_channel=True) is_channel=True)
cmd.__doc__ = self._format_help(channel)
self.cached_channel_cmds.append(cmd) self.cached_channel_cmds.append(cmd)
self.cached_cmdsets = {} self.cached_cmdsets = {}