-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a009b4
commit 82fbac9
Showing
9 changed files
with
162 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.git/ | ||
.github/ | ||
.dockerignore | ||
Dockerfile | ||
|
||
*~ | ||
*.DS_Store | ||
*.egg-info/ | ||
__pycache__/ | ||
|
||
.docker | ||
|
||
.idea/ | ||
.vscode/ | ||
|
||
examples/ | ||
|
||
venv/ | ||
/__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
/__ | ||
|
||
*~ | ||
*.DS_Store | ||
*.egg-info/ | ||
__pycache__/ | ||
|
||
.docker | ||
|
||
.idea/ | ||
.vscode/ | ||
|
||
venv/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Python version can be changed, e.g. | ||
FROM docker.io/python:3.11.3-slim-bullseye | ||
|
||
LABEL org.opencontainers.image.authors="FNNDSC <[email protected]>" \ | ||
org.opencontainers.image.title="An email plugin" \ | ||
org.opencontainers.image.description="A ChRIS plugin for email" | ||
|
||
ARG SRCDIR=/usr/local/src/mail | ||
RUN mkdir -p ${SRCDIR} | ||
WORKDIR ${SRCDIR} | ||
|
||
COPY . . | ||
RUN pip install "." \ | ||
&& cd / && rm -rf ${SRCDIR} | ||
WORKDIR / | ||
|
||
CMD ["mail"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pl_mail | ||
========== | ||
# pl_mail | ||
|
||
A ChRIS Plugin for sending email. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#!/usr/bin/env python | ||
|
||
from pathlib import Path | ||
from argparse import ArgumentParser, Namespace | ||
|
||
import os | ||
import os.path | ||
|
||
import smtplib | ||
from email.message import EmailMessage | ||
|
||
from chris_plugin import chris_plugin | ||
from pflog import pflog | ||
|
||
|
||
parser = ArgumentParser(description='A ChRIS plugin to send email') | ||
parser.add_argument('-r', '--rcpt', type=str, required=False, default='', help='comma separated receipients. [inputdir]/rcpt if not specified in argument.') | ||
parser.add_argument('-t', '--title', type=str, required=False, default='', help='email title. [inputdir]/title if not specified in argument.') | ||
parser.add_argument('-c', '--content', type=str, required=False, default='', help='content. [inputdir]/content if not specified in argument.') | ||
|
||
parser.add_argument('-s', '--sender', type=str, required=False, default='[email protected]', help='sender (from). use [inputdir]/sender if exists.') | ||
parser.add_argument('-m', '--mailserver', type=str, required=False, default='postfix.postfix.svc.k8s.galena.fnndsc', help='email server. use [inputdir]/mailserver if exists.') | ||
|
||
|
||
@chris_plugin( | ||
parser=parser, | ||
title='A ChRIS plugin to send email', | ||
category='', # ref. https://chrisstore.co/plugins | ||
min_memory_limit='500Mi', # supported units: Mi, Gi | ||
min_cpu_limit='1000m', # millicores, e.g. "1000m" = 1 CPU core | ||
min_gpu_limit=0, # set min_gpu_limit=1 to enable GPU | ||
) | ||
@pflog.tel_logTime( | ||
event = 'email', | ||
log = 'Email', | ||
) | ||
def main(options: Namespace, inputdir: Path, outputdir: Path): | ||
filename = os.sep.join([inputdir, 'rcpt']) | ||
rcpt = _args_or_filename(options.rcpt, filename, 'Email: no --rcpt and no [inputdir]/rcpt') | ||
|
||
filename = os.sep.join([inputdir, 'title']) | ||
title = _args_or_filename(options.title, filename, 'Email: no --title and no [inputdir]/title') | ||
|
||
filename = os.sep.join([inputdir, 'content']) | ||
content = _args_or_filename(options.content, filename, 'Email: no --content and no [inputdir]/content') | ||
|
||
filename = os.sep.join([inputdir, 'sender']) | ||
sender = _filename_or_args(options.sender, filename, 'Email: no --sender and no [inputdir]/sender') | ||
|
||
filename = os.sep.join([inputdir, 'mailserver']) | ||
mail_server = _filename_or_args(options.mailserver, filename, 'Email: no --mailserver and no [inputdir]/mailserver') | ||
|
||
_send_email(title=title, content=content, recipients=rcpt, mail_server=mail_server, sender=sender) | ||
|
||
|
||
def _args_or_filename(arg, filename, err_msg): | ||
if arg: | ||
return arg | ||
|
||
if not os.path.exists(filename): | ||
raise RuntimeError(err_msg) | ||
|
||
with open(filename, 'r') as f: | ||
return f.read().strip() | ||
|
||
|
||
def _filename_or_args(filename, arg, err_msg): | ||
if os.path.exists(filename): | ||
with open(filename, 'r') as f: | ||
return f.read().strip() | ||
|
||
if arg: | ||
return arg | ||
|
||
raise RuntimeError(err_msg) | ||
|
||
|
||
def _send_email(title, content, recipients, mail_server, sender): | ||
if not recipients: | ||
raise RuntimeError('Email: no --rcpt and no [inputdir]/rcpt') | ||
|
||
msg = EmailMessage() | ||
msg['Subject'] = title | ||
msg['From'] = sender | ||
msg['To'] = recipients | ||
msg.set_content(content) | ||
|
||
s = smtplib.SMTP(mail_server) | ||
s.send_message(msg) | ||
s.quit() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,17 +6,29 @@ | |
setuptools.setup( | ||
name='pl-mail', | ||
version='0.0.1', | ||
author='', | ||
author_email='', | ||
description='', | ||
author='FNNDSC', | ||
author_email='[email protected]', | ||
description='A ChRIS plugin for email', | ||
long_description=long_description, | ||
long_description_content_type='text/markdown', | ||
url='', | ||
packages=setuptools.find_packages(exclude=['test*']), | ||
py_modules=['mail'], | ||
license='MIT', | ||
entry_points={ | ||
'console_scripts': [ | ||
'mail = mail:main', | ||
] | ||
}, | ||
install_requires=[ | ||
'chris_plugin', | ||
'pflog', | ||
], | ||
classifiers=[ | ||
'License :: OSI Approved :: MIT License', | ||
'Programming Language :: Python :: 3', | ||
'Operating System :: OS Independent', | ||
], | ||
'Topic :: Scientific/Engineering', | ||
'Topic :: Scientific/Engineering :: Bio-Informatics', | ||
'Topic :: Scientific/Engineering :: Medical Science Apps.' | ||
], | ||
) |