Example #1
0
    def test_extra_sections(self, tmpdir):
        config = """
[calendars]
[[home]]
path = ~/.khal/calendars/home/
color = dark blue
unknown = 42
[unknownsection]
foo = bar
"""
        conf_path = str(tmpdir.join('old.conf'))
        with open(conf_path, 'w+') as conf:
            conf.write(config)
        get_config(conf_path)
Example #2
0
    def test_extra_sections(self, tmpdir):
        config = """
[calendars]
[[home]]
path = ~/.khal/calendars/home/
color = dark blue
unknown = 42
[unknownsection]
foo = bar
"""
        conf_path = str(tmpdir.join('old.conf'))
        with open(conf_path, 'w+') as conf:
            conf.write(config)
        get_config(conf_path)
Example #3
0
 def test_simple_config(self):
     config = get_config(
         PATH + 'simple.conf',
         _get_color_from_vdir=lambda x: None,
         _get_vdir_type=lambda x: 'calendar',
     )
     comp_config = {
         'calendars': {
             'home': {
                 'path': os.path.expanduser('~/.calendars/home/'),
                 'readonly': False,
                 'color': None,
                 'type': 'calendar'
             },
             'work': {
                 'path': os.path.expanduser('~/.calendars/work/'),
                 'readonly': False,
                 'color': None,
                 'type': 'calendar'
             },
         },
         'sqlite': {
             'path': os.path.expanduser('~/.local/share/khal/khal.db')
         },
         'locale': LOCALE_BERLIN,
         'default': {
             'default_calendar': None,
             'print_new': 'False',
             'highlight_event_days': False,
             'timedelta': dt.timedelta(days=2),
             'show_all_days': False
         }
     }
     for key in comp_config:
         assert config[key] == comp_config[key]
Example #4
0
 def test_simple_config(self):
     config = get_config(
         PATH + 'simple.conf',
         _get_color_from_vdir=lambda x: None,
         _get_vdir_type=lambda x: 'calendar',
     )
     comp_config = {
         'calendars': {
             'home': {'path': os.path.expanduser('~/.calendars/home/'),
                      'readonly': False, 'color': None, 'priority': 10, 'type': 'calendar'},
             'work': {'path': os.path.expanduser('~/.calendars/work/'),
                      'readonly': False, 'color': None, 'priority': 10, 'type': 'calendar'},
         },
         'sqlite': {'path': os.path.expanduser('~/.local/share/khal/khal.db')},
         'locale': LOCALE_BERLIN,
         'default': {
             'default_calendar': None,
             'print_new': 'False',
             'highlight_event_days': False,
             'timedelta': dt.timedelta(days=2),
             'show_all_days': False,
         }
     }
     for key in comp_config:
         assert config[key] == comp_config[key]
Example #5
0
 def test_simple_config(self):
     config = get_config(PATH + 'simple.conf')
     comp_config = {
         'calendars': {
             'home': {'path': os.path.expanduser('~/.calendars/home/'),
                      'readonly': False, 'color': None, 'type': 'calendar'},
             'work': {'path': os.path.expanduser('~/.calendars/work/'),
                      'readonly': False, 'color': None, 'type': 'calendar'},
         },
         'sqlite': {'path': os.path.expanduser('~/.local/share/khal/khal.db')},
         'locale': {
             'local_timezone': pytz.timezone('Europe/Berlin'),
             'default_timezone': pytz.timezone('Europe/Berlin'),
             'timeformat': '%H:%M',
             'dateformat': '%d.%m.',
             'longdateformat': '%d.%m.%Y',
             'datetimeformat': '%d.%m. %H:%M',
             'longdatetimeformat': '%d.%m.%Y %H:%M',
             'firstweekday': 0,
             'unicode_symbols': True,
             'weeknumbers': False,
         },
         'default': {
             'default_command': 'calendar',
             'default_calendar': None,
             'show_all_days': False,
             'print_new': 'False',
             'days': 2,
             'highlight_event_days': False
         }
     }
     for key in comp_config:
         assert config[key] == comp_config[key]
