From 1fdbb71501c249bc3b579c1fc0fdc3ee9ae55efb Mon Sep 17 00:00:00 2001 From: Tamir Kfir Date: Fri, 12 Apr 2019 01:10:47 +0300 Subject: [PATCH 1/2] Add terminal support with example .comeback file --- comeback/plugins/terminal/__init__.py | 0 comeback/plugins/terminal/main.py | 50 +++++++++++++++++++++++++++ example/example_ktamir/.comeback | 2 ++ 3 files changed, 52 insertions(+) create mode 100644 comeback/plugins/terminal/__init__.py create mode 100644 comeback/plugins/terminal/main.py create mode 100644 example/example_ktamir/.comeback diff --git a/comeback/plugins/terminal/__init__.py b/comeback/plugins/terminal/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/comeback/plugins/terminal/main.py b/comeback/plugins/terminal/main.py new file mode 100644 index 0000000..b46aab4 --- /dev/null +++ b/comeback/plugins/terminal/main.py @@ -0,0 +1,50 @@ +import pathlib +from typing import Optional + +from comeback import utils + + +def check_plugin(cwd: str = None) -> utils.RUN_STATUS: + """Test if we can use this plugin""" + if cwd is None: + return False, 'cwd parameter is not set.' + if not pathlib.Path(cwd).is_dir(): + return False, 'cwd is not an existing directory' + return True, None + + +def run_windows(cwd: str) -> utils.RUN_STATUS: + pass + + +def run_linux(cwd: str) -> utils.RUN_STATUS: + pass + + +def run_mac(cwd: str) -> utils.RUN_STATUS: + terminal_type = 'iTerm' + apps_path = pathlib.Path('/Applications') + iterm_dir_pattern = '*[iI][tT]erm*' + results = list(apps_path.glob(iterm_dir_pattern)) + if not results: + terminal_type = 'Terminal' + + utils.run(f'open -a {terminal_type} {cwd}') + + return True, 'Opened terminal successfully' + + +def run_plugin(cwd: Optional[str]) -> utils.RUN_STATUS: + is_startable, err = check_plugin(cwd) + if not is_startable: + return False, err + + assert isinstance(cwd, str) + + platform = utils.get_platform() + if platform == 'windows': + return run_windows(cwd) + elif platform == 'linux': + return run_linux(cwd) + elif platform == 'mac': + return run_mac(cwd) diff --git a/example/example_ktamir/.comeback b/example/example_ktamir/.comeback new file mode 100644 index 0000000..8e85959 --- /dev/null +++ b/example/example_ktamir/.comeback @@ -0,0 +1,2 @@ +terminal: + cwd: / From 46865a02abe85f9159e37530b2580ffc21efb356 Mon Sep 17 00:00:00 2001 From: Tamir Kfir Date: Fri, 3 May 2019 20:45:32 +0300 Subject: [PATCH 2/2] CR: raise NotImplementedError, make types optional --- comeback/plugins/terminal/main.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/comeback/plugins/terminal/main.py b/comeback/plugins/terminal/main.py index b46aab4..b4e5672 100644 --- a/comeback/plugins/terminal/main.py +++ b/comeback/plugins/terminal/main.py @@ -4,7 +4,7 @@ from comeback import utils -def check_plugin(cwd: str = None) -> utils.RUN_STATUS: +def check_plugin(cwd: Optional[str] = None) -> utils.RUN_STATUS: """Test if we can use this plugin""" if cwd is None: return False, 'cwd parameter is not set.' @@ -13,12 +13,12 @@ def check_plugin(cwd: str = None) -> utils.RUN_STATUS: return True, None -def run_windows(cwd: str) -> utils.RUN_STATUS: - pass +def run_windows(cwd: Optional[str]) -> utils.RUN_STATUS: + raise NotImplementedError() -def run_linux(cwd: str) -> utils.RUN_STATUS: - pass +def run_linux(cwd: Optional[str]) -> utils.RUN_STATUS: + raise NotImplementedError() def run_mac(cwd: str) -> utils.RUN_STATUS: