This commit is contained in:
Daniel Langbein 2022-05-30 20:07:26 +02:00
parent 35c41c3ff2
commit 80323e25c7
7 changed files with 25 additions and 25 deletions

View File

@ -59,9 +59,9 @@ python3 -m pip install --index-url https://test.pypi.org/simple/ --no-deps --upg
Note about usage of TestPyPI and `--no-deps`: Note about usage of TestPyPI and `--no-deps`:
> Since TestPyPI doesnt have the same packages as the live PyPI, its possible that attempting > Since TestPyPI doesn't have the same packages as the live PyPI, it's possible that attempting
> to install dependencies may fail or install something unexpected. While this package > to install dependencies may fail or install something unexpected. While this package
> doesnt have any dependencies, its a good practice to avoid installing dependencies when > doesn't have any dependencies, it's a good practice to avoid installing dependencies when
> using TestPyPI. > using TestPyPI.
(Optionally) list installed modules: (Optionally) list installed modules:

View File

@ -3,7 +3,7 @@
[metadata] [metadata]
name = de.p1st.exec_notify name = de.p1st.exec_notify
version = 0.1.6 version = 0.1.7
author = Daniel Langbein author = Daniel Langbein
author_email = daniel@systemli.org author_email = daniel@systemli.org
description = mail notification if command fails description = mail notification if command fails

View File

@ -4,7 +4,7 @@ from sys import argv
import socket import socket
from typing import List from typing import List
from de.p1st.exec_notify.lib import exec, config, mail, util from de.p1st.exec_notify.lib import exec, mail, util
def main(): def main():
@ -33,7 +33,7 @@ def executeCommand(command: List[str]) -> int:
exitCode, stdout, stderr = exec.execute(command) exitCode, stdout, stderr = exec.execute(command)
prefix='' prefix = ''
BODY = f'{""*19}\n' \ BODY = f'{""*19}\n' \
f'┣╸Command:\n' \ f'┣╸Command:\n' \
f'{util.appendLinePrefix(prefix, str(command))}\n' \ f'{util.appendLinePrefix(prefix, str(command))}\n' \

View File

@ -19,10 +19,10 @@ class LazyConfig:
return LazyConfig._config[section][key] return LazyConfig._config[section][key]
def getHostAndPort() -> Tuple[str, str]: def getHostAndPort() -> Tuple[str, int]:
try: try:
return LazyConfig.get('mail', 'host'), LazyConfig.get('mail', 'port') return LazyConfig.get('mail', 'host'), int(LazyConfig.get('mail', 'port'))
except Exception as e: except Exception:
print(f'execNotify>> Could not read value [mail][host] from {_getCfgFile()}', file=stderr) print(f'execNotify>> Could not read value [mail][host] from {_getCfgFile()}', file=stderr)
traceback.print_exc() traceback.print_exc()
exit(1) exit(1)
@ -31,7 +31,7 @@ def getHostAndPort() -> Tuple[str, str]:
def getPassword() -> str: def getPassword() -> str:
try: try:
return LazyConfig.get('mail', 'password') return LazyConfig.get('mail', 'password')
except Exception as e: except Exception:
print(f'execNotify>> Could not read value [mail][password] from {_getCfgFile()}', file=stderr) print(f'execNotify>> Could not read value [mail][password] from {_getCfgFile()}', file=stderr)
traceback.print_exc() traceback.print_exc()
exit(1) exit(1)
@ -40,7 +40,7 @@ def getPassword() -> str:
def getFrom() -> str: def getFrom() -> str:
try: try:
return LazyConfig.get('mail', 'from') # used for mail login as well return LazyConfig.get('mail', 'from') # used for mail login as well
except Exception as e: except Exception:
print(f'execNotify>> Could not read value [mail][from] from {_getCfgFile()}', file=stderr) print(f'execNotify>> Could not read value [mail][from] from {_getCfgFile()}', file=stderr)
traceback.print_exc() traceback.print_exc()
exit(1) exit(1)
@ -49,7 +49,7 @@ def getFrom() -> str:
def getTo() -> str: def getTo() -> str:
try: try:
return LazyConfig.get('mail', 'to') return LazyConfig.get('mail', 'to')
except Exception as e: except Exception:
print(f'execNotify>> Could not read value [mail][to] from {_getCfgFile()}', file=stderr) print(f'execNotify>> Could not read value [mail][to] from {_getCfgFile()}', file=stderr)
traceback.print_exc() traceback.print_exc()
exit(1) exit(1)
@ -58,7 +58,7 @@ def getTo() -> str:
def getMailDir() -> Path: def getMailDir() -> Path:
try: try:
return Path(LazyConfig.get('file', 'maildir')) return Path(LazyConfig.get('file', 'maildir'))
except Exception as e: except Exception:
print(f'execNotify>> Could not read value [file][maildir] from {_getCfgFile()}', file=stderr) print(f'execNotify>> Could not read value [file][maildir] from {_getCfgFile()}', file=stderr)
traceback.print_exc() traceback.print_exc()
exit(1) exit(1)

