How to use the vdirsyncer.utils.expand_path 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 / tests / storage / dav / _owncloud.py View on Github external
~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Using utilities from paste to wrap the PHP application into WSGI.

    :copyright: (c) 2014 Markus Unterwaditzer
    :license: MIT, see LICENSE for more details.
'''

from vdirsyncer.utils import expand_path
import subprocess
import os
import time
import pytest
import requests

owncloud_repo = expand_path(os.path.join(
    os.path.dirname(__file__), '../../../owncloud-testserver/'
))

php_sh = os.path.abspath(os.path.join(owncloud_repo, 'php.sh'))


def wait():
    for i in range(10):
        try:
            requests.get('http://127.0.0.1:8080/')
        except requests.exceptions.ConnectionError:
            time.sleep(1)
        else:
            return True
    return False
github pimutils / vdirsyncer / vdirsyncer / utils / password.py View on Github external
except RuntimeError:
        return None

    ctx = ctx.find_object(AppContext)
    if ctx is None or not ctx.config:
        return None

    try:
        command = ctx.config.general['password_command'].split()
    except KeyError:
        return None

    if not command:
        return None

    command[0] = expand_path(command[0])

    try:
        stdout = subprocess.check_output(command + [username, host],
                                         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.'
        )
github pimutils / vdirsyncer / vdirsyncer / storage / singlefile.py View on Github external
def create_collection(cls, collection, **kwargs):
        path = os.path.abspath(expand_path(kwargs['path']))

        if collection is not None:
            try:
                path = path % (collection,)
            except TypeError:
                raise ValueError('Exactly one %s required in path '
                                 'if collection is not null.')

        checkfile(path, create=True)
        kwargs['path'] = path
        kwargs['collection'] = collection
        return kwargs
github pimutils / vdirsyncer / vdirsyncer / storage / google.py View on Github external
def _save_token(token):
            checkdir(expand_path(os.path.dirname(token_file)), create=True)
            with atomic_write(token_file, mode='w', overwrite=True) as f:
                json.dump(token, f)
github pimutils / vdirsyncer / vdirsyncer / storage / singlefile.py View on Github external
def __init__(self, path, encoding='utf-8', **kwargs):
        super().__init__(**kwargs)
        path = os.path.abspath(expand_path(path))
        checkfile(path, create=False)

        self.path = path
        self.encoding = encoding
        self._at_once = False
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 / storage / singlefile.py View on Github external
def discover(cls, path, **kwargs):
        if kwargs.pop('collection', None) is not None:
            raise TypeError('collection argument must not be given.')

        path = os.path.abspath(expand_path(path))
        try:
            path_glob = path % '*'
        except TypeError:
            # If not exactly one '%s' is present, we cannot discover
            # collections because we wouldn't know which name to assign.
            raise NotImplementedError()

        placeholder_pos = path.index('%s')

        for subpath in glob.iglob(path_glob):
            if os.path.isfile(subpath):
                args = dict(kwargs)
                args['path'] = subpath

                collection_end = (
                    placeholder_pos
github pimutils / vdirsyncer / vdirsyncer / cli / config.py View on Github external
if _check_call is None:
        from subprocess import check_call as _check_call

    from ..vobject import Item

    dir = tempfile.mkdtemp(prefix='vdirsyncer-conflict.')
    try:
        a_tmp = os.path.join(dir, a_name)
        b_tmp = os.path.join(dir, b_name)

        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 / cli / utils.py View on Github external
def get_status_path(base_path, pair, collection=None, data_type=None):
    assert data_type is not None
    status_name = get_status_name(pair, collection)
    path = expand_path(os.path.join(base_path, status_name))
    if os.path.isfile(path) and data_type == 'items':
        new_path = path + '.items'
        # XXX: Legacy migration
        cli_logger.warning('Migrating statuses: Renaming {} to {}'
                           .format(path, new_path))
        os.rename(path, new_path)

    path += '.' + data_type
    return path