Fix cmdset merge with systemcmd. Resolves #2146

This commit is contained in:
Griatch 2020-06-27 12:56:58 +02:00
parent d5a59cb618
commit 072d480439
2 changed files with 14 additions and 9 deletions

View file

@ -472,13 +472,13 @@ def get_and_merge_cmdsets(caller, session, account, obj, callertype, raw_string)
tempmergers[prio] = cmdset
# sort cmdsets after reverse priority (highest prio are merged in last)
cmdsets = yield sorted(list(tempmergers.values()), key=lambda x: x.priority)
sorted_cmdsets = yield sorted(list(tempmergers.values()), key=lambda x: x.priority)
# Merge all command sets into one, beginning with the lowest-prio one
cmdset = cmdsets[0]
for merging_cmdset in cmdsets[1:]:
cmdset = sorted_cmdsets[0]
for merging_cmdset in sorted_cmdsets[1:]:
cmdset = yield cmdset + merging_cmdset
# store the full sets for diagnosis
# store the original, ungrouped set for diagnosis
cmdset.merged_from = cmdsets
# cache
_CMDSET_MERGE_CACHE[mergehash] = cmdset

View file

@ -443,12 +443,12 @@ class CmdSet(object, metaclass=_CmdSetMeta):
# print "__add__ for %s (prio %i) called with %s (prio %i)." % (self.key, self.priority, cmdset_a.key, cmdset_a.priority)
# return the system commands to the cmdset
cmdset_c.add(sys_commands)
cmdset_c.add(sys_commands, allow_duplicates=True)
return cmdset_c
def add(self, cmd):
def add(self, cmd, allow_duplicates=False):
"""
Add a new command or commands to this CmdSetcommand, a list of
Add a new command or commands to this CmdSet, a list of
commands or a cmdset to this cmdset. Note that this is *not*
a merge operation (that is handled by the + operator).
@ -456,6 +456,9 @@ class CmdSet(object, metaclass=_CmdSetMeta):
cmd (Command, list, Cmdset): This allows for adding one or
more commands to this Cmdset in one go. If another Cmdset
is given, all its commands will be added.
allow_duplicates (bool, optional): If set, will not try to remove
duplicate cmds in the set. This is needed during the merge process
to avoid wiping commands coming from cmdsets with duplicate=True.
Notes:
If cmd already exists in set, it will replace the old one
@ -498,8 +501,10 @@ class CmdSet(object, metaclass=_CmdSetMeta):
commands[ic] = cmd # replace
except ValueError:
commands.append(cmd)
# extra run to make sure to avoid doublets
self.commands = list(set(commands))
self.commands = commands
if not allow_duplicates:
# extra run to make sure to avoid doublets
self.commands = list(set(self.commands))
# add system_command to separate list as well,
# for quick look-up
if cmd.key.startswith("__"):