Example #6
0
 def test_small(self):
     config = get_config(PATH + 'small.conf')
     assert config == {
         'calendars': {
             'home': {'path': os.path.expanduser('~/.calendars/home/'), 'color': 'dark green', 'readonly': False},
             'work': {'path': os.path.expanduser('~/.calendars/work/'), 'readonly': True, 'color': ''}},
         'sqlite': {'path': os.path.expanduser('~/.local/share/khal/khal.db')},
         'locale': {
             'local_timezone': get_localzone(),
             'default_timezone': get_localzone(),
             'timeformat': '%H:%M',
             'dateformat': '%d.%m.',
             'longdateformat': '%d.%m.%Y',
             'datetimeformat': '%d.%m. %H:%M',
             'longdatetimeformat': '%d.%m.%Y %H:%M',
             'firstweekday': 0,
             'encoding': 'utf-8',
             'unicode_symbols': True,
         },
         'default': {
             'default_command': 'calendar',
             'debug': False,
             'default_calendar': 'home',
         }
     }
Example #7
0
 def test_small(self):
     config = get_config(PATH + 'small.conf')
     comp_config = {
         'calendars': {
             'home': {'path': os.path.expanduser('~/.calendars/home/'),
                      'color': 'dark green', 'readonly': False,
                      'type': 'calendar'},
             'work': {'path': os.path.expanduser('~/.calendars/work/'),
                      'readonly': True, 'color': '',
                      'type': 'calendar'}},
         'sqlite': {'path': os.path.expanduser('~/.local/share/khal/khal.db')},
         'locale': {
             'local_timezone': get_localzone(),
             'default_timezone': get_localzone(),
             'timeformat': '%H:%M',
             'dateformat': '%d.%m.',
             'longdateformat': '%d.%m.%Y',
             'datetimeformat': '%d.%m. %H:%M',
             'longdatetimeformat': '%d.%m.%Y %H:%M',
             'firstweekday': 0,
             'encoding': 'utf-8',
             'unicode_symbols': True,
             'weeknumbers': False,
         },
         'default': {
             'default_calendar': None,
             'default_command': 'calendar',
             'print_new': 'False',
             'show_all_days': False,
             'days': 2,
         }
     }
     for key in comp_config:
         assert config[key] == comp_config[key]
Example #8
0
    def test_old_config(self, tmpdir):
        old_config = """
[Calendar home]
path: ~/.khal/calendars/home/
color: dark blue
[sqlite]
path: ~/.khal/khal.db
[locale]
timeformat: %H:%M
dateformat: %d.%m.
longdateformat: %d.%m.%Y
[default]
"""
        conf_path = str(tmpdir.join('old.conf'))
        with open(conf_path, 'w+') as conf:
            conf.write(old_config)
        with pytest.raises(CannotParseConfigFileError):
            get_config(conf_path)
Example #9
0
    def test_old_config(self, tmpdir):
        old_config = """
[Calendar home]
path: ~/.khal/calendars/home/
color: dark blue
[sqlite]
path: ~/.khal/khal.db
[locale]
timeformat: %H:%M
dateformat: %d.%m.
longdateformat: %d.%m.%Y
[default]
"""
        conf_path = str(tmpdir.join('old.conf'))
        with open(conf_path, 'w+') as conf:
            conf.write(old_config)
        with pytest.raises(CannotParseConfigFileError):
            get_config(conf_path)
Example #10
0
 def test_small(self):
     config = get_config(
         PATH + 'small.conf',
         _get_color_from_vdir=lambda x: None,
         _get_vdir_type=lambda x: 'calendar',
     )
     comp_config = {
         'calendars': {
             'home': {
                 'path': os.path.expanduser('~/.calendars/home/'),
                 'color': 'dark green',
                 'readonly': False,
                 'priority': 20,
                 'type': 'calendar'
             },
             'work': {
                 'path': os.path.expanduser('~/.calendars/work/'),
                 'readonly': True,
                 'color': None,
                 'priority': 10,
                 'type': 'calendar'
             }
         },
         'sqlite': {
             'path': os.path.expanduser('~/.local/share/khal/khal.db')
         },
         'locale': {
             'local_timezone': get_localzone(),
             'default_timezone': get_localzone(),
             'timeformat': '%X',
             'dateformat': '%x',
             'longdateformat': '%x',
             'datetimeformat': '%c',
             'longdatetimeformat': '%c',
             'firstweekday': 0,
             'unicode_symbols': True,
             'weeknumbers': False,
         },
         'default': {
             'default_calendar': None,
             'print_new': 'False',
             'highlight_event_days': False,
             'timedelta': dt.timedelta(days=2),
             'default_event_duration': dt.timedelta(days=1),
             'default_dayevent_duration': dt.timedelta(hours=1),
             'show_all_days': False
         }
     }
     for key in comp_config:
         assert config[key] == comp_config[key]
