mirror of
https://codeberg.org/privacy1st/exec-notify
synced 2024-12-22 23:16:04 +01:00
more readable mail.saveMail output
This commit is contained in:
parent
47cd16ac14
commit
76ccc6897a
@ -38,9 +38,7 @@ def executeCommand(command: List) -> int:
|
||||
print(BODY)
|
||||
|
||||
if exitCode != 0:
|
||||
hostname = socket.gethostname()
|
||||
|
||||
SUBJECT = f'{hostname} | {str(command)}'
|
||||
SUBJECT = f'{socket.gethostname()} | {str(command)}'
|
||||
mail.sendMailOrWriteToFile(SUBJECT=SUBJECT, BODY=BODY)
|
||||
|
||||
return exitCode
|
||||
|
@ -6,7 +6,7 @@ import socket
|
||||
from email.mime.text import MIMEText
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
|
||||
from de.p1st.exec_notify.lib import config
|
||||
from de.p1st.exec_notify.lib import config, util
|
||||
|
||||
|
||||
def sendMailOrWriteToFile(SUBJECT: str, BODY: str, informAboutLocalMail: bool = True):
|
||||
@ -65,13 +65,23 @@ def saveMail(SUBJECT: str, BODY: str):
|
||||
mailDir = config.getMailDir()
|
||||
mailFile = mailDir.joinpath(timeStr)
|
||||
|
||||
prefix='┃ '
|
||||
mailStr = f'┏{"━"*19}\n' \
|
||||
f'┣╸Date:\n' \
|
||||
f'{util.appendLinePrefix(prefix, timeStr)}\n' \
|
||||
f'┣╸Subject:\n' \
|
||||
f'{util.appendLinePrefix(prefix, SUBJECT)}\n' \
|
||||
f'┣╸Body:\n' \
|
||||
f'{util.appendLinePrefix(prefix, BODY)}\n' \
|
||||
f'┗{"━"*19}'
|
||||
|
||||
try:
|
||||
# create parent directory if not existent
|
||||
mailDir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# append to file; create file if not existent
|
||||
with open(mailFile, "a") as f:
|
||||
f.write(f'{"=" * 20}\n=== date ===\n{timeStr}\n=== subject ===\n{SUBJECT}\n=== body ===\n{BODY}\n')
|
||||
f.write(mailStr)
|
||||
except Exception as e:
|
||||
print(f'execNotify>> Could not write to file: {e}', file=sys.stderr)
|
||||
|
||||
|
@ -28,7 +28,7 @@ def main():
|
||||
if subj is None:
|
||||
subj = 'notify'
|
||||
if BODY is None:
|
||||
BODY = f'=== stdin ===\n{stdin.read()}'
|
||||
BODY = stdin.read()
|
||||
|
||||
SUBJECT = f'{hostname} | {subj}'
|
||||
print(BODY)
|
||||
|
Loading…
Reference in New Issue
Block a user