View File

@ -1,7 +1,7 @@
from sys import stderr import sys
import datetime import datetime
import smtplib, ssl import smtplib
import socket import ssl
from email.mime.text import MIMEText from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart from email.mime.multipart import MIMEMultipart
@ -13,8 +13,8 @@ def sendMailOrWriteToFile(SUBJECT: str, BODY: str, informAboutLocalMail: bool =
if informAboutLocalMail and _localMailExists(): if informAboutLocalMail and _localMailExists():
mailDir = config.getMailDir() mailDir = config.getMailDir()
SUBJECT=f'{SUBJECT} | UNREAD LOCAL MAIL' SUBJECT = f'{SUBJECT} | UNREAD LOCAL MAIL'
BODY=f'[!] Note [!]\n' \ BODY = f'[!] Note [!]\n' \
f'There is local mail inside {mailDir} that was not delivered previously! ' \ f'There is local mail inside {mailDir} that was not delivered previously! ' \
f'Please read and then delete it to get rid of this warning.\n\n\n' \ f'Please read and then delete it to get rid of this warning.\n\n\n' \
f'{BODY}' f'{BODY}'
@ -22,8 +22,8 @@ def sendMailOrWriteToFile(SUBJECT: str, BODY: str, informAboutLocalMail: bool =
try: try:
sendMail(SUBJECT=SUBJECT, BODY=BODY) sendMail(SUBJECT=SUBJECT, BODY=BODY)
except Exception as e: except Exception as e:
print(f'execNotify>> Could not send mail: {e}', file=stderr) print(f'execNotify>> Could not send mail: {e}', file=sys.stderr)
print(f'execNotify>> Writing to file instead ...', file=stderr) print(f'execNotify>> Writing to file instead ...', file=sys.stderr)
# Instead, try to save the mail so that the user can read # Instead, try to save the mail so that the user can read
# it later when connected to this computer # it later when connected to this computer
@ -67,7 +67,7 @@ def saveMail(SUBJECT: str, BODY: str):
mailDir = config.getMailDir() mailDir = config.getMailDir()
mailFile = mailDir.joinpath(timeStr) mailFile = mailDir.joinpath(timeStr)
prefix='' prefix = ''
mailStr = f'{""*19}\n' \ mailStr = f'{""*19}\n' \
f'┣╸Date:\n' \ f'┣╸Date:\n' \
f'{util.appendLinePrefix(prefix, timeStr)}\n' \ f'{util.appendLinePrefix(prefix, timeStr)}\n' \

View File

@ -35,5 +35,5 @@ def appendLinePrefix(prefix: str, s: str) -> str:
return prefix return prefix
result = ''.join([prefix + line for line in s.splitlines(keepends=True)]) result = ''.join([prefix + line for line in s.splitlines(keepends=True)])
if result.endswith(os.linesep): if result.endswith(os.linesep):
result+=prefix result += prefix
return result return result

View File

@ -2,7 +2,7 @@
from sys import argv, stderr, stdin from sys import argv, stderr, stdin
import socket import socket
from de.p1st.exec_notify.lib import exec, config, mail from de.p1st.exec_notify.lib import mail
def main(): def main():