Example #11
0
    def test_default_calendar_readonly(self, tmpdir):
        config = """
[calendars]
[[home]]
path = ~/.khal/calendars/home/
color = dark blue
readonly = True
[default]
default_calendar = home
"""
        conf_path = str(tmpdir.join('old.conf'))
        with open(conf_path, 'w+') as conf:
            conf.write(config)
        with pytest.raises(InvalidSettingsError):
            config_checks(get_config(conf_path))
Example #12
0
File: cli.py Project: ploth/khal
def prepare_context(ctx, config):
    assert ctx.obj is None

    ctx.obj = {}
    try:
        ctx.obj['conf'] = conf = get_config(config)
    except InvalidSettingsError:
        sys.exit(1)

    logger.debug('khal %s' % __version__)
    logger.debug('Using config:')
    logger.debug(stringify_conf(conf))

    if conf is None:
        raise click.UsageError('Invalid config file, exiting.')
Example #13
0
    def test_default_calendar_readonly(self, tmpdir):
        config = """
[calendars]
[[home]]
path = ~/.khal/calendars/home/
color = dark blue
readonly = True
[default]
default_calendar = home
"""
        conf_path = str(tmpdir.join('old.conf'))
        with open(conf_path, 'w+') as conf:
            conf.write(config)
        with pytest.raises(InvalidSettingsError):
            config_checks(get_config(conf_path))
Example #14
0
File: cli.py Project: okapia/khal
def prepare_context(ctx, config):
    assert ctx.obj is None

    ctx.obj = {}
    try:
        ctx.obj['conf'] = conf = get_config(config)
    except InvalidSettingsError:
        sys.exit(1)

    logger.debug('khal %s' % __version__)
    logger.debug('Using config:')
    logger.debug(to_unicode(stringify_conf(conf), 'utf-8'))

    if conf is None:
        raise click.UsageError('Invalid config file, exiting.')
Example #15
0
def prepare_context(ctx, config):
    assert ctx.obj is None

    logger.debug('khal %s' % __version__)
    try:
        conf = get_config(config)
    except NoConfigFile:
        conf = _NoConfig()
    except InvalidSettingsError:
        sys.exit(1)
    else:
        logger.debug('Using config:')
        logger.debug(stringify_conf(conf))

    ctx.obj = {'conf_path': config, 'conf': conf}
Example #16
0
 def test_simple_config(self):
     config = get_config(
         PATH + 'simple.conf',
         _get_color_from_vdir=lambda x: None,
         _get_vdir_type=lambda x: 'calendar',
     )
     comp_config = {
         'calendars': {
             'home': {
                 'path': os.path.expanduser('~/.calendars/home/'),
                 'readonly': False,
                 'color': None,
                 'type': 'calendar'
             },
             'work': {
                 'path': os.path.expanduser('~/.calendars/work/'),
                 'readonly': False,
                 'color': None,
                 'type': 'calendar'
             },
         },
         'sqlite': {
             'path': os.path.expanduser('~/.local/share/khal/khal.db')
         },
         'locale': {
             'local_timezone': pytz.timezone('Europe/Berlin'),
             'default_timezone': pytz.timezone('Europe/Berlin'),
             'timeformat': '%H:%M',
             'dateformat': '%d.%m.',
             'longdateformat': '%d.%m.%Y',
             'datetimeformat': '%d.%m. %H:%M',
             'longdatetimeformat': '%d.%m.%Y %H:%M',
             'firstweekday': 0,
             'unicode_symbols': True,
             'weeknumbers': False,
         },
         'default': {
             'default_command': 'calendar',
             'default_calendar': None,
             'print_new': 'False',
             'highlight_event_days': False,
             'timedelta': '2d',
             'show_all_days': False
         }
     }
     for key in comp_config:
         assert config[key] == comp_config[key]
