From 80323e25c7428bd6699625f7ee33367cc11b306c Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Mon, 30 May 2022 20:07:26 +0200 Subject: [PATCH] v0.1.7 --- README.md | 4 ++-- setup.cfg | 2 +- src/de/p1st/exec_notify/execNotify.py | 4 ++-- src/de/p1st/exec_notify/lib/config.py | 14 +++++++------- src/de/p1st/exec_notify/lib/mail.py | 22 +++++++++++----------- src/de/p1st/exec_notify/lib/util.py | 2 +- src/de/p1st/exec_notify/notify.py | 2 +- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index ad8756b..a8a6dc9 100644 --- a/README.md +++ b/README.md @@ -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`: -> Since TestPyPI doesn’t have the same packages as the live PyPI, it’s 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 -> doesn’t have any dependencies, it’s 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. (Optionally) list installed modules: diff --git a/setup.cfg b/setup.cfg index a693209..670ae3f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,7 +3,7 @@ [metadata] name = de.p1st.exec_notify -version = 0.1.6 +version = 0.1.7 author = Daniel Langbein author_email = daniel@systemli.org description = mail notification if command fails diff --git a/src/de/p1st/exec_notify/execNotify.py b/src/de/p1st/exec_notify/execNotify.py index 2113b33..4b27364 100755 --- a/src/de/p1st/exec_notify/execNotify.py +++ b/src/de/p1st/exec_notify/execNotify.py @@ -4,7 +4,7 @@ from sys import argv import socket 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(): @@ -33,7 +33,7 @@ def executeCommand(command: List[str]) -> int: exitCode, stdout, stderr = exec.execute(command) - prefix='┃ ' + prefix = '┃ ' BODY = f'┏{"━"*19}\n' \ f'┣╸Command:\n' \ f'{util.appendLinePrefix(prefix, str(command))}\n' \ diff --git a/src/de/p1st/exec_notify/lib/config.py b/src/de/p1st/exec_notify/lib/config.py index 9ae3644..a68dbd6 100644 --- a/src/de/p1st/exec_notify/lib/config.py +++ b/src/de/p1st/exec_notify/lib/config.py @@ -19,10 +19,10 @@ class LazyConfig: return LazyConfig._config[section][key] -def getHostAndPort() -> Tuple[str, str]: +def getHostAndPort() -> Tuple[str, int]: try: - return LazyConfig.get('mail', 'host'), LazyConfig.get('mail', 'port') - except Exception as e: + 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) traceback.print_exc() exit(1) @@ -31,7 +31,7 @@ def getHostAndPort() -> Tuple[str, str]: def getPassword() -> str: try: return LazyConfig.get('mail', 'password') - except Exception as e: + except Exception: print(f'execNotify>> Could not read value [mail][password] from {_getCfgFile()}', file=stderr) traceback.print_exc() exit(1) @@ -40,7 +40,7 @@ def getPassword() -> str: def getFrom() -> str: try: 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) traceback.print_exc() exit(1) @@ -49,7 +49,7 @@ def getFrom() -> str: def getTo() -> str: try: return LazyConfig.get('mail', 'to') - except Exception as e: + except Exception: print(f'execNotify>> Could not read value [mail][to] from {_getCfgFile()}', file=stderr) traceback.print_exc() exit(1) @@ -58,7 +58,7 @@ def getTo() -> str: def getMailDir() -> Path: try: 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) traceback.print_exc() exit(1) diff --git a/src/de/p1st/exec_notify/lib/mail.py b/src/de/p1st/exec_notify/lib/mail.py index 6291edd..560cf05 100644 --- a/src/de/p1st/exec_notify/lib/mail.py +++ b/src/de/p1st/exec_notify/lib/mail.py @@ -1,7 +1,7 @@ -from sys import stderr +import sys import datetime -import smtplib, ssl -import socket +import smtplib +import ssl from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart @@ -13,17 +13,17 @@ def sendMailOrWriteToFile(SUBJECT: str, BODY: str, informAboutLocalMail: bool = if informAboutLocalMail and _localMailExists(): mailDir = config.getMailDir() - SUBJECT=f'{SUBJECT} | UNREAD LOCAL MAIL' - BODY=f'[!] Note [!]\n' \ - 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'{BODY}' + SUBJECT = f'{SUBJECT} | UNREAD LOCAL MAIL' + BODY = f'[!] Note [!]\n' \ + 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'{BODY}' try: sendMail(SUBJECT=SUBJECT, BODY=BODY) except Exception as e: - print(f'execNotify>> Could not send mail: {e}', file=stderr) - print(f'execNotify>> Writing to file instead ...', file=stderr) + print(f'execNotify>> Could not send mail: {e}', file=sys.stderr) + print(f'execNotify>> 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 @@ -67,7 +67,7 @@ def saveMail(SUBJECT: str, BODY: str): mailDir = config.getMailDir() mailFile = mailDir.joinpath(timeStr) - prefix='┃ ' + prefix = '┃ ' mailStr = f'┏{"━"*19}\n' \ f'┣╸Date:\n' \ f'{util.appendLinePrefix(prefix, timeStr)}\n' \ diff --git a/src/de/p1st/exec_notify/lib/util.py b/src/de/p1st/exec_notify/lib/util.py index d378ce5..4287c35 100644 --- a/src/de/p1st/exec_notify/lib/util.py +++ b/src/de/p1st/exec_notify/lib/util.py @@ -35,5 +35,5 @@ def appendLinePrefix(prefix: str, s: str) -> str: return prefix result = ''.join([prefix + line for line in s.splitlines(keepends=True)]) if result.endswith(os.linesep): - result+=prefix + result += prefix return result diff --git a/src/de/p1st/exec_notify/notify.py b/src/de/p1st/exec_notify/notify.py index bb2e01b..c3bb09b 100755 --- a/src/de/p1st/exec_notify/notify.py +++ b/src/de/p1st/exec_notify/notify.py @@ -2,7 +2,7 @@ from sys import argv, stderr, stdin import socket -from de.p1st.exec_notify.lib import exec, config, mail +from de.p1st.exec_notify.lib import mail def main():