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 = ''
|
BODY = ''
|
||||||
for key, value in zip(keys, values):
|
for key, value in zip(keys, values):
|
||||||
BODY += '=== {} ===\n{}\n'.format(key, value)
|
BODY += f'=== {key} ===\n{value}\n'
|
||||||
print(BODY)
|
print(BODY)
|
||||||
|
|
||||||
if exitCode != 0:
|
if exitCode != 0:
|
||||||
hostname = socket.gethostname()
|
hostname = socket.gethostname()
|
||||||
|
|
||||||
SUBJECT = '{} | {}'.format(hostname, str(command))
|
SUBJECT = '{hostname} | {str(command)}'
|
||||||
mail.sendMailOrWriteToFile(SUBJECT=SUBJECT, BODY=BODY)
|
mail.sendMailOrWriteToFile(SUBJECT=SUBJECT, BODY=BODY)
|
||||||
|
|
||||||
return exitCode
|
return exitCode
|
||||||
|
@ -10,9 +10,10 @@ from de.p1st.exec_notify.lib import config
|
|||||||
|
|
||||||
|
|
||||||
def sendMailOrWriteToFile(SUBJECT: str, BODY: str, informAboutLocalMail: bool = True):
|
def sendMailOrWriteToFile(SUBJECT: str, BODY: str, informAboutLocalMail: bool = True):
|
||||||
if informAboutLocalMail and localMailExists():
|
if informAboutLocalMail and _localMailExists():
|
||||||
BODY=f'[!] Note [!]\nThere is some local mail inside [file][maildir] that could not be sent previously! ' \
|
SUBJECT=f'{SUBJECT} | UNREAD LOCAL MAIL'
|
||||||
f'Please read and then delete the local mail.\n\n\n' \
|
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}'
|
f'{BODY}'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -60,19 +61,21 @@ def saveMail(SUBJECT: str, BODY: str):
|
|||||||
time = datetime.datetime.now()
|
time = datetime.datetime.now()
|
||||||
timeStr = time.strftime('%Y%m%d_%H%M%S')
|
timeStr = time.strftime('%Y%m%d_%H%M%S')
|
||||||
|
|
||||||
|
mailDir = config.getMailDir()
|
||||||
|
mailFile = mailDir.joinpath(timeStr)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# create parent directory if not existent
|
# create parent directory if not existent
|
||||||
mailDir = config.getMailDir()
|
|
||||||
mailDir.mkdir(parents=True, exist_ok=True)
|
mailDir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
# append to file; create file if not existent
|
# 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')
|
f.write(f'{"=" * 20}\n=== date ===\n{timeStr}\n=== subject ===\n{SUBJECT}\n=== body ===\n{BODY}\n')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f'execNotify>> Could not write to file: {e}', file=sys.stderr)
|
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.
|
: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