diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..bf58b06 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,16 @@ +{ + "editor.codeActionsOnSave": { + "source.organizeImports": "explicit" + }, + "editor.formatOnSave": true, + "files.trimTrailingWhitespace": true, + "[python]": { + "diffEditor.ignoreTrimWhitespace": false, + "gitlens.codeLens.symbolScopes": [ + "!Module" + ], + "editor.formatOnType": false, + "editor.wordBasedSuggestions": "off", + "editor.defaultFormatter": "ms-python.black-formatter" + } +} \ No newline at end of file diff --git a/Pipfile b/Pipfile index 09a3233..5a20030 100644 --- a/Pipfile +++ b/Pipfile @@ -6,6 +6,7 @@ name = "pypi" [packages] gotify = "*" click = "*" +toml = "*" [dev-packages] diff --git a/goat_monitor.py b/goat_monitor.py new file mode 100644 index 0000000..86ad1ec --- /dev/null +++ b/goat_monitor.py @@ -0,0 +1,66 @@ +# %% imports +import subprocess +from pathlib import Path +from typing import List + +import click +import gotify +import toml + +__version__ = "v0.0.0" + + +# %% commands + + +@click.command() +@click.pass_context +# @click.option( +# "--config", +# default="~/.config/goat_monitor.toml", +# type=click.Path(exists=False, writable=True, path_type=Path), +# help="Specify a .toml configuration file location", +# ) +# def init(config: Path): +# with open(config, "w") as f: +# cfg_data = dict() +# toml.dump(cfg_data, f) +def create_config(ctx): + print("init called") + print(ctx) + + +@click.group(invoke_without_command=True) +@click.argument("command", nargs=-1, required=False, type=str) +@click.option( + "--config", + default="~/.config/goat_monitor.toml", + type=click.Path(path_type=Path), + help="Use a .toml configuration file", +) +@click.option("--init", is_flag=True, default=False, help="Create a configuration file") +@click.pass_context +def wrap(ctx, command: List[str], config: Path, init: bool): # , config: Path): + """Wrap an arbitrary command with gotify notifications""" + + if init: + print("calling init") + create_config(command) + else: + # run the command + result = subprocess.run( + command, + shell=True, + stderr=subprocess.STDOUT, + stdout=subprocess.PIPE, + encoding="utf-8", + ) + # TODO: print lines real time as the subprocess runs + print(result.stdout, end="") + + return result.returncode + + +# %% main +if __name__ == "__main__": + wrap() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..19a859b --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,17 @@ +[tool.black] +line-length = 120 +exclude = ''' +/( + \.eggs + | \.git + | \.hg + | \.mypy_cache + | \.tox + | \.venv + | \.vscode + | _build + | buck-out + | build + | dist +)/ +''' diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..3ba7503 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,4 @@ +[flake8] +exclude = **/*__init__.py,.venv/*,tox/*,build/*,dist/* +ignore = C901,E203,E731,W503 +max-line-length = 120 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..e69de29