mirror of
https://codeberg.org/privacy1st/exec-notify
synced 2024-12-22 23:16:04 +01:00
refactor: rename to exec-notify
This commit is contained in:
parent
dcb855be85
commit
5d088864e6
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,4 @@
|
||||
/etc/execNotify/cfg.ini
|
||||
/etc/exec-notify/cfg.ini
|
||||
/mail/
|
||||
|
||||
/.idea/workspace.xml
|
||||
|
6
.idea/execNotify.iml
generated
6
.idea/execNotify.iml
generated
@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/dist" />
|
||||
@ -8,8 +9,9 @@
|
||||
<excludeFolder url="file://$MODULE_DIR$/mail" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/src/de.p1st.exec_notify.egg-info" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.10 (venv-310)" jdkType="Python SDK" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.11 (exec-notify)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
2
.idea/runConfigurations/execNotify.xml
generated
2
.idea/runConfigurations/execNotify.xml
generated
@ -13,7 +13,7 @@
|
||||
<option name="ADD_CONTENT_ROOTS" value="false" />
|
||||
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
|
||||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/src/de/p1st/exec_notify/execNotify.py" />
|
||||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/src/de/p1st/exec_notify/exec_notify.py" />
|
||||
<option name="PARAMETERS" value="ls /non/existent/file" />
|
||||
<option name="SHOW_COMMAND_LINE" value="false" />
|
||||
<option name="EMULATE_TERMINAL" value="false" />
|
||||
|
2
.idea/runConfigurations/notify.xml
generated
2
.idea/runConfigurations/notify.xml
generated
@ -13,7 +13,7 @@
|
||||
<option name="ADD_CONTENT_ROOTS" value="false" />
|
||||
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
|
||||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/src/de/p1st/exec_notify/notify.py" />
|
||||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/src/de/p1st/exec_notify/do_notify.py" />
|
||||
<option name="PARAMETERS" value="someSubject someBody-123" />
|
||||
<option name="SHOW_COMMAND_LINE" value="false" />
|
||||
<option name="EMULATE_TERMINAL" value="false" />
|
||||
|
41
README.md
41
README.md
@ -1,11 +1,12 @@
|
||||
# execNotify
|
||||
# exec-notify
|
||||
|
||||
* Send email notification if command fails with [de-p1st-execNotify](src/de/p1st/exec_notify/execNotify.py).
|
||||
* Send unconditional notifications with [de-p1st-notify](src/de/p1st/exec_notify/notify.py).
|
||||
* Send email notification if command fails with [exec-notify](src/de/p1st/exec_notify/exec_notify.py).
|
||||
* Send unconditional notifications with [do-notify](src/de/p1st/exec_notify/do_notify.py).
|
||||
|
||||
## TODOs
|
||||
|
||||
~~* Send notification about unread local mail only once!~~
|
||||
* add PKGBUILD
|
||||
* Rename python module (and git repository?) to `exec-notify`
|
||||
* Use subprocess_util > execute_print_capture
|
||||
* This way, the user can see the stdout/stderr while it is executed
|
||||
@ -47,7 +48,7 @@ pip --version
|
||||
Then install with one of the following options:
|
||||
|
||||
```shell
|
||||
sudo python3 -m pip install --upgrade --force-reinstall git+https://codeberg.org/privacy1st/execNotify
|
||||
sudo python3 -m pip install --upgrade --force-reinstall git+https://codeberg.org/privacy1st/exec-notify
|
||||
sudo python3 -m pip install --upgrade --force-reinstall .
|
||||
sudo python3 -m pip install --upgrade --index-url https://test.pypi.org/simple/ --no-deps de.p1st.exec-notify
|
||||
```
|
||||
@ -59,13 +60,13 @@ More detailed instructions about _venv_ can be found at [https://docs.python.org
|
||||
Create a _venv_:
|
||||
|
||||
```shell
|
||||
python3 -m venv ~/execNotify/venv
|
||||
python3 -m venv ~/exec-notify/venv
|
||||
```
|
||||
|
||||
Activate the venv:
|
||||
|
||||
```shell
|
||||
source ~/execNotify/venv/bin/activate
|
||||
source ~/exec-notify/venv/bin/activate
|
||||
# echo "VIRTUAL_ENV=${VIRTUAL_ENV}"
|
||||
```
|
||||
|
||||
@ -73,10 +74,10 @@ And choose one source of installation:
|
||||
|
||||
```shell
|
||||
# Install from git URL
|
||||
python3 -m pip install git+https://codeberg.org/privacy1st/execNotify
|
||||
python3 -m pip install git+https://codeberg.org/privacy1st/exec-notify
|
||||
|
||||
# Install from local directory
|
||||
python3 -m pip install ~/Downloads/git/execNotify/
|
||||
python3 -m pip install ~/Downloads/git/exec-notify/
|
||||
|
||||
# Install the module from TestPyPI
|
||||
python3 -m pip install --index-url https://test.pypi.org/simple/ --no-deps --upgrade de.p1st.exec-notify
|
||||
@ -97,10 +98,10 @@ pip list
|
||||
|
||||
## Configuration
|
||||
|
||||
Create configuration file `/etc/execNotify/cfg.ini`:
|
||||
Create configuration file `/etc/exec-notify/cfg.ini`:
|
||||
|
||||
```shell
|
||||
install -Dm0600 /etc/execNotify/cfg.ini << 'EOF'
|
||||
install -Dm0600 /etc/exec-notify/cfg.ini << 'EOF'
|
||||
[DEFAULT]
|
||||
|
||||
[mail]
|
||||
@ -116,42 +117,42 @@ maildir = /home/exampleUser/mail/
|
||||
EOF
|
||||
```
|
||||
|
||||
See also: [./etc/execNotify/cfg.ini.example](etc/execNotify/cfg.ini.example)
|
||||
See also: [./etc/exec-notify/cfg.ini.example](etc/exec-notify/cfg.ini.example)
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
### Usage of execNotify
|
||||
### Usage of exec-notify
|
||||
|
||||
Add `de-p1st-execNotify` in front of your command to execute.
|
||||
Add `exec-notify` in front of your command to execute.
|
||||
|
||||
**Example:**
|
||||
|
||||
`de-p1st-execNotify ls /non/existent/file` will mail you the exit code, stdout and stderr of `ls /non/existent/file`
|
||||
`exec-notify ls /non/existent/file` will mail you the exit code, stdout and stderr of `ls /non/existent/file`
|
||||
|
||||
### Usage of notify
|
||||
|
||||
Send stdout via mail:
|
||||
|
||||
`echo "Hello world!" | de-p1st-notify`
|
||||
`echo "Hello world!" | do-notify`
|
||||
|
||||
Send stdout and stderr via mail:
|
||||
|
||||
`echo "Hello world!" 2>&1 | de-p1st-notify`
|
||||
`echo "Hello world!" 2>&1 | do-notify`
|
||||
|
||||
Send stdout and specify an optional email subject:
|
||||
|
||||
`echo "Hello world!" | de-p1st-notify "someSubject"`
|
||||
`echo "Hello world!" | do-notify "someSubject"`
|
||||
|
||||
Send message without using a pipe:
|
||||
|
||||
`de-p1st-notify "someSubject" "Hello World! What's up?"`
|
||||
`do-notify "someSubject" "Hello World! What's up?"`
|
||||
|
||||
|
||||
## Development
|
||||
|
||||
When started with environment variable `DE_P1ST_EXEC_NOTIFY` set,
|
||||
then the configuration file is read from [./etc/execNotify/cfg.ini](etc/execNotify/cfg.ini).
|
||||
then the configuration file is read from [./etc/exec-notify/cfg.ini](etc/exec-notify/cfg.ini).
|
||||
|
||||
### Testing
|
||||
|
||||
@ -179,4 +180,4 @@ python3 -m twine upload --repository testpypi dist/*
|
||||
|
||||
6) Congratulations! You can view the uploaded module under:
|
||||
|
||||
* [https://test.pypi.org/project/de.p1st.exec_notify/](https://test.pypi.org/project/de.p1st.exec_notify/)
|
||||
* [https://test.pypi.org/project/exec_notify/](https://test.pypi.org/project/exec_notify/)
|
||||
|
12
setup.cfg
12
setup.cfg
@ -2,16 +2,16 @@
|
||||
; https://packaging.python.org/tutorials/packaging-projects/#configuring-metadata
|
||||
|
||||
[metadata]
|
||||
name = de.p1st.exec_notify
|
||||
name = exec_notify
|
||||
version = 0.1.10
|
||||
author = Daniel Langbein
|
||||
author_email = daniel@systemli.org
|
||||
description = mail notification if command fails
|
||||
description = email notification if command fails
|
||||
long_description = file: README.md
|
||||
long_description_content_type = text/markdown
|
||||
url = https://codeberg.org/privacy1st/execNotify
|
||||
url = https://codeberg.org/privacy1st/exec-notify
|
||||
project_urls =
|
||||
Bug Tracker = https://codeberg.org/privacy1st/execNotify/issues
|
||||
Bug Tracker = https://codeberg.org/privacy1st/exec-notify/issues
|
||||
|
||||
; https://pypi.org/classifiers/
|
||||
classifiers =
|
||||
@ -32,5 +32,5 @@ where = src
|
||||
[options.entry_points]
|
||||
; https://setuptools.readthedocs.io/en/latest/userguide/entry_point.html
|
||||
console_scripts=
|
||||
de-p1st-execNotify = de.p1st.exec_notify.execNotify:main
|
||||
de-p1st-notify = de.p1st.exec_notify.notify:main
|
||||
exec-notify = de.p1st.exec_notify.exec_notify:main
|
||||
do-notify = de.p1st.exec_notify.do_notify:main
|
||||
|
@ -11,13 +11,13 @@ def main():
|
||||
Send an email with some content and optionally specify an email subject.
|
||||
|
||||
Usage:
|
||||
echo <body> | de-p1st-notify
|
||||
echo <body> | do-notify
|
||||
|
||||
echo <body> | de-p1st-notify <subject>
|
||||
echo <body> | do-notify <subject>
|
||||
|
||||
de-p1st-notify <body>
|
||||
do-notify <body>
|
||||
|
||||
de-p1st-notify <subject> <body>
|
||||
do-notify <subject> <body>
|
||||
"""
|
||||
|
||||
BODY = None
|
||||
@ -25,7 +25,7 @@ def main():
|
||||
hostname = socket.gethostname()
|
||||
|
||||
if len(sys.argv) > 3:
|
||||
print('execNotify>> Expected at most two arguments!', file=sys.stderr)
|
||||
print('exec-notify>> Expected at most two arguments!', file=sys.stderr)
|
||||
exit(1)
|
||||
if len(sys.argv) == 2 or len(sys.argv) == 3:
|
||||
subj = sys.argv[1]
|
@ -11,7 +11,7 @@ from de.p1st.exec_notify.lib import exec, mail, util
|
||||
def main():
|
||||
"""
|
||||
Usage:
|
||||
de-p1st-execNotify <command>
|
||||
exec-notify <command>
|
||||
|
||||
with command = <executable> [<argument> ...]
|
||||
|
@ -23,7 +23,7 @@ def getHostAndPort() -> Tuple[str, int]:
|
||||
try:
|
||||
return LazyConfig.get('mail', 'host'), int(LazyConfig.get('mail', 'port'))
|
||||
except Exception:
|
||||
print(f'execNotify>> Could not read value [mail][host] from {_getCfgFile()}', file=stderr)
|
||||
print(f'exec-notify>> Could not read value [mail][host] from {_getCfgFile()}', file=stderr)
|
||||
traceback.print_exc()
|
||||
exit(1)
|
||||
|
||||
@ -32,7 +32,7 @@ def getPassword() -> str:
|
||||
try:
|
||||
return LazyConfig.get('mail', 'password')
|
||||
except Exception:
|
||||
print(f'execNotify>> Could not read value [mail][password] from {_getCfgFile()}', file=stderr)
|
||||
print(f'exec-notify>> Could not read value [mail][password] from {_getCfgFile()}', file=stderr)
|
||||
traceback.print_exc()
|
||||
exit(1)
|
||||
|
||||
@ -41,7 +41,7 @@ def getFrom() -> str:
|
||||
try:
|
||||
return LazyConfig.get('mail', 'from') # used for mail login as well
|
||||
except Exception:
|
||||
print(f'execNotify>> Could not read value [mail][from] from {_getCfgFile()}', file=stderr)
|
||||
print(f'exec-notify>> Could not read value [mail][from] from {_getCfgFile()}', file=stderr)
|
||||
traceback.print_exc()
|
||||
exit(1)
|
||||
|
||||
@ -50,7 +50,7 @@ def getTo() -> str:
|
||||
try:
|
||||
return LazyConfig.get('mail', 'to')
|
||||
except Exception:
|
||||
print(f'execNotify>> Could not read value [mail][to] from {_getCfgFile()}', file=stderr)
|
||||
print(f'exec-notify>> Could not read value [mail][to] from {_getCfgFile()}', file=stderr)
|
||||
traceback.print_exc()
|
||||
exit(1)
|
||||
|
||||
@ -59,7 +59,7 @@ def getMailDir() -> Path:
|
||||
try:
|
||||
return Path(LazyConfig.get('file', 'maildir'))
|
||||
except Exception:
|
||||
print(f'execNotify>> Could not read value [file][maildir] from {_getCfgFile()}', file=stderr)
|
||||
print(f'exec-notify>> Could not read value [file][maildir] from {_getCfgFile()}', file=stderr)
|
||||
traceback.print_exc()
|
||||
exit(1)
|
||||
|
||||
@ -75,6 +75,6 @@ def _getCfgFile() -> Path:
|
||||
|
||||
def _getCfgDir() -> Path:
|
||||
if util.isInDevelopment():
|
||||
return util.getProjectBase().joinpath('etc', 'execNotify')
|
||||
return util.getProjectBase().joinpath('etc', 'exec-notify')
|
||||
else:
|
||||
return PosixPath('/etc/execNotify/')
|
||||
return PosixPath('/etc/exec-notify/')
|
||||
|
@ -11,7 +11,8 @@ def execute(command: List[str]):
|
||||
|
||||
:param command: A command to executed as list of words, e.g. `['echo', 'Hello world!']`
|
||||
:return: (exit_code, stdout, stderr)
|
||||
:raises Exception: Might throw an exception.E.g. FileNotFoundError if the executable (first element of `command`) does not exist.
|
||||
:raises Exception: Might throw an exception.E.g. FileNotFoundError
|
||||
if the executable (first element of `command`) does not exist.
|
||||
"""
|
||||
|
||||
if sys.version_info.major == 3 and sys.version_info.minor < 7:
|
||||
|
@ -22,8 +22,8 @@ def sendMailOrWriteToFile(SUBJECT: str, BODY: str, informAboutLocalMail: bool =
|
||||
try:
|
||||
sendMail(SUBJECT=SUBJECT, BODY=BODY)
|
||||
except Exception as e:
|
||||
print(f'execNotify>> Could not send mail: {e}', file=sys.stderr)
|
||||
print(f'execNotify>> Writing to file instead ...', file=sys.stderr)
|
||||
print(f'exec-notify>> Could not send mail: {e}', file=sys.stderr)
|
||||
print(f'exec-notify>> Writing to file instead ...', file=sys.stderr)
|
||||
|
||||
# Instead, try to save the mail so that the user can read
|
||||
# it later when connected to this computer
|
||||
@ -85,7 +85,7 @@ def saveMail(SUBJECT: str, BODY: str):
|
||||
with open(mailFile, "a") as f:
|
||||
f.write(mailStr)
|
||||
except Exception as e:
|
||||
print(f'execNotify>> Could not write to file: {e}', file=sys.stderr)
|
||||
print(f'exec-notify>> Could not write to file: {e}', file=sys.stderr)
|
||||
|
||||
|
||||
def _localMailExists():
|
||||
|
Loading…
Reference in New Issue
Block a user