Example #17
0
 def test_small(self):
     config = get_config(PATH + 'small.conf')
     comp_config = {
         'calendars': {
             'home': {
                 'path': os.path.expanduser('~/.calendars/home/'),
                 'color': 'dark green',
                 'readonly': False,
                 'type': 'calendar'
             },
             'work': {
                 'path': os.path.expanduser('~/.calendars/work/'),
                 'readonly': True,
                 'color': '',
                 'type': 'calendar'
             }
         },
         'sqlite': {
             'path': os.path.expanduser('~/.local/share/khal/khal.db')
         },
         'locale': {
             'local_timezone': get_localzone(),
             'default_timezone': get_localzone(),
             'timeformat': '%H:%M',
             'dateformat': '%d.%m.',
             'longdateformat': '%d.%m.%Y',
             'datetimeformat': '%d.%m. %H:%M',
             'longdatetimeformat': '%d.%m.%Y %H:%M',
             'firstweekday': 0,
             'encoding': 'utf-8',
             'unicode_symbols': True,
             'weeknumbers': False,
         },
         'default': {
             'default_calendar': None,
             'default_command': 'calendar',
             'print_new': 'False',
             'show_all_days': False,
             'days': 2,
             'highlight_event_days': False
         }
     }
     for key in comp_config:
         assert config[key] == comp_config[key]
Example #18
0
def prepare_context(ctx, config, verbose):
    if ctx.obj is not None:
        return

    if verbose:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)

    ctx.obj = {}
    try:
        ctx.obj['conf'] = conf = get_config(config)
    except InvalidSettingsError:
        sys.exit(1)

    logger.debug('Using config:')
    logger.debug(to_unicode(stringify_conf(conf), 'utf-8'))

    if conf is None:
        raise click.UsageError('Invalid config file, exiting.')
Example #19
0
def prepare_context(ctx, config, verbose):
    if ctx.obj is not None:
        return

    if verbose:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)

    ctx.obj = {}
    try:
        ctx.obj['conf'] = conf = get_config(config)
    except InvalidSettingsError:
        sys.exit(1)

    logger.debug('Using config:')
    logger.debug(to_unicode(stringify_conf(conf), 'utf-8'))

    if conf is None:
        raise click.UsageError('Invalid config file, exiting.')
Example #20
0
File: cli.py Project: gunendu/khal
def prepare_context(ctx, config, verbose):
    if ctx.obj is not None:
        return

    if verbose:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)

    ctx.obj = {}
    try:
        ctx.obj['conf'] = conf = get_config(config)
    except InvalidSettingsError:
        sys.exit(1)

    out = StringIO()
    conf.write(out)
    logger.debug('Using config:')
    logger.debug(out.getvalue())

    if conf is None:
        raise click.UsageError('Invalid config file, exiting.')
Example #21
0
File: cli.py Project: gunendu/khal
def prepare_context(ctx, config, verbose):
    if ctx.obj is not None:
        return

    if verbose:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)

    ctx.obj = {}
    try:
        ctx.obj['conf'] = conf = get_config(config)
    except InvalidSettingsError:
        sys.exit(1)

    out = StringIO()
    conf.write(out)
    logger.debug('Using config:')
    logger.debug(out.getvalue())

    if conf is None:
        raise click.UsageError('Invalid config file, exiting.')
