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`:
> 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
> 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.
(Optionally) list installed modules:

View File

@ -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

View File

@ -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' \

View File

@ -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)

View File

@ -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,8 +13,8 @@ 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' \
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}'
@ -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=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' \

View File

@ -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

View File

@ -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():