How to use the vdirsyncer.exceptions.UserError function in vdirsyncer

To help you get started, we’ve selected a few vdirsyncer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pimutils / vdirsyncer / vdirsyncer / cli / config.py View on Github external
def parse(self):
        for section in self._parser.sections():
            if ' ' in section:
                section_type, name = section.split(' ', 1)
            else:
                section_type = name = section

            try:
                self._parse_section(
                    section_type, name,
                    dict(_parse_options(self._parser.items(section),
                                        section=section))
                )
            except ValueError as e:
                raise exceptions.UserError(
                    'Section "{}": {}'.format(section, str(e)))

        _validate_general_section(self._general)
        if getattr(self._file, 'name', None):
            self._general['status_path'] = os.path.join(
                os.path.dirname(self._file.name),
                expand_path(self._general['status_path'])
            )

        return self._general, self._pairs, self._storages
github pimutils / vdirsyncer / vdirsyncer / cli / fetchparams.py View on Github external
def _strategy_command(*command):
    import subprocess
    command = (expand_path(command[0]),) + command[1:]
    try:
        stdout = subprocess.check_output(command, universal_newlines=True)
        return stdout.strip('\n')
    except OSError as e:
        raise exceptions.UserError('Failed to execute command: {}\n{}'
                                   .format(' '.join(command), str(e)))
github pimutils / vdirsyncer / vdirsyncer / http.py View on Github external
def prepare_verify(verify, verify_fingerprint):
    if isinstance(verify, (str, bytes)):
        verify = expand_path(verify)
    elif not isinstance(verify, bool):
        raise exceptions.UserError('Invalid value for verify ({}), '
                                   'must be a path to a PEM-file or boolean.'
                                   .format(verify))

    if verify_fingerprint is not None:
        if not isinstance(verify_fingerprint, (bytes, str)):
            raise exceptions.UserError('Invalid value for verify_fingerprint '
                                       '({}), must be a string or null.'
                                       .format(verify_fingerprint))
    elif not verify:
        raise exceptions.UserError(
            'Disabling all SSL validation is forbidden. Consider setting '
            'verify_fingerprint if you have a broken or self-signed cert.'
        )

    return {
        'verify': verify,
        'verify_fingerprint': verify_fingerprint,
    }
github pimutils / vdirsyncer / vdirsyncer / storage / olddav.py View on Github external
def __init__(self, start_date=None, end_date=None,
                 item_types=(), **kwargs):
        super(CalDAVStorage, self).__init__(**kwargs)
        if not isinstance(item_types, (list, tuple)):
            raise exceptions.UserError('item_types must be a list.')

        self.item_types = tuple(item_types)
        if (start_date is None) != (end_date is None):
            raise exceptions.UserError('If start_date is given, '
                                       'end_date has to be given too.')
        elif start_date is not None and end_date is not None:
            namespace = dict(datetime.__dict__)
            namespace['start_date'] = self.start_date = \
                (eval(start_date, namespace)
                 if isinstance(start_date, (bytes, str))
                 else start_date)
            self.end_date = \
                (eval(end_date, namespace)
                 if isinstance(end_date, (bytes, str))
                 else end_date)
github pimutils / vdirsyncer / vdirsyncer / cli / config.py View on Github external
def __init__(self, general, pairs, storages):
        self.general = general
        self.storages = storages
        for name, options in storages.items():
            options['instance_name'] = name

        self.pairs = {}
        for name, options in pairs.items():
            try:
                self.pairs[name] = PairConfig(self, name, options)
            except ValueError as e:
                raise exceptions.UserError('Pair {}: {}'.format(name, e))
github pimutils / vdirsyncer / vdirsyncer / cli / config.py View on Github external
with open(a_tmp, 'w') as f:
            f.write(a.raw)
        with open(b_tmp, 'w') as f:
            f.write(b.raw)

        command[0] = expand_path(command[0])
        _check_call(command + [a_tmp, b_tmp])

        with open(a_tmp) as f:
            new_a = f.read()
        with open(b_tmp) as f:
            new_b = f.read()

        if new_a != new_b:
            raise exceptions.UserError('The two files are not completely '
                                       'equal.')
        return Item(new_a)
    finally:
        shutil.rmtree(dir)
github pimutils / vdirsyncer / vdirsyncer / sync / __init__.py View on Github external
sync_logger.info('...same content on both sides.')
            elif conflict_resolution is None:
                raise SyncConflict(ident=self.ident, href_a=meta_a.href,
                                   href_b=meta_b.href)
            elif callable(conflict_resolution):
                item_a = a.get_item_cache(self.ident)
                item_b = b.get_item_cache(self.ident)
                new_item = conflict_resolution(item_a, item_b)
                if new_item.hash != meta_a.hash:
                    Update(new_item, a).run(a, b, conflict_resolution,
                                            partial_sync)
                if new_item.hash != meta_b.hash:
                    Update(new_item, b).run(a, b, conflict_resolution,
                                            partial_sync)
            else:
                raise UserError('Invalid conflict resolution mode: {!r}'
                                .format(conflict_resolution))
github pimutils / vdirsyncer / vdirsyncer / sync.py View on Github external
sync_logger.info(u'...same content on both sides.')
            elif conflict_resolution is None:
                raise SyncConflict(ident=self.ident, href_a=meta_a.href,
                                   href_b=meta_b.href)
            elif callable(conflict_resolution):
                item_a = a.get_item_cache(self.ident)
                item_b = b.get_item_cache(self.ident)
                new_item = conflict_resolution(item_a, item_b)
                if new_item.hash != meta_a.hash:
                    Update(new_item, a).run(a, b, conflict_resolution,
                                            partial_sync)
                if new_item.hash != meta_b.hash:
                    Update(new_item, b).run(a, b, conflict_resolution,
                                            partial_sync)
            else:
                raise exceptions.UserError(
                    'Invalid conflict resolution mode: {!r}'
                    .format(conflict_resolution))
github pimutils / vdirsyncer / vdirsyncer / metasync.py View on Github external
def _resolve_conflict():
        if a == b:
            status[key] = a
        elif conflict_resolution == 'a wins':
            _a_to_b()
        elif conflict_resolution == 'b wins':
            _b_to_a()
        else:
            if callable(conflict_resolution):
                logger.warning('Custom commands don\'t work on metasync.')
            elif conflict_resolution is not None:
                raise exceptions.UserError(
                    'Invalid conflict resolution setting.'
                )
            raise MetaSyncConflict(key)