From 19a233d5c45f3b41a017e6c9b96eedac6934a8f8 Mon Sep 17 00:00:00 2001 From: Agam Date: Tue, 26 Feb 2019 00:34:15 +0200 Subject: [PATCH] Remove need for check_plugin (#14) * Start removing usage of check_plugin * Remove the need to create a check_plugin function --- comeback/main.py | 21 +++++++++++++++------ comeback/plugins/chrome/main.py | 5 +++++ comeback/plugins/pycharm/main.py | 4 ++++ comeback/plugins/vscode/main.py | 3 +++ 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/comeback/main.py b/comeback/main.py index e38b482..8bd444f 100644 --- a/comeback/main.py +++ b/comeback/main.py @@ -23,15 +23,16 @@ def get_probable_project_name(): def call_plugin(module, plugin_name, **plugin_params): - is_startable, err = module.check_plugin(**plugin_params) - if not is_startable: - click.echo(f'Couldn\'t use plugin {plugin_name}: {err}') + try: + success, err = module.run_plugin(**plugin_params) + except TypeError as e: + click.echo( + f'There was a problem executing the plugin {plugin_name}: {e}') exit() - success, err = module.run_plugin(**plugin_params) if not success: - click.echo(f'There was a problem executing the plugin \ - {plugin_name}: {err}') + click.echo( + f'There was a problem executing the plugin {plugin_name}: {err}') exit() verbose_echo(f'Successfully started {plugin_name}!') @@ -47,6 +48,14 @@ def is_plugin_exists(plugin_name): def load_plugin(plugin_name, plugin_params): + if not plugin_name: + click.echo(f'Can\'t load a plugin without a plugin name') + exit() + + # Fix plugins that don't require params + if not plugin_params: + plugin_params = {} + importer = f'{plugins.__name__}.{plugin_name}.main' m = importlib.import_module(importer) call_plugin(m, plugin_name, **plugin_params) diff --git a/comeback/plugins/chrome/main.py b/comeback/plugins/chrome/main.py index 6417ad5..5b39524 100644 --- a/comeback/plugins/chrome/main.py +++ b/comeback/plugins/chrome/main.py @@ -18,6 +18,10 @@ def check_plugin(url=None): def run_plugin(url): + is_startable, err = check_plugin(url) + if not is_startable: + return False, err + browser_names = ['google-chrome', 'chrome'] success = False @@ -29,3 +33,4 @@ def run_plugin(url): webbrowser.open_new_tab(url) return True, None + diff --git a/comeback/plugins/pycharm/main.py b/comeback/plugins/pycharm/main.py index 3dd2c3c..3cce335 100644 --- a/comeback/plugins/pycharm/main.py +++ b/comeback/plugins/pycharm/main.py @@ -47,6 +47,10 @@ def run_windows(cwd): def run_plugin(cwd): + is_startable, err = check_plugin(cwd) + if not is_startable: + return False, err + platform = utils.get_platform() if platform == "windows": return run_windows(cwd) diff --git a/comeback/plugins/vscode/main.py b/comeback/plugins/vscode/main.py index 93f07fe..93f4624 100644 --- a/comeback/plugins/vscode/main.py +++ b/comeback/plugins/vscode/main.py @@ -16,6 +16,9 @@ def check_plugin(cwd=None): def run_plugin(cwd): + is_startable, err = check_plugin(cwd) + if not is_startable: + return False, err directory = pathlib.Path(cwd).expanduser() subprocess.call(f'code {directory}', shell=True) return True, None