mirror of
https://codeberg.org/privacy1st/exec-notify
synced 2024-12-22 23:16:04 +01:00
minor improvements
This commit is contained in:
parent
10f486c5f6
commit
3ecafa19a2
@ -28,13 +28,13 @@ def executeCommand(command: List) -> int:
|
||||
|
||||
BODY = ''
|
||||
for key, value in zip(keys, values):
|
||||
BODY += '=== {} ===\n{}\n'.format(key, value)
|
||||
BODY += f'=== {key} ===\n{value}\n'
|
||||
print(BODY)
|
||||
|
||||
if exitCode != 0:
|
||||
hostname = socket.gethostname()
|
||||
|
||||
SUBJECT = '{} | {}'.format(hostname, str(command))
|
||||
SUBJECT = '{hostname} | {str(command)}'
|
||||
mail.sendMailOrWriteToFile(SUBJECT=SUBJECT, BODY=BODY)
|
||||
|
||||
return exitCode
|
||||
|
@ -10,9 +10,10 @@ from de.p1st.exec_notify.lib import config
|
||||
|
||||
|
||||
def sendMailOrWriteToFile(SUBJECT: str, BODY: str, informAboutLocalMail: bool = True):
|
||||
if informAboutLocalMail and localMailExists():
|
||||
BODY=f'[!] Note [!]\nThere is some local mail inside [file][maildir] that could not be sent previously! ' \
|
||||
f'Please read and then delete the local mail.\n\n\n' \
|
||||
if informAboutLocalMail and _localMailExists():
|
||||
SUBJECT=f'{SUBJECT} | UNREAD LOCAL MAIL'
|
||||
BODY=f'[!] Note [!]\nThere is local mail inside [file][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:
|
||||
@ -60,19 +61,21 @@ def saveMail(SUBJECT: str, BODY: str):
|
||||
time = datetime.datetime.now()
|
||||
timeStr = time.strftime('%Y%m%d_%H%M%S')
|
||||
|
||||
mailDir = config.getMailDir()
|
||||
mailFile = mailDir.joinpath(timeStr)
|
||||
|
||||
try:
|
||||
# create parent directory if not existent
|
||||
mailDir = config.getMailDir()
|
||||
mailDir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# append to file; create file if not existent
|
||||
with open(mailDir.joinpath(timeStr), "a") as f:
|
||||
with open(mailFile, "a") as f:
|
||||
f.write(f'{"=" * 20}\n=== date ===\n{timeStr}\n=== subject ===\n{SUBJECT}\n=== body ===\n{BODY}\n')
|
||||
except Exception as e:
|
||||
print(f'execNotify>> Could not write to file: {e}', file=sys.stderr)
|
||||
|
||||
|
||||
def localMailExists():
|
||||
def _localMailExists():
|
||||
"""
|
||||
:return: True if local mail exists in maildir folder. Once the mail is read the user shall delete (or move) it.
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user