Skip to content

Commit

Permalink
Merge pull request #3 from FNNDSC/fix-inputdir-to-be-str
Browse files Browse the repository at this point in the history
fix inputdir and outputdir as str
  • Loading branch information
chhsiao1981 committed Jan 31, 2024
2 parents 413d40a + 84e8728 commit 0cd6fc2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

A ChRIS Plugin for sending email.

* rcpt: Comma separated receipients. It can be specified with `-r`, `--rcpt`, or in `[inputdir]/rcpt`
* title: Title of the email. It can be specified with `-t`, `--title`, or in `[inputdir]/title`
* content: Content of the email. It can be specified with `-c`, `--content`, or in `[inputdir]/content`.
* rcpt: Comma separated receipients. It can be specified in `[inputdir]/rcpt` , or with `-r`, `--rcpt`.
* title: Title of the email. It can be specified in `[inputdir]/title`, or with `-t`, `--title`.
* content: Content of the email. It can be specified in `[inputdir]/content`, or with `-c`, `--content`.
* sender: Sender of the email (default: `[email protected]`). It can be specified in `[inputdir]/sender`, or with `-s`, `--sender`.
* mailserver: Mail server (default: `postfix.postfix.svc.k8s.galena.fnndsc`). It can be speicified in `[inputdir]/mailserver`, or with `-m`, `--mailserver`.
* mailserver: Mail server (default: `postfix.postfix.svc.k8s.galena.fnndsc`). It can be specified in `[inputdir]/mailserver`, or with `-m`, `--mailserver`.
27 changes: 15 additions & 12 deletions mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,28 @@
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')
inputdir_str = str(inputdir)
outputdir_str = str(outputdir)
print(f'inputdir: {inputdir_str} outputdir: {outputdir_str}')
filename = os.sep.join([inputdir_str, 'rcpt'])
rcpt = _filename_or_arg(options.rcpt, filename, 'Email: no [inputdir]/rcpt and no --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_str, 'title'])
title = _filename_or_arg(options.title, filename, 'Email: no [inputdir]/title and no --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_str, 'content'])
content = _filename_or_arg(options.content, filename, 'Email: no [inputdir]/content and no --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_str, 'sender'])
sender = _filename_or_arg(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')
filename = os.sep.join([inputdir_str, 'mailserver'])
mail_server = _filename_or_arg(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):
def _arg_or_filename(arg, filename, err_msg):
if arg:
return arg

Expand All @@ -64,7 +67,7 @@ def _args_or_filename(arg, filename, err_msg):
return f.read().strip()


def _filename_or_args(arg, filename, err_msg):
def _filename_or_arg(arg, filename, err_msg):
if os.path.exists(filename):
with open(filename, 'r') as f:
return f.read().strip()
Expand Down

0 comments on commit 0cd6fc2

Please sign in to comment.