import argparse import copy import pathlib import sys from teachingdates import PROG import teachingdates.calendars as calendars import teachingdates.config as config def run(): args = config.parse_command_line() if args.debug: print("{prog}: debug: args: {a}".format(prog=PROG, a=args)) try: period_config, paper_config = config.parse_config(args.config, args) if args.debug: print("{prog}: debug: period config: {c}".format( prog=PROG, c=period_config)) print("{prog}: debug: paper config: {c}".format( prog=PROG, c=paper_config)) # priority: year on command line (defaults to current year), # year in config if period_config: args.year = ( args.config["year"] if "year" in args.config.keys() else args.year) cal = calendars.TeachingCalendar( args.year, args.period, args.paper, period_config, paper_config) print("Period = {p}".format(p=args.period)) print(cal.calendar()) print(cal.lecture_dates()) except config.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 config.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)) except config.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))