diff --git a/calendar/teachingdates/app.py b/calendar/teachingdates/app.py index d306da6..b5ae874 100644 --- a/calendar/teachingdates/app.py +++ b/calendar/teachingdates/app.py @@ -3,9 +3,9 @@ import pathlib import sys -from teachingdates import PROG import teachingdates.calendars as calendars import teachingdates.config as configuration +from teachingdates import PROG def run(): @@ -14,30 +14,42 @@ print("{prog}: debug: args: {a}".format(prog=PROG, a=args)) try: - config = configuration.Configuration(args) + dates_config = configuration.Configuration(args) if args.debug: print("{prog}: debug: period config: {c}".format( - prog=PROG, c=config.get_period_config())) + prog=PROG, c=dates_config.get_period_config())) print("{prog}: debug: paper config: {c}".format( - prog=PROG, c=config.get_paper_config())) - cal = calendars.TeachingCalendar( - config.year, config.period, config.paper, - config.get_period_config(), config.get_paper_config()) + prog=PROG, c=dates_config.get_paper_config())) + cal = calendars.TeachingCalendar(dates_config.year, + dates_config.period, + dates_config.paper, + dates_config.get_period_config(), + dates_config.get_paper_config()) print("Period = {p}".format(p=args.period)) print(cal.calendar()) print(cal.lecture_dates()) - except configuration.LectureStyleError as e: - print("{prog}: error: 'lecture' style was requested but " - "{c} contains no papers for {t}.".format( - prog=PROG, c=args.config, t=args.period)) + + except configuration.ConfigurationError as e: + print("{prog}: error: failed to load configuration from " + "'{file}'.".format(prog=PROG, file=e)) + except configuration.PaperKeyError as e: + print("{prog}: error: paper '{paper}' in '{file}' is missing " + "required key '{key}'.".format(prog=PROG, + paper=e.parent, + file=e.file, + key=e.key)) + except configuration.PeriodKeyError as e: + print("{prog}: error: teaching period '{period}' in '{file}' is " + "missing required key '{key}'.".format(prog=PROG, + period=e.parent, + file=e.file, + key=e.key)) except configuration.PaperError as e: - print("{prog}: error: no entry in {c} for paper {p} ({t}).".format( - prog=PROG, c=args.config, p=args.paper, t=args.period)) + print("{prog}: error: no entry for paper '{paper}' ({period}) in " + "'{file}.'".format(prog=PROG, + file=e, + paper=args.paper, + period=args.period)) except configuration.PeriodError as e: - print("{prog}: error: no entry in {c} for teaching " - "period {p}.".format( - prog=PROG, c=args.config_file, p=args.period)) - except KeyError as e: - print("{prog}: error: teaching period {p} in {c} is missing " - "required key {k}.".format( - prog=PROG, p=args.period, c=args.config, k=e)) + print("{prog}: error: no entry for teaching period '{period}' in " + "'{file}'.".format(prog=PROG, file=e, period=args.period))