Ejemplo n.º 1
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.')
Ejemplo n.º 2
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.')
Ejemplo n.º 3
0
Archivo: cli.py Proyecto: 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.')
Ejemplo n.º 4
0
Archivo: cli.py Proyecto: 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.')
Ejemplo n.º 5
0
Archivo: cli.py Proyecto: drkarl/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['-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:])

    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))
Ejemplo n.º 6
0
Archivo: cli.py Proyecto: okapia/khal
 def verbosity_callback(ctx, option, verbose):
     if verbose:
         logger.setLevel(logging.DEBUG)
     else:
         logger.setLevel(logging.INFO)
Ejemplo n.º 7
0
Archivo: cli.py Proyecto: 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))
Ejemplo n.º 8
0
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))
Ejemplo n.º 9
0
Archivo: cli.py Proyecto: ploth/khal
 def verbosity_callback(ctx, option, verbose):
     if verbose:
         logger.setLevel(logging.DEBUG)
     else:
         logger.setLevel(logging.INFO)