Merge branch 'BlauFeuer-cleanup-1' of git://github.com/BlauFeuer/evennia into BlauFeuer-BlauFeuer-cleanup-1

This commit is contained in:
Griatch 2017-09-09 18:59:16 +02:00
commit 67470bbd66

View file

@ -122,7 +122,7 @@ class CmdSetObjAlias(COMMAND_DEFAULT_CLASS):
help_category = "Building" help_category = "Building"
def func(self): def func(self):
"Set the aliases." """Set the aliases."""
caller = self.caller caller = self.caller
@ -202,7 +202,7 @@ class CmdCopy(ObjManipCommand):
help_category = "Building" help_category = "Building"
def func(self): def func(self):
"Uses ObjManipCommand.parse()" """Uses ObjManipCommand.parse()"""
caller = self.caller caller = self.caller
args = self.args args = self.args
@ -309,8 +309,7 @@ class CmdCpAttr(ObjManipCommand):
""" """
if not obj.attributes.has(attr): if not obj.attributes.has(attr):
self.caller.msg( self.caller.msg(
"%s doesn't have an attribute %s." "%s doesn't have an attribute %s." % (obj.name, attr))
% (obj.name, attr))
return False return False
return True return True
@ -571,11 +570,12 @@ class CmdDesc(COMMAND_DEFAULT_CLASS):
self.caller.db.evmenu_target = obj self.caller.db.evmenu_target = obj
# launch the editor # launch the editor
EvEditor(self.caller, loadfunc=_desc_load, savefunc=_desc_save, quitfunc=_desc_quit, key="desc", persistent=True) EvEditor(self.caller, loadfunc=_desc_load, savefunc=_desc_save,
quitfunc=_desc_quit, key="desc", persistent=True)
return return
def func(self): def func(self):
"Define command" """Define command"""
caller = self.caller caller = self.caller
if not self.args and 'edit' not in self.switches: if not self.args and 'edit' not in self.switches:
@ -635,7 +635,7 @@ class CmdDestroy(COMMAND_DEFAULT_CLASS):
default_confirm = 'yes' # what to assume if just pressing enter (yes/no) default_confirm = 'yes' # what to assume if just pressing enter (yes/no)
def func(self): def func(self):
"Implements the command." """Implements the command."""
caller = self.caller caller = self.caller
delete = True delete = True
@ -758,7 +758,7 @@ class CmdDig(ObjManipCommand):
"edit:id({id}) or perm(Admin)" "edit:id({id}) or perm(Admin)"
def func(self): def func(self):
"Do the digging. Inherits variables from ObjManipCommand.parse()" """Do the digging. Inherits variables from ObjManipCommand.parse()"""
caller = self.caller caller = self.caller
@ -791,8 +791,8 @@ class CmdDig(ObjManipCommand):
alias_string = "" alias_string = ""
if new_room.aliases.all(): if new_room.aliases.all():
alias_string = " (%s)" % ", ".join(new_room.aliases.all()) alias_string = " (%s)" % ", ".join(new_room.aliases.all())
room_string = "Created room %s(%s)%s of type %s." % (new_room, room_string = "Created room %s(%s)%s of type %s." %\
new_room.dbref, alias_string, typeclass) (new_room, new_room.dbref, alias_string, typeclass)
# create exit to room # create exit to room
@ -912,7 +912,7 @@ class CmdTunnel(COMMAND_DEFAULT_CLASS):
"o": ("out", "i")} "o": ("out", "i")}
def func(self): def func(self):
"Implements the tunnel command" """Implements the tunnel command"""
if not self.args or not self.lhs: if not self.args or not self.lhs:
string = "Usage: @tunnel[/switch] <direction> [= <roomname>" \ string = "Usage: @tunnel[/switch] <direction> [= <roomname>" \
@ -972,7 +972,7 @@ class CmdLink(COMMAND_DEFAULT_CLASS):
help_category = "Building" help_category = "Building"
def func(self): def func(self):
"Perform the link" """Perform the link"""
caller = self.caller caller = self.caller
if not self.args: if not self.args:
@ -986,7 +986,6 @@ class CmdLink(COMMAND_DEFAULT_CLASS):
if not obj: if not obj:
return return
string = ""
if self.rhs: if self.rhs:
# this means a target name was given # this means a target name was given
target = caller.search(self.rhs, global_search=True) target = caller.search(self.rhs, global_search=True)
@ -994,8 +993,9 @@ class CmdLink(COMMAND_DEFAULT_CLASS):
return return
string = "" string = ""
note = "Note: %s(%s) did not have a destination set before. Make sure you linked the right thing."
if not obj.destination: if not obj.destination:
string += "Note: %s(%s) did not have a destination set before. Make sure you linked the right thing." % (obj.name, obj.dbref) string = note % (obj.name, obj.dbref)
if "twoway" in self.switches: if "twoway" in self.switches:
if not (target.location and obj.location): if not (target.location and obj.location):
string = "To create a two-way link, %s and %s must both have a location" % (obj, target) string = "To create a two-way link, %s and %s must both have a location" % (obj, target)
@ -1003,10 +1003,11 @@ class CmdLink(COMMAND_DEFAULT_CLASS):
self.caller.msg(string) self.caller.msg(string)
return return
if not target.destination: if not target.destination:
string += "\nNote: %s(%s) did not have a destination set before. Make sure you linked the right thing." % (target.name, target.dbref) string += note % (target.name, target.dbref)
obj.destination = target.location obj.destination = target.location
target.destination = obj.location target.destination = obj.location
string += "\nLink created %s (in %s) <-> %s (in %s) (two-way)." % (obj.name, obj.location, target.name, target.location) string += "\nLink created %s (in %s) <-> %s (in %s) (two-way)." %\
(obj.name, obj.location, target.name, target.location)
else: else:
obj.destination = target obj.destination = target
string += "\nLink created %s -> %s (one way)." % (obj.name, target) string += "\nLink created %s -> %s (one way)." % (obj.name, target)
@ -1088,7 +1089,7 @@ class CmdSetHome(CmdLink):
help_category = "Building" help_category = "Building"
def func(self): def func(self):
"implement the command" """implement the command"""
if not self.args: if not self.args:
string = "Usage: @home <obj> [= <home_location>]" string = "Usage: @home <obj> [= <home_location>]"
self.caller.msg(string) self.caller.msg(string)
@ -1113,7 +1114,8 @@ class CmdSetHome(CmdLink):
old_home = obj.home old_home = obj.home
obj.home = new_home obj.home = new_home
if old_home: if old_home:
string = "%s's home location was changed from %s(%s) to %s(%s)." % (obj, old_home, old_home.dbref, new_home, new_home.dbref) string = "%s's home location was changed from %s(%s) to %s(%s)." %\
(obj, old_home, old_home.dbref, new_home, new_home.dbref)
else: else:
string = "%s' home location was set to %s(%s)." % (obj, new_home, new_home.dbref) string = "%s' home location was set to %s(%s)." % (obj, new_home, new_home.dbref)
self.caller.msg(string) self.caller.msg(string)
@ -1135,7 +1137,7 @@ class CmdListCmdSets(COMMAND_DEFAULT_CLASS):
help_category = "Building" help_category = "Building"
def func(self): def func(self):
"list the cmdsets" """list the cmdsets"""
caller = self.caller caller = self.caller
if self.arglist: if self.arglist:
@ -1166,7 +1168,7 @@ class CmdName(ObjManipCommand):
help_category = "Building" help_category = "Building"
def func(self): def func(self):
"change the name" """change the name"""
caller = self.caller caller = self.caller
if not self.args: if not self.args:
@ -1276,8 +1278,8 @@ class CmdOpen(ObjManipCommand):
exit_obj.destination = destination exit_obj.destination = destination
if exit_aliases: if exit_aliases:
[exit_obj.aliases.add(alias) for alias in exit_aliases] [exit_obj.aliases.add(alias) for alias in exit_aliases]
string += " Rerouted its old destination '%s' to '%s' and changed aliases." % \ string += " Rerouted its old destination '%s' to '%s' and changed aliases." %\
(old_destination.name, destination.name) (old_destination.name, destination.name)
else: else:
string += " It already points to the correct place." string += " It already points to the correct place."
@ -1298,7 +1300,7 @@ class CmdOpen(ObjManipCommand):
string = "Created new Exit '%s' from %s to %s%s." % ( string = "Created new Exit '%s' from %s to %s%s." % (
exit_name, location.name, destination.name, string) exit_name, location.name, destination.name, string)
else: else:
string = "Error: Exit '%s' not created." % (exit_name) string = "Error: Exit '%s' not created." % exit_name
# emit results # emit results
caller.msg(string) caller.msg(string)
return exit_obj return exit_obj
@ -1522,9 +1524,9 @@ class CmdSetAttribute(ObjManipCommand):
"dicts.|n") "dicts.|n")
def edit_handler(self, obj, attr): def edit_handler(self, obj, attr):
"Activate the line editor" """Activate the line editor"""
def load(caller): def load(caller):
"Called for the editor to load the buffer" """Called for the editor to load the buffer"""
old_value = obj.attributes.get(attr) old_value = obj.attributes.get(attr)
if old_value is not None and not isinstance(old_value, basestring): if old_value is not None and not isinstance(old_value, basestring):
typ = type(old_value).__name__ typ = type(old_value).__name__
@ -1534,14 +1536,14 @@ class CmdSetAttribute(ObjManipCommand):
return old_value return old_value
def save(caller, buf): def save(caller, buf):
"Called when editor saves its buffer." """Called when editor saves its buffer."""
obj.attributes.add(attr, buf) obj.attributes.add(attr, buf)
caller.msg("Saved Attribute %s." % attr) caller.msg("Saved Attribute %s." % attr)
# start the editor # start the editor
EvEditor(self.caller, load, save, key="%s/%s" % (obj, attr)) EvEditor(self.caller, load, save, key="%s/%s" % (obj, attr))
def func(self): def func(self):
"Implement the set attribute - a limited form of @py." """Implement the set attribute - a limited form of @py."""
caller = self.caller caller = self.caller
if not self.args: if not self.args:
@ -1647,7 +1649,7 @@ class CmdTypeclass(COMMAND_DEFAULT_CLASS):
help_category = "Building" help_category = "Building"
def func(self): def func(self):
"Implements command" """Implements command"""
caller = self.caller caller = self.caller
@ -1785,7 +1787,7 @@ class CmdLock(ObjManipCommand):
If no lockstring is given, shows all locks on If no lockstring is given, shows all locks on
object. object.
Lockstring is on the form Lockstring is of the form
access_type:[NOT] func1(args)[ AND|OR][ NOT] func2(args) ...] access_type:[NOT] func1(args)[ AND|OR][ NOT] func2(args) ...]
Where func1, func2 ... valid lockfuncs with or without arguments. Where func1, func2 ... valid lockfuncs with or without arguments.
Separator expressions need not be capitalized. Separator expressions need not be capitalized.
@ -1806,7 +1808,7 @@ class CmdLock(ObjManipCommand):
help_category = "Building" help_category = "Building"
def func(self): def func(self):
"Sets up the command" """Sets up the command"""
caller = self.caller caller = self.caller
if not self.args: if not self.args:
@ -1816,7 +1818,7 @@ class CmdLock(ObjManipCommand):
return return
if '/' in self.lhs: if '/' in self.lhs:
# call on the form @lock obj/access_type # call of the form @lock obj/access_type
objname, access_type = [p.strip() for p in self.lhs.split('/', 1)] objname, access_type = [p.strip() for p in self.lhs.split('/', 1)]
obj = None obj = None
if objname.startswith("*"): if objname.startswith("*"):
@ -1829,7 +1831,7 @@ class CmdLock(ObjManipCommand):
caller.msg("You are not allowed to do that.") caller.msg("You are not allowed to do that.")
return return
lockdef = obj.locks.get(access_type) lockdef = obj.locks.get(access_type)
string = ""
if lockdef: if lockdef:
if 'del' in self.switches: if 'del' in self.switches:
obj.locks.delete(access_type) obj.locks.delete(access_type)
@ -2012,9 +2014,9 @@ class CmdExamine(ObjManipCommand):
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"):
# all() returns a 'stack', so make a copy to sort. # all() returns a 'stack', so make a copy to sort.
stored_cmdsets = sorted(obj.cmdset.all(), key=lambda x: x.priority, reverse=True) stored_cmdsets = sorted(obj.cmdset.all(), key=lambda x: x.priority, reverse=True)
string += "\n|wStored Cmdset(s)|n:\n %s" % ("\n ".join("%s [%s] (%s, prio %s)" % string += "\n|wStored Cmdset(s)|n:\n %s" % ("\n ".join("%s [%s] (%s, prio %s)" % (
(cmdset.path, cmdset.key, cmdset.mergetype, cmdset.priority) cmdset.path, cmdset.key, cmdset.mergetype, cmdset.priority) for cmdset in stored_cmdsets
for cmdset in stored_cmdsets if cmdset.key != "_EMPTY_CMDSET")) if cmdset.key != "_EMPTY_CMDSET"))
# this gets all components of the currently merged set # this gets all components of the currently merged set
all_cmdsets = [(cmdset.key, cmdset) for cmdset in avail_cmdset.merged_from] all_cmdsets = [(cmdset.key, cmdset) for cmdset in avail_cmdset.merged_from]
@ -2031,15 +2033,15 @@ class CmdExamine(ObjManipCommand):
else: else:
try: try:
# we have to protect this since many objects don't have sessions. # we have to protect this since many objects don't have sessions.
all_cmdsets.extend([(cmdset.key, cmdset) for cmdset in obj.get_session(obj.sessions.get()).cmdset.all()]) all_cmdsets.extend([(cmdset.key, cmdset)
for cmdset in obj.get_session(obj.sessions.get()).cmdset.all()])
except (TypeError, AttributeError): except (TypeError, AttributeError):
# an error means we are merging an object without a session # an error means we are merging an object without a session
pass pass
all_cmdsets = [cmdset for cmdset in dict(all_cmdsets).values()] 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|wMerged Cmdset(s)|n:\n %s" % ("\n ".join("%s [%s] (%s, prio %s)" % string += "\n|wMerged Cmdset(s)|n:\n %s" % ("\n ".join("%s [%s] (%s, prio %s)" % (
(cmdset.path, cmdset.key, cmdset.mergetype, 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
@ -2083,7 +2085,7 @@ class CmdExamine(ObjManipCommand):
return '%s\n%s\n%s' % (separator, string.strip(), separator) return '%s\n%s\n%s' % (separator, string.strip(), separator)
def func(self): def func(self):
"Process command" """Process command"""
caller = self.caller caller = self.caller
def get_cmdset_callback(cmdset): def get_cmdset_callback(cmdset):
@ -2107,7 +2109,8 @@ class CmdExamine(ObjManipCommand):
self.msg(caller.at_look(obj)) self.msg(caller.at_look(obj))
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.account, obj, "object", self.raw_string).addCallback(get_cmdset_callback) get_and_merge_cmdsets(obj, self.session, self.account, obj, "object",
self.raw_string).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
@ -2179,7 +2182,7 @@ class CmdFind(COMMAND_DEFAULT_CLASS):
help_category = "Building" help_category = "Building"
def func(self): def func(self):
"Search functionality" """Search functionality"""
caller = self.caller caller = self.caller
switches = self.switches switches = self.switches
@ -2232,7 +2235,7 @@ class CmdFind(COMMAND_DEFAULT_CLASS):
if not result: if not result:
string += "\n |RNo match found.|n" string += "\n |RNo match found.|n"
elif not low <= int(result[0].id) <= high: elif not low <= int(result[0].id) <= high:
string += "\n |RNo match found for '%s' in #dbref interval.|n" % (searchstring) string += "\n |RNo match found for '%s' in #dbref interval.|n" % searchstring
else: else:
result = result[0] result = result[0]
string += "\n|g %s - %s|n" % (result.get_display_name(caller), result.path) string += "\n|g %s - %s|n" % (result.get_display_name(caller), result.path)
@ -2310,7 +2313,7 @@ class CmdTeleport(COMMAND_DEFAULT_CLASS):
help_category = "Building" help_category = "Building"
def func(self): def func(self):
"Performs the teleport" """Performs the teleport"""
caller = self.caller caller = self.caller
args = self.args args = self.args
@ -2411,7 +2414,7 @@ class CmdScript(COMMAND_DEFAULT_CLASS):
help_category = "Building" help_category = "Building"
def func(self): def func(self):
"Do stuff" """Do stuff"""
caller = self.caller caller = self.caller
@ -2513,7 +2516,7 @@ class CmdTag(COMMAND_DEFAULT_CLASS):
arg_regex = r"(/\w+?(\s|$))|\s|$" arg_regex = r"(/\w+?(\s|$))|\s|$"
def func(self): def func(self):
"Implement the @tag functionality" """Implement the @tag functionality"""
if not self.args: if not self.args:
self.caller.msg("Usage: @tag[/switches] <obj> [= <tag>[:<category>]]") self.caller.msg("Usage: @tag[/switches] <obj> [= <tag>[:<category>]]")
@ -2575,7 +2578,7 @@ class CmdTag(COMMAND_DEFAULT_CLASS):
return return
# no search/deletion # no search/deletion
if self.rhs: if self.rhs:
# = is found, so we are on the form obj = tag # = is found; command args are of the form obj = tag
obj = self.caller.search(self.lhs, global_search=True) obj = self.caller.search(self.lhs, global_search=True)
if not obj: if not obj:
return return
@ -2653,10 +2656,10 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
help_category = "Building" help_category = "Building"
def func(self): def func(self):
"Implements the spawner" """Implements the spawner"""
def _show_prototypes(prototypes): def _show_prototypes(prototypes):
"Helper to show a list of available prototypes" """Helper to show a list of available prototypes"""
prots = ", ".join(sorted(prototypes.keys())) prots = ", ".join(sorted(prototypes.keys()))
return "\nAvailable prototypes (case sensistive): %s" % \ return "\nAvailable prototypes (case sensistive): %s" % \
("\n" + utils.fill(prots) if prots else "None") ("\n" + utils.fill(prots) if prots else "None")