rt-send-all-reminders: Add --dry-run flag.
This commit is contained in:
parent
01b132a208
commit
de60b9ed56
1 changed files with 23 additions and 10 deletions
|
@ -17,7 +17,7 @@ SHARE_DIR.mkdir(parents=True, exist_ok=True)
|
|||
|
||||
class Reminder:
|
||||
def __init__(self, key, min_days, max_days, search, body_file,
|
||||
date_field='Due', action='correspond'):
|
||||
date_field='Due', action='correspond', dry_run=False):
|
||||
self.key = key
|
||||
self.min_days_diff = int(min_days)
|
||||
self.max_days_diff = int(max_days)
|
||||
|
@ -25,21 +25,32 @@ class Reminder:
|
|||
self.date_field = date_field
|
||||
self.body_file = body_file
|
||||
self.action = action
|
||||
self.dry_run = dry_run
|
||||
|
||||
def _remind_cmd(self):
|
||||
yield 'rt-auto-remind'
|
||||
if self.dry_run:
|
||||
yield '--dry-run'
|
||||
yield '--{}'.format(self.action)
|
||||
yield '--key'
|
||||
yield self.key
|
||||
yield self.date_field
|
||||
yield str(self.min_days_diff)
|
||||
yield str(self.max_days_diff)
|
||||
yield self.search
|
||||
yield str(self.body_file)
|
||||
|
||||
def remind_cmd(self):
|
||||
return [
|
||||
'rt-auto-remind', '--{}'.format(self.action),
|
||||
'--key', self.key,
|
||||
self.date_field,
|
||||
str(self.min_days_diff),
|
||||
str(self.max_days_diff),
|
||||
self.search,
|
||||
str(self.body_file),
|
||||
]
|
||||
return list(self._remind_cmd())
|
||||
|
||||
|
||||
def parse_arguments(arglist):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
'--dry-run', '-n',
|
||||
action='store_true',
|
||||
help="Pass --dry-run to rt-auto-remind",
|
||||
)
|
||||
parser.add_argument(
|
||||
'--template-dir',
|
||||
type=pathlib.Path,
|
||||
|
@ -64,6 +75,8 @@ def main(arglist=None, stdout=sys.stdout, stderr=sys.stderr):
|
|||
for key, reminder_kwargs in yaml_data.items():
|
||||
if 'body_file' not in reminder_kwargs:
|
||||
reminder_kwargs['body_file'] = args.template_dir / (key + '.txt')
|
||||
if args.dry_run:
|
||||
reminder_kwargs['dry_run'] = True
|
||||
reminder = Reminder(key, **reminder_kwargs)
|
||||
try:
|
||||
subprocess.run(reminder.remind_cmd(), check=True)
|
||||
|
|
Loading…
Reference in a new issue