def build_collection(ctx): try: conf = ctx.obj['conf'] collection = khalendar.CalendarCollection( hmethod=ctx.obj['conf']['highlight_days']['method'], default_color=ctx.obj['conf']['highlight_days']['default_color'], multiple=ctx.obj['conf']['highlight_days']['multiple'], color=ctx.obj['conf']['highlight_days']['color'], highlight_event_days=ctx.obj['conf']['default']['highlight_event_days'], locale=ctx.obj['conf']['locale']) selection = ctx.obj.get('calendar_selection', None) for name, cal in conf['calendars'].items(): if selection is None or name in ctx.obj['calendar_selection']: collection.append(khalendar.Calendar( name=name, dbpath=conf['sqlite']['path'], path=cal['path'], readonly=cal['readonly'], color=cal['color'], unicode_symbols=conf['locale']['unicode_symbols'], locale=conf['locale'], ctype=cal['type'], )) except FatalError as error: logger.fatal(error) sys.exit(1) collection._default_calendar_name = conf['default']['default_calendar'] return collection
def build_collection(ctx): try: conf = ctx.obj['conf'] selection = ctx.obj.get('calendar_selection', None) props = dict() for name, cal in conf['calendars'].items(): if selection is None or name in ctx.obj['calendar_selection']: props[name] = { 'name': name, 'path': cal['path'], 'readonly': cal['readonly'], 'color': cal['color'], 'ctype': cal['type'], } collection = khalendar.CalendarCollection( calendars=props, color=ctx.obj['conf']['highlight_days']['color'], locale=ctx.obj['conf']['locale'], dbpath=conf['sqlite']['path'], hmethod=ctx.obj['conf']['highlight_days']['method'], default_color=ctx.obj['conf']['highlight_days']['default_color'], multiple=ctx.obj['conf']['highlight_days']['multiple'], highlight_event_days=ctx.obj['conf']['default']['highlight_event_days'], ) except FatalError as error: logger.fatal(error) sys.exit(1) collection._default_calendar_name = conf['default']['default_calendar'] return collection
def build_collection(ctx): conf = ctx.obj['conf'] collection = khalendar.CalendarCollection() selection = ctx.obj.get('calendar_selection', None) for name, cal in conf['calendars'].items(): if selection is None or name in ctx.obj['calendar_selection']: collection.append( khalendar.Calendar( name=name, dbpath=conf['sqlite']['path'], path=cal['path'], readonly=cal['readonly'], color=cal['color'], unicode_symbols=conf['locale']['unicode_symbols'], local_tz=conf['locale']['local_timezone'], default_tz=conf['locale']['default_timezone'])) collection._default_calendar_name = conf['default']['default_calendar'] return collection
def main_khal(): capture_user_interruption() # setting the process title so it looks nicer in ps # shows up as 'khal' under linux and as 'python: khal (python2.7)' # under FreeBSD, which is still nicer than the default setproctitle('khal') arguments = docopt(__doc__, version=__productname__ + ' ' + __version__, options_first=False) if arguments['-c'] is None: arguments['-c'] = _find_configuration_file() if arguments['-c'] is None: sys.exit('Cannot find any config file, exiting') if arguments['-v']: logger.setLevel(logging.DEBUG) conf = ConfigParser().parse_config(arguments['-c']) # TODO use some existing lib and move all the validation from ConfigParse # into validate as well conf = validate(conf, logger) if conf is None: sys.exit('Invalid config file, exiting.') collection = khalendar.CalendarCollection() for cal in conf.calendars: if (cal.name in arguments['-a'] and arguments['-d'] == list()) or \ (cal.name not in arguments['-d'] and arguments['-a'] == list()): collection.append( khalendar.Calendar(name=cal.name, dbpath=conf.sqlite.path, path=cal.path, readonly=cal.readonly, color=cal.color, unicode_symbols=conf.locale.unicode_symbols, local_tz=conf.locale.local_timezone, default_tz=conf.locale.default_timezone)) collection._default_calendar_name = conf.default.default_calendar commands = ['agenda', 'calendar', 'new', 'interactive', 'printcalendars'] if not any([arguments[com] for com in commands]): arguments = docopt(__doc__, version=__productname__ + ' ' + __version__, argv=[conf.default.default_command] + sys.argv[1:]) # arguments[conf.default.default_command] = True # TODO if arguments['calendar']: controllers.Calendar( collection, date=arguments['DATE'], firstweekday=conf.locale.firstweekday, encoding=conf.locale.encoding, dateformat=conf.locale.dateformat, longdateformat=conf.locale.longdateformat, ) elif arguments['agenda']: controllers.Agenda( collection, date=arguments['DATE'], firstweekday=conf.locale.firstweekday, encoding=conf.locale.encoding, dateformat=conf.locale.dateformat, longdateformat=conf.locale.longdateformat, ) elif arguments['new']: controllers.NewFromString(collection, conf, arguments['DESCRIPTION']) elif arguments['interactive']: controllers.Interactive(collection, conf) elif arguments['printcalendars']: print('\n'.join(collection.names))