start adding actual gotify stuff

This commit is contained in:
Brendan Haines 2024-09-13 21:00:44 -06:00
parent 830ec3b3d0
commit 9c3ccb233c
2 changed files with 116 additions and 27 deletions

104
Pipfile.lock generated Normal file
View File

@ -0,0 +1,104 @@
{
"_meta": {
"hash": {
"sha256": "0f54883c8ada6db11ca84430fcbd7e2c6faf74e1d4b2cad48c78b2d29aa3faf8"
},
"pipfile-spec": 6,
"requires": {
"python_version": "3.11"
},
"sources": [
{
"name": "pypi",
"url": "https://pypi.org/simple",
"verify_ssl": true
}
]
},
"default": {
"anyio": {
"hashes": [
"sha256:5aadc6a1bbb7cdb0bede386cac5e2940f5e2ff3aa20277e991cf028e0585ce94",
"sha256:c1b2d8f46a8a812513012e1107cb0e68c17159a7a594208005a57dc776e1bdc7"
],
"markers": "python_version >= '3.8'",
"version": "==4.4.0"
},
"certifi": {
"hashes": [
"sha256:922820b53db7a7257ffbda3f597266d435245903d80737e34f8a45ff3e3230d8",
"sha256:bec941d2aa8195e248a60b31ff9f0558284cf01a52591ceda73ea9afffd69fd9"
],
"markers": "python_version >= '3.6'",
"version": "==2024.8.30"
},
"click": {
"hashes": [
"sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28",
"sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de"
],
"index": "pypi",
"markers": "python_version >= '3.7'",
"version": "==8.1.7"
},
"gotify": {
"hashes": [
"sha256:184faec76de78279c5acd6e21dfefd11223d74a816b607f1063ac22df40641b2",
"sha256:47bdc0332143cd5c251e284ffa487467429c624a1d40aefb013774f6f4dd4b7d"
],
"index": "pypi",
"markers": "python_version >= '3.9'",
"version": "==0.6.0"
},
"h11": {
"hashes": [
"sha256:8f19fbbe99e72420ff35c00b27a34cb9937e902a8b810e2c88300c6f0a3b699d",
"sha256:e3fe4ac4b851c468cc8363d500db52c2ead036020723024a109d37346efaa761"
],
"markers": "python_version >= '3.7'",
"version": "==0.14.0"
},
"httpcore": {
"hashes": [
"sha256:34a38e2f9291467ee3b44e89dd52615370e152954ba21721378a87b2960f7a61",
"sha256:421f18bac248b25d310f3cacd198d55b8e6125c107797b609ff9b7a6ba7991b5"
],
"markers": "python_version >= '3.8'",
"version": "==1.0.5"
},
"httpx": {
"hashes": [
"sha256:7bb2708e112d8fdd7829cd4243970f0c223274051cb35ee80c03301ee29a3df0",
"sha256:f7c2be1d2f3c3c3160d441802406b206c2b76f5947b11115e6df10c6c65e66c2"
],
"markers": "python_version >= '3.8'",
"version": "==0.27.2"
},
"idna": {
"hashes": [
"sha256:050b4e5baadcd44d760cedbd2b8e639f2ff89bbc7a5730fcc662954303377aac",
"sha256:d838c2c0ed6fced7693d5e8ab8e734d5f8fda53a039c0164afb0b82e771e3603"
],
"markers": "python_version >= '3.6'",
"version": "==3.8"
},
"sniffio": {
"hashes": [
"sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2",
"sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc"
],
"markers": "python_version >= '3.7'",
"version": "==1.3.1"
},
"toml": {
"hashes": [
"sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b",
"sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"
],
"index": "pypi",
"markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2'",
"version": "==0.10.2"
}
},
"develop": {}
}

View File

@ -11,26 +11,7 @@ __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",
@ -38,15 +19,16 @@ def create_config(ctx):
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):
def wrap(command: List[str], config: Path):
"""Wrap an arbitrary command with gotify notifications"""
if init:
print("calling init")
create_config(command)
else:
# read settings first
with open(config, "r") as f:
settings = toml.load(f)
url = settings["server"]
with gotify.Gotify(base_url=url) as gotify_connection:
# run the command
result = subprocess.run(
command,
@ -55,10 +37,13 @@ def wrap(ctx, command: List[str], config: Path, init: bool): # , config: Path):
stdout=subprocess.PIPE,
encoding="utf-8",
)
# TODO: print lines real time as the subprocess runs
print(result.stdout, end="")
return result.returncode
gotify_connection.create_message(message=f'Command "{" ".join(command)}" finished {""}', title="")
return result.returncode
# %% main