From 6e13b8b73572f9c0ac9b5c683b98a475afbeab38 Mon Sep 17 00:00:00 2001 From: mathieui Date: Wed, 15 Aug 2018 13:13:17 +0200 Subject: yapf -rip on plugins --- plugins/alias.py | 51 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 20 deletions(-) (limited to 'plugins/alias.py') diff --git a/plugins/alias.py b/plugins/alias.py index 108fde54..a10beb7c 100644 --- a/plugins/alias.py +++ b/plugins/alias.py @@ -71,15 +71,19 @@ from poezio.core.structs import Completion class Plugin(BasePlugin): def init(self): - self.api.add_command('alias', self.command_alias, - usage=' [args]', - short='Create an alias command', - help='Create an alias for with [args].') - self.api.add_command('unalias', self.command_unalias, - usage='', - help='Remove a previously created alias', - short='Remove an alias', - completion=self.completion_unalias) + self.api.add_command( + 'alias', + self.command_alias, + usage=' [args]', + short='Create an alias command', + help='Create an alias for with [args].') + self.api.add_command( + 'unalias', + self.command_unalias, + usage='', + help='Remove a previously created alias', + short='Remove an alias', + completion=self.completion_unalias) self.commands = {} self.load_conf() @@ -114,18 +118,18 @@ class Plugin(BasePlugin): self.config.set(alias, command + ' ' + args) self.commands[alias] = command_wrapper( - generic_command, lambda: self.get_command(command), args) + generic_command, lambda: self.get_command(command), args) self.api.del_command(alias) - self.api.add_command(alias, self.commands[alias], - 'This command is an alias for /%s %s' % - (alias, command)) + self.api.add_command( + alias, self.commands[alias], + 'This command is an alias for /%s %s' % (alias, command)) if not silent: if update: self.api.information('Alias /%s updated' % alias, 'Info') else: self.api.information('Alias /%s successfuly created' % alias, - 'Info') + 'Info') def command_unalias(self, alias): """ @@ -135,19 +139,23 @@ class Plugin(BasePlugin): del self.commands[alias] self.api.del_command(alias) self.config.remove(alias) - self.api.information('Alias /%s successfuly deleted' % alias, 'Info') + self.api.information('Alias /%s successfuly deleted' % alias, + 'Info') def completion_unalias(self, the_input): "Completion for /unalias" aliases = [alias for alias in self.commands] aliases.sort() - return Completion(the_input.auto_completion, aliases, '', quotify=False) + return Completion( + the_input.auto_completion, aliases, '', quotify=False) def get_command(self, name): """Returns the function associated with a command""" + def dummy(args): """Dummy function called if the command doesn’t exist""" pass + if name in self.commands: return dummy elif name in self.core.commands: @@ -156,6 +164,7 @@ class Plugin(BasePlugin): return self.api.current_tab().commands[name].func return dummy + def split_args(line): """ Extract the relevant vars from the command line @@ -165,16 +174,17 @@ def split_args(line): return None alias_pos = line.find(' ') alias = line[:alias_pos] - end = line[alias_pos+1:] + end = line[alias_pos + 1:] args_pos = end.find(' ') if args_pos == -1: command = end args = '' else: command = end[:args_pos] - args = end[args_pos+1:] + args = end[args_pos + 1:] return (alias, command, args) + def generic_command(command, extra_args, args): """ Function that will execute the command and set the relevant @@ -187,10 +197,11 @@ def generic_command(command, extra_args, args): new_extra_args += ' '.join(args) return command()(new_extra_args) + def command_wrapper(func, command, extra_args): "set the predefined arguments" + def wrapper(*args, **kwargs): return func(command, extra_args, *args, **kwargs) - return wrapper - + return wrapper -- cgit v1.2.3