diff --git a/jarviscli/CmdInterpreter.py b/jarviscli/CmdInterpreter.py index 017b2e777..c071c819b 100644 --- a/jarviscli/CmdInterpreter.py +++ b/jarviscli/CmdInterpreter.py @@ -75,8 +75,7 @@ def input_number(self, prompt="", color="", rtype=float, rmin=None, rmax=None): try: value = rtype(self.input(prompt, color).replace(',', '.')) if (rmin is not None and value < rmin) or (rmax is not None and value > rmax): - prompt = "Sorry, needs to be between {} and {}. Try again: ".format( - rmin, rmax) + prompt = f"Sorry, needs to be between {rmin} and {rmax}. Try again: " else: return value except ValueError: @@ -258,13 +257,13 @@ def get_saving_directory(self, path): destination = get_parent_directory(path) break - elif user_choice == 'no' or user_choice == 'n': + if user_choice == 'no' or user_choice == 'n': destination = self.input('Enter the folder destination: ') if not os.path.exists(destination): os.makedirs(destination) break - else: - self.incorrect_option() + + self.incorrect_option() os.chdir(destination) @@ -320,7 +319,7 @@ def __init__( self.first_reaction = first_reaction self.first_reaction_text = first_reaction_text self.prompt = prompt - if (command): + if command: self.first_reaction = False self.first_reaction_text = "" self.prompt = "" @@ -358,7 +357,7 @@ def __init__( for directory in directories: self._plugin_manager.add_directory(directory) - if (not command): + if not command: self._init_plugin_info() self._activate_plugins() @@ -376,7 +375,8 @@ def _init_plugin_info(self): plugin_status = "{magenta}{enabled} {cyan}plugins loaded" if plugin_status_formatter['disabled'] > 0: - plugin_status += " {magenta}{disabled} {cyan}plugins disabled. More information: {magenta}status\n" + plugin_status += """ {magenta}{disabled} {cyan}plugins disabled. + More information: {magenta}status\n""" plugin_status += Fore.RESET self.first_reaction_text += plugin_status.format( @@ -406,10 +406,10 @@ def _activate_plugins(self): def _plugin_update_completion(self, plugin, plugin_name): """Return True if completion is available""" - completions = [i for i in plugin.complete()] + completions = list(plugin.complete()) if len(completions) > 0: def complete(completions): - def _complete_impl(self, text, line, begidx, endidx): + def _complete_impl(text): return [i for i in completions if i.startswith(text)] return _complete_impl setattr( @@ -448,49 +448,44 @@ def do_status(self, s): """Prints plugin status status""" count_enabled = self._plugin_manager.get_number_plugins_loaded() count_disabled = len(self._plugin_manager.get_disabled()) - self.say( - "{} Plugins enabled, {} Plugins disabled.".format( - count_enabled, - count_disabled)) + self.say(f"{count_enabled} plugins enabled, {count_disabled} plugins disabled.") if "short" not in s and count_disabled > 0: self.say("") for disabled, reason in self._plugin_manager.get_disabled().items(): - self.say( - "{:<20}: {}".format( - disabled, - " OR ".join(reason))) + self.say(f"{disabled:<20}: {' OR '.join(reason)}") + def do_help(self, arg): if arg: Cmd.do_help(self, arg) else: self.say("") - headerString = "These are valid commands for Jarvis" - formatString = "Format: command ([aliases for command])" - self.say(headerString) - self.say(formatString, Fore.CYAN) - pluginDict = self._plugin_manager.get_plugins() - uniquePlugins = {} - for key in pluginDict.keys(): - plugin = pluginDict[key] - if(plugin not in uniquePlugins.keys()): - uniquePlugins[plugin.get_name()] = plugin - helpOutput = [] - for name in sorted(uniquePlugins.keys()): - if (name == "help"): + header_string = "These are valid commands for Jarvis" + format_string = "Format: command ([aliases for command])" + self.say(header_string) + self.say(format_string, Fore.CYAN) + plugin_dict = self._plugin_manager.get_plugins() + unique_plugins = {} + for key in plugin_dict.keys(): + plugin = plugin_dict[key] + if plugin not in unique_plugins: + unique_plugins[plugin.get_name()] = plugin + help_output = [] + for name in sorted(unique_plugins.keys()): + if name == "help": continue try: - aliasString = ", ".join(uniquePlugins[name].alias()) - if (aliasString != ""): - pluginOutput = "* " + name + " (" + aliasString + ")" - helpOutput.append(pluginOutput) + alias_string = ", ".join(unique_plugins[name].alias()) + if alias_string != "": + plugin_output = "* " + name + " (" + alias_string + ")" + help_output.append(plugin_output) else: - helpOutput.append("* " + name) + help_output.append("* " + name) except AttributeError: - helpOutput.append("* " + name) + help_output.append("* " + name) - Cmd.columnize(self, helpOutput) + Cmd.columnize(self, help_output) def help_status(self): self.say("Prints info about enabled or disabled plugins")