Example #22
0
 def test_small(self):
     config = get_config(
         PATH + 'small.conf',
         _get_color_from_vdir=lambda x: None,
         _get_vdir_type=lambda x: 'calendar',
     )
     comp_config = {
         'calendars': {
             'home': {'path': os.path.expanduser('~/.calendars/home/'),
                      'color': 'dark green', 'readonly': False, 'priority': 20,
                      'type': 'calendar'},
             'work': {'path': os.path.expanduser('~/.calendars/work/'),
                      'readonly': True, 'color': None, 'priority': 10,
                      'type': 'calendar'}},
         'sqlite': {'path': os.path.expanduser('~/.local/share/khal/khal.db')},
         'locale': {
             'local_timezone': get_localzone(),
             'default_timezone': get_localzone(),
             'timeformat': '%X',
             'dateformat': '%x',
             'longdateformat': '%x',
             'datetimeformat': '%c',
             'longdatetimeformat': '%c',
             'firstweekday': 0,
             'unicode_symbols': True,
             'weeknumbers': False,
         },
         'default': {
             'default_calendar': None,
             'print_new': 'False',
             'highlight_event_days': False,
             'timedelta': dt.timedelta(days=2),
             'show_all_days': False
         }
     }
     for key in comp_config:
         assert config[key] == comp_config[key]
Example #23
0
 def test_small(self):
     config = get_config(PATH + 'small.conf')
     assert config == {
         'calendars': {
             'home': {
                 'path': os.path.expanduser('~/.calendars/home/'),
                 'color': 'dark green',
                 'readonly': False
             },
             'work': {
                 'path': os.path.expanduser('~/.calendars/work/'),
                 'readonly': True,
                 'color': ''
             }
         },
         'sqlite': {
             'path': os.path.expanduser('~/.local/share/khal/khal.db')
         },
         'locale': {
             'local_timezone': get_localzone(),
             'default_timezone': get_localzone(),
             'timeformat': '%H:%M',
             'dateformat': '%d.%m.',
             'longdateformat': '%d.%m.%Y',
             'datetimeformat': '%d.%m. %H:%M',
             'longdatetimeformat': '%d.%m.%Y %H:%M',
             'firstweekday': 0,
             'encoding': 'utf-8',
             'unicode_symbols': True,
         },
         'default': {
             'default_command': 'calendar',
             'debug': False,
             'default_calendar': 'home',
         }
     }
Example #24
0
 def test_nocalendars(self):
     with pytest.raises(InvalidSettingsError):
         get_config(PATH + 'nocalendars.conf')
Example #25
0
 def _init_config(self):
     self.config = get_config(self.config_path)
     self.collection = build_collection(self.config, None)
     self.datetimeformat = self.config["locale"]["datetimeformat"]
Example #26
0
 def test_one_level_calendar(self):
     with pytest.raises(InvalidSettingsError):
         get_config(PATH + 'one_level_calendars.conf')
Example #27
0
 def test_one_level_calendar(self):
     with pytest.raises(InvalidSettingsError):
         get_config(PATH + 'one_level_calendars.conf')
Example #28
0
 def test_nocalendars(self):
     with pytest.raises(InvalidSettingsError):
         get_config(PATH + 'nocalendars.conf')
Example #29
0
 def test_nocalendars(self):
     with pytest.raises(ValueError):
         get_config(PATH + 'nocalendars.conf')
Example #30
0
File: cli.py Project: clook/khal
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['-v']:
        logger.setLevel(logging.DEBUG)
    logger.debug('this is {} version {}'.format(__productname__, __version__))

    conf = get_config(arguments['-c'])

    out = StringIO.StringIO()
    conf.write(out)
    logger.debug('using config:')
    logger.debug(out.getvalue())

    collection = khalendar.CalendarCollection()

    for name, cal in conf['calendars'].items():
        if (name in arguments['-a'] and arguments['-d'] == list()) or \
           (name not in arguments['-d'] and arguments['-a'] == list()):
            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']
    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:])

    days = int(arguments['--days']) if arguments['--days'] else None
    events = int(arguments['--events']) if arguments['--events'] else None

    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'],
                             days=days,
                             events = events)
    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'],
                           days=days,
                           events=events)
    elif arguments['new']:
        controllers.NewFromString(collection, conf, arguments['DESCRIPTION'])
    elif arguments['interactive']:
        controllers.Interactive(collection, conf)
    elif arguments['printcalendars']:
        print('\n'.join(collection.names))
Example #31
0
 def _init_config(self):
     self.config = get_config(self.config_path)
     self.collection = build_collection(self.config, None)
     self.datetimeformat = self.config["locale"]["datetimeformat"]