feat: add hooks at end of timer
Hooks that can be launched after end of timer have been added and can be set as scripts in $HOME/.config/pomme/hooks/after
This commit is contained in:
parent
ead9725017
commit
f232c40b1e
14
poetry.lock
generated
14
poetry.lock
generated
@ -247,6 +247,14 @@ wcwidth = "*"
|
||||
checkqa-mypy = ["mypy (v0.761)"]
|
||||
testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "requests", "xmlschema"]
|
||||
|
||||
[[package]]
|
||||
category = "main"
|
||||
description = "PyXDG contains implementations of freedesktop.org standards in python."
|
||||
name = "pyxdg"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
version = "0.26"
|
||||
|
||||
[[package]]
|
||||
category = "dev"
|
||||
description = "Alternative regular expression module, to replace re."
|
||||
@ -296,7 +304,7 @@ python-versions = "*"
|
||||
version = "0.1.8"
|
||||
|
||||
[metadata]
|
||||
content-hash = "cfd25d1d42c5011134c700ba470269b7c0d6076e9cc444a69b4dcfefdb8ea2bd"
|
||||
content-hash = "fd95a1de8c202bcfdd879a6d4ad47206212f3afad7e823ba527938a5dfcaeadc"
|
||||
python-versions = "^3.8"
|
||||
|
||||
[metadata.files]
|
||||
@ -403,6 +411,10 @@ pytest = [
|
||||
{file = "pytest-5.3.5-py3-none-any.whl", hash = "sha256:ff615c761e25eb25df19edddc0b970302d2a9091fbce0e7213298d85fb61fef6"},
|
||||
{file = "pytest-5.3.5.tar.gz", hash = "sha256:0d5fe9189a148acc3c3eb2ac8e1ac0742cb7618c084f3d228baaec0c254b318d"},
|
||||
]
|
||||
pyxdg = [
|
||||
{file = "pyxdg-0.26-py2.py3-none-any.whl", hash = "sha256:1948ff8e2db02156c0cccd2529b43c0cff56ebaa71f5f021bbd755bc1419190e"},
|
||||
{file = "pyxdg-0.26.tar.gz", hash = "sha256:fe2928d3f532ed32b39c32a482b54136fe766d19936afc96c8f00645f9da1a06"},
|
||||
]
|
||||
regex = [
|
||||
{file = "regex-2020.1.8-cp27-cp27m-win32.whl", hash = "sha256:4e8f02d3d72ca94efc8396f8036c0d3bcc812aefc28ec70f35bb888c74a25161"},
|
||||
{file = "regex-2020.1.8-cp27-cp27m-win_amd64.whl", hash = "sha256:e6c02171d62ed6972ca8631f6f34fa3281d51db8b326ee397b9c83093a6b7242"},
|
||||
|
20
pomme/dirs.py
Normal file
20
pomme/dirs.py
Normal file
@ -0,0 +1,20 @@
|
||||
from pathlib import Path
|
||||
from xdg import BaseDirectory
|
||||
import typing
|
||||
|
||||
|
||||
class Dirs:
|
||||
def __init__(self):
|
||||
self.conf_dir = Path(BaseDirectory.xdg_config_home).joinpath("pomme")
|
||||
self.hooks_dirs: typing.Dict[str, Path] = dict()
|
||||
self.hooks_dirs["after"] = Path(
|
||||
BaseDirectory.xdg_config_home
|
||||
).joinpath("pomme/hooks/after")
|
||||
|
||||
if not self.conf_dir.is_dir():
|
||||
self.conf_dir.mkdir(parents=True)
|
||||
print("Configuration directory created: {}".format(self.conf_dir))
|
||||
for name, path in self.hooks_dirs.items():
|
||||
if not path.is_dir():
|
||||
path.mkdir(parents=True)
|
||||
print("Hooks directory created {}".format(path))
|
14
pomme/hooks.py
Normal file
14
pomme/hooks.py
Normal file
@ -0,0 +1,14 @@
|
||||
import os
|
||||
from pomme.dirs import Dirs
|
||||
|
||||
|
||||
class Hooks():
|
||||
def __init__(self):
|
||||
self.dirs = Dirs()
|
||||
|
||||
def after(self):
|
||||
script_list = self.dirs.hooks_dirs["after"].iterdir()
|
||||
|
||||
for script in script_list:
|
||||
if script.is_file():
|
||||
os.system(script)
|
@ -8,6 +8,7 @@ import time
|
||||
from blessed import Terminal # type: ignore
|
||||
|
||||
from pomme.timer import Timer
|
||||
from pomme.hooks import Hooks
|
||||
|
||||
file_path = os.path.dirname(__file__)
|
||||
config = toml.load(os.path.join(file_path, "config.toml"))
|
||||
@ -51,11 +52,13 @@ def print_time(s) -> None:
|
||||
"""
|
||||
:param s: sheduler
|
||||
"""
|
||||
hooks = Hooks()
|
||||
print(term.home + term.clear)
|
||||
if timer.running():
|
||||
print(timer.remaining())
|
||||
else:
|
||||
print("timer finished")
|
||||
hooks.after()
|
||||
return
|
||||
s.enter(1, 1, print_time, (s,))
|
||||
|
||||
|
@ -10,6 +10,7 @@ python = "^3.8"
|
||||
click = "^7.0"
|
||||
toml = "^0.10.0"
|
||||
blessed = "^1.5"
|
||||
pyxdg = "^0.26"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
mypy = "^0.761"
|
||||
|
Loading…
Reference in New Issue
Block a user