Skip to content

Commit

Permalink
Remove need for check_plugin (#14)
Browse files Browse the repository at this point in the history
* Start removing usage of check_plugin

* Remove the need to create a check_plugin function
  • Loading branch information
Agam authored Feb 25, 2019
1 parent 518a6a0 commit 19a233d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
21 changes: 15 additions & 6 deletions comeback/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}!')
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions comeback/plugins/chrome/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -29,3 +33,4 @@ def run_plugin(url):
webbrowser.open_new_tab(url)

return True, None

4 changes: 4 additions & 0 deletions comeback/plugins/pycharm/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions comeback/plugins/vscode/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 19a233d

Please sign in to comment.