(PEP8) Whitespace/indent, split lines in help.py
This commit is contained in:
parent
340ebb688d
commit
e3aa3ce7c6
1 changed files with 25 additions and 20 deletions
|
|
@ -198,7 +198,8 @@ class CmdHelp(Command):
|
||||||
# retrieve all available commands and database topics
|
# retrieve all available commands and database topics
|
||||||
all_cmds = [cmd for cmd in cmdset if self.check_show_help(cmd, caller)]
|
all_cmds = [cmd for cmd in cmdset if self.check_show_help(cmd, caller)]
|
||||||
all_topics = [topic for topic in HelpEntry.objects.all() if topic.access(caller, 'view', default=True)]
|
all_topics = [topic for topic in HelpEntry.objects.all() if topic.access(caller, 'view', default=True)]
|
||||||
all_categories = list(set([cmd.help_category.lower() for cmd in all_cmds] + [topic.help_category.lower() for topic in all_topics]))
|
all_categories = list(set([cmd.help_category.lower() for cmd in all_cmds] + [topic.help_category.lower()
|
||||||
|
for topic in all_topics]))
|
||||||
|
|
||||||
if query in ("list", "all"):
|
if query in ("list", "all"):
|
||||||
# we want to list all available help entries, grouped by category
|
# we want to list all available help entries, grouped by category
|
||||||
|
|
@ -222,7 +223,8 @@ class CmdHelp(Command):
|
||||||
if suggestion_maxnum > 0:
|
if suggestion_maxnum > 0:
|
||||||
vocabulary = [cmd.key for cmd in all_cmds if cmd] + [topic.key for topic in all_topics] + all_categories
|
vocabulary = [cmd.key for cmd in all_cmds if cmd] + [topic.key for topic in all_topics] + all_categories
|
||||||
[vocabulary.extend(cmd.aliases) for cmd in all_cmds]
|
[vocabulary.extend(cmd.aliases) for cmd in all_cmds]
|
||||||
suggestions = [sugg for sugg in string_suggestions(query, set(vocabulary), cutoff=suggestion_cutoff, maxnum=suggestion_maxnum)
|
suggestions = [sugg for sugg in string_suggestions(query, set(vocabulary), cutoff=suggestion_cutoff,
|
||||||
|
maxnum=suggestion_maxnum)
|
||||||
if sugg != query]
|
if sugg != query]
|
||||||
if not suggestions:
|
if not suggestions:
|
||||||
suggestions = [sugg for sugg in vocabulary if sugg != query and sugg.startswith(query)]
|
suggestions = [sugg for sugg in vocabulary if sugg != query and sugg.startswith(query)]
|
||||||
|
|
@ -231,9 +233,9 @@ class CmdHelp(Command):
|
||||||
match = [cmd for cmd in all_cmds if cmd == query]
|
match = [cmd for cmd in all_cmds if cmd == query]
|
||||||
if len(match) == 1:
|
if len(match) == 1:
|
||||||
formatted = self.format_help_entry(match[0].key,
|
formatted = self.format_help_entry(match[0].key,
|
||||||
match[0].get_help(caller, cmdset),
|
match[0].get_help(caller, cmdset),
|
||||||
aliases=match[0].aliases,
|
aliases=match[0].aliases,
|
||||||
suggested=suggestions)
|
suggested=suggestions)
|
||||||
self.msg_help(formatted)
|
self.msg_help(formatted)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -241,16 +243,17 @@ class CmdHelp(Command):
|
||||||
match = list(HelpEntry.objects.find_topicmatch(query, exact=True))
|
match = list(HelpEntry.objects.find_topicmatch(query, exact=True))
|
||||||
if len(match) == 1:
|
if len(match) == 1:
|
||||||
formatted = self.format_help_entry(match[0].key,
|
formatted = self.format_help_entry(match[0].key,
|
||||||
match[0].entrytext,
|
match[0].entrytext,
|
||||||
aliases=match[0].aliases.all(),
|
aliases=match[0].aliases.all(),
|
||||||
suggested=suggestions)
|
suggested=suggestions)
|
||||||
self.msg_help(formatted)
|
self.msg_help(formatted)
|
||||||
return
|
return
|
||||||
|
|
||||||
# try to see if a category name was entered
|
# try to see if a category name was entered
|
||||||
if query in all_categories:
|
if query in all_categories:
|
||||||
self.msg_help(self.format_help_list({query:[cmd.key for cmd in all_cmds if cmd.help_category==query]},
|
self.msg_help(self.format_help_list({query: [cmd.key for cmd in all_cmds if cmd.help_category == query]},
|
||||||
{query:[topic.key for topic in all_topics if topic.help_category==query]}))
|
{query: [topic.key for topic in all_topics
|
||||||
|
if topic.help_category == query]}))
|
||||||
return
|
return
|
||||||
|
|
||||||
# no exact matches found. Just give suggestions.
|
# no exact matches found. Just give suggestions.
|
||||||
|
|
@ -264,6 +267,7 @@ def _loadhelp(caller):
|
||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def _savehelp(caller, buffer):
|
def _savehelp(caller, buffer):
|
||||||
entry = caller.db._editing_help
|
entry = caller.db._editing_help
|
||||||
caller.msg("Saved help entry.")
|
caller.msg("Saved help entry.")
|
||||||
|
|
@ -275,6 +279,7 @@ def _quithelp(caller):
|
||||||
caller.msg("Closing the editor.")
|
caller.msg("Closing the editor.")
|
||||||
del caller.db._editing_help
|
del caller.db._editing_help
|
||||||
|
|
||||||
|
|
||||||
class CmdSetHelp(COMMAND_DEFAULT_CLASS):
|
class CmdSetHelp(COMMAND_DEFAULT_CLASS):
|
||||||
"""
|
"""
|
||||||
Edit the help database.
|
Edit the help database.
|
||||||
|
|
@ -307,7 +312,7 @@ class CmdSetHelp(COMMAND_DEFAULT_CLASS):
|
||||||
help_category = "Building"
|
help_category = "Building"
|
||||||
|
|
||||||
def func(self):
|
def func(self):
|
||||||
"Implement the function"
|
"""Implement the function"""
|
||||||
|
|
||||||
switches = self.switches
|
switches = self.switches
|
||||||
lhslist = self.lhslist
|
lhslist = self.lhslist
|
||||||
|
|
@ -329,7 +334,7 @@ class CmdSetHelp(COMMAND_DEFAULT_CLASS):
|
||||||
# check if we have an old entry with the same name
|
# check if we have an old entry with the same name
|
||||||
try:
|
try:
|
||||||
for querystr in topicstrlist:
|
for querystr in topicstrlist:
|
||||||
old_entry = HelpEntry.objects.find_topicmatch(querystr) # also search by alias
|
old_entry = HelpEntry.objects.find_topicmatch(querystr) # also search by alias
|
||||||
if old_entry:
|
if old_entry:
|
||||||
old_entry = list(old_entry)[0]
|
old_entry = list(old_entry)[0]
|
||||||
break
|
break
|
||||||
|
|
@ -352,12 +357,12 @@ class CmdSetHelp(COMMAND_DEFAULT_CLASS):
|
||||||
else:
|
else:
|
||||||
helpentry = create.create_help_entry(topicstr,
|
helpentry = create.create_help_entry(topicstr,
|
||||||
self.rhs, category=category,
|
self.rhs, category=category,
|
||||||
locks=lockstring,aliases=aliases)
|
locks=lockstring, aliases=aliases)
|
||||||
self.caller.db._editing_help = helpentry
|
self.caller.db._editing_help = helpentry
|
||||||
|
|
||||||
EvEditor(self.caller, loadfunc=_loadhelp, savefunc=_savehelp,
|
EvEditor(self.caller, loadfunc=_loadhelp, savefunc=_savehelp,
|
||||||
quitfunc=_quithelp, key="topic {}".format(topicstr),
|
quitfunc=_quithelp, key="topic {}".format(topicstr),
|
||||||
persistent=True)
|
persistent=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
if 'append' in switches or "merge" in switches or "extend" in switches:
|
if 'append' in switches or "merge" in switches or "extend" in switches:
|
||||||
|
|
@ -401,21 +406,21 @@ class CmdSetHelp(COMMAND_DEFAULT_CLASS):
|
||||||
self.msg("Overwrote the old topic '%s'%s." % (topicstr, aliastxt))
|
self.msg("Overwrote the old topic '%s'%s." % (topicstr, aliastxt))
|
||||||
else:
|
else:
|
||||||
self.msg("Topic '%s'%s already exists. Use /replace to overwrite "
|
self.msg("Topic '%s'%s already exists. Use /replace to overwrite "
|
||||||
"or /append or /merge to add text to it." % (topicstr, aliastxt))
|
"or /append or /merge to add text to it." % (topicstr, aliastxt))
|
||||||
else:
|
else:
|
||||||
# no old entry. Create a new one.
|
# no old entry. Create a new one.
|
||||||
new_entry = create.create_help_entry(topicstr,
|
new_entry = create.create_help_entry(topicstr,
|
||||||
self.rhs, category=category,
|
self.rhs, category=category,
|
||||||
locks=lockstring,aliases=aliases)
|
locks=lockstring, aliases=aliases)
|
||||||
if new_entry:
|
if new_entry:
|
||||||
self.msg("Topic '%s'%s was successfully created." % (topicstr, aliastxt))
|
self.msg("Topic '%s'%s was successfully created." % (topicstr, aliastxt))
|
||||||
if 'edit' in switches:
|
if 'edit' in switches:
|
||||||
# open the line editor to edit the helptext
|
# open the line editor to edit the helptext
|
||||||
self.caller.db._editing_help = new_entry
|
self.caller.db._editing_help = new_entry
|
||||||
EvEditor(self.caller, loadfunc=_loadhelp,
|
EvEditor(self.caller, loadfunc=_loadhelp,
|
||||||
savefunc=_savehelp, quitfunc=_quithelp,
|
savefunc=_savehelp, quitfunc=_quithelp,
|
||||||
key="topic {}".format(new_entry.key),
|
key="topic {}".format(new_entry.key),
|
||||||
persistent=True)
|
persistent=True)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
self.msg("Error when creating topic '%s'%s! Contact an admin." % (topicstr, aliastxt))
|
self.msg("Error when creating topic '%s'%s! Contact an admin." % (topicstr, aliastxt))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue