rt-send-all-reminders: Make template search directory configurable.
This commit is contained in:
parent
e55397d0f6
commit
7282ba1199
1 changed files with 13 additions and 6 deletions
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue