From 7282ba119984c56a01df7885deea6fd2a116ba80 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Tue, 15 May 2018 09:07:23 -0400 Subject: [PATCH] rt-send-all-reminders: Make template search directory configurable. --- scripts/rt-send-all-reminders | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/scripts/rt-send-all-reminders b/scripts/rt-send-all-reminders index b87c57d..5679fca 100755 --- a/scripts/rt-send-all-reminders +++ b/scripts/rt-send-all-reminders @@ -16,10 +16,8 @@ SHARE_DIR = pathlib.Path(_data_home, 'rt-auto-remind') SHARE_DIR.mkdir(parents=True, exist_ok=True) class Reminder: - def __init__(self, key, min_days, max_days, search, - date_field='Due', body_file=None, action='correspond'): - if body_file is None: - body_file = pathlib.Path(SHARE_DIR, 'templates', key + '.txt') + def __init__(self, key, min_days, max_days, search, body_file, + date_field='Due', action='correspond'): self.key = key self.min_days_diff = int(min_days) self.max_days_diff = int(max_days) @@ -42,6 +40,13 @@ class Reminder: def parse_arguments(arglist): parser = argparse.ArgumentParser() + parser.add_argument( + '--template-dir', + type=pathlib.Path, + default=SHARE_DIR / 'templates', + help="Directory to search for templates that aren't specified in the" + " YAML file (default `%(default)s`)", + ) parser.add_argument( 'yaml_files', metavar='PATH', type=pathlib.Path, @@ -56,8 +61,10 @@ def main(arglist=None, stdout=sys.stdout, stderr=sys.stderr): for yaml_path in args.yaml_files: with yaml_path.open() as yaml_file: yaml_data = yaml.safe_load(yaml_file) - for key in yaml_data: - reminder = Reminder(key, **yaml_data[key]) + for key, reminder_kwargs in yaml_data.items(): + if 'body_file' not in reminder_kwargs: + reminder_kwargs['body_file'] = args.template_dir / (key + '.txt') + reminder = Reminder(key, **reminder_kwargs) try: subprocess.run(reminder.remind_cmd(), check=True) except subprocess.CalledProcessError as error: