Пример #1
1
def sync(devices=[]):
    '''
    Run continuous synchronization between CouchDB instances.
    '''
    if len(devices) == 0:
        devices = local_config.get_default_devices()

    for name in devices:
        (url, path) = local_config.get_config(name)
        (device_id, device_password) = local_config.get_device_config(name)
        (db_login, db_password) = local_config.get_db_credentials(name)

        print 'Start continuous replication from Cozy to device.'
        replication.replicate(name, url, name, device_password, device_id,
                              db_login, db_password, to_local=True)
        print 'Start continuous replication from device to Cozy.'
        replication.replicate(name, url, name, device_password, device_id,
                              db_login, db_password)

        print 'Continuous replications started.'
        print 'Running daemon for binary synchronization...'
        try:
            context = local_config.get_daemon_context(name, 'sync')
            with context:
                replication.BinaryReplication(name)
        except KeyboardInterrupt:
            print ' Binary Synchronization interrupted.'
Пример #2
0
def init_replication(name):
    '''
    Run initial replications then start continutous replication.
    Write device information in database.
    '''
    (url, path) = local_config.get_config(name)
    (device_id, password) = local_config.get_device_config(name)
    (db_login, db_password) = local_config.get_db_credentials(name)

    print 'Replication from remote to local...'
    replication.replicate(
        name, url, name, password, device_id, db_login, db_password,
        to_local=True, continuous=False, deleted=False)
    print 'Init device...'
    dbutils.init_device(name, url, path, password, device_id)
    print 'Replication from local to remote...'
    replication.replicate(
        name, url, name, password, device_id, db_login, db_password,
        to_local=False, continuous=False)

    print 'Continuous replication from remote to local setting...'
    replication.replicate(name, url, name, password, device_id,
                          db_login, db_password, to_local=True)

    print 'Continuous replication from local to remote setting...'
    replication.replicate(name, url, name, password, device_id,
                          db_login, db_password)
    print 'Metadata replications are done.'
Пример #3
0
def remove_device_remotely(name, password):
    '''
    Delete given device form target Cozy.
    '''
    (url, path) = local_config.get_config(name)
    (device_id, device_password) = local_config.get_device_config(name)
    remote.remove_device(url, device_id, password)
Пример #4
0
def remove_device_remotely(name):
    '''
    Delete given device form target Cozy.
    '''
    (url, path) = local_config.get_config(name)
    (device_id, password) = local_config.get_device_config(name)
    password = getpass.getpass('Type your Cozy password to remove your '
                               'device remotely:\n')
    remote.remove_device(url, device_id, password)
Пример #5
0
def cache_folder(device, path, add=True):
    '''
    Download target file from remote Cozy to local folder.
    '''

    # Get configuration.
    (device_url, device_mount_path) = local_config.get_config(device)
    (device_id, device_password) = local_config.get_device_config(device)
    (db_username, db_password) = local_config.get_db_credentials(device)

    # Built target device url.
    device_url = "http://%s:%s@localhost:5984/%s" % (
        db_username,
        db_password,
        device
    )

    # Ensure that path corresponds to a mounted folder.
    abs_path = os.path.abspath(path)
    device_mount_path = os.path.abspath(device_mount_path)
    device_mount_path_len = len(device_mount_path)
    device_config_path = os.path.join(local_config.CONFIG_FOLDER, device)

    if add:
        print "Start %s caching folder." % abs_path
    else:
        print "Start %s uncaching folder." % abs_path

    if abs_path[:device_mount_path_len] == device_mount_path:

        # Cache object
        binary_cache = binarycache.BinaryCache(
            device, device_config_path, device_url, device_mount_path)

        # Walk through given folder and run cache operation on each file found.
        for (dirpath, dirnames, filenames) in os.walk(abs_path):
            for filename in filenames:
                file_path = os.path.join(dirpath, filename)
                file_path = file_path[device_mount_path_len:]
                file_path = couchmount._normalize_path(file_path)

                if add:
                    binary_cache.add(file_path)
                    print "File %s successfully cached." % file_path
                else:
                    binary_cache.remove(file_path)
                    print "File %s successfully uncached." % file_path
    else:
        print 'This is not a folder synchronized with your Cozy'
Пример #6
0
def unregister_device(device):
    '''
    Remove device from local configuration, destroy corresponding database
    and unregister it from remote Cozy.
    '''
    (url, path) = local_config.get_config(device)
    (device_id, device_password) = local_config.get_device_config(device)

    print 'Cozy connection removal for %s.' % device
    local_config.remove(device)
    print '- Local configuration removed.'
    dbutils.remove_db(device)
    print '- Local files removed.'
    password = getpass.getpass('Please type the password of your Cozy:\n')
    remote.remove_device(url, device_id, password)
    print '- Remote configuration removed.'
    print 'Removal succeeded, everything clean!' % device
Пример #7
0
def sync(name):
    '''
    Run continuous synchronization between CouchDB instances.
    '''
    (url, path) = local_config.get_config(name)
    (device_id, device_password) = local_config.get_device_config(name)
    (db_login, db_password) = local_config.get_db_credentials(name)

    replication.replicate(name, url, name, device_password, device_id,
                          db_login, db_password, to_local=True)
    replication.replicate(name, url, name, device_password, device_id,
                          db_login, db_password)

    print 'Continuous replications started.'
    print 'Running daemon for binary synchronization...'
    try:
        replication.BinaryReplication(name)
    except local_config.DaemonAlreadyRunning, e:
        print e
Пример #8
0
def sync(name):
    '''
    Run continuous synchronization between CouchDB instances.
    '''
    (url, path) = local_config.get_config(name)
    (device_id, device_password) = local_config.get_device_config(name)
    (db_login, db_password) = local_config.get_db_credentials(name)

    replication.replicate(name, url, name, device_password, device_id,
                          db_login, db_password, to_local=True)
    replication.replicate(name, url, name, device_password, device_id,
                          db_login, db_password)

    print 'Continuous replications started.'
    print 'Running daemon for binary synchronization...'
    try:
        context = local_config.get_daemon_context(name, 'sync')
        with context:
            replication.BinaryReplication(name)
    except KeyboardInterrupt:
        print ' Binary Synchronization interrupted.'
Пример #9
0
def cache_file(device, path, add=True):
    '''
    Download target file from remote Cozy to local cache.
    '''

    # Get configuration.
    (device_url, device_mount_path) = local_config.get_config(device)
    (device_id, device_password) = local_config.get_device_config(device)
    (db_username, db_password) = local_config.get_db_credentials(device)

    # Built target device url.
    device_url = "http://%s:%s@localhost:5984/%s" % (
        db_username,
        db_password,
        device
    )

    # Ensure that path corresponds to a mounted file.
    abs_path = os.path.abspath(path)
    device_mount_path = os.path.abspath(device_mount_path)
    device_mount_path_len = len(device_mount_path)
    device_config_path = os.path.join(local_config.CONFIG_FOLDER, device)
    path = abs_path[device_mount_path_len:]
    path = couchmount._normalize_path(path)

    print "Start %s caching." % abs_path
    if abs_path[:device_mount_path_len] == device_mount_path:
        binary_cache = binarycache.BinaryCache(
            device, device_config_path, device_url, device_mount_path)
        if add:
            binary_cache.add(path)
            print "File %s successfully cached." % abs_path
        else:
            binary_cache.remove(path)
            print "File %s successfully uncached." % abs_path

    else:
        print "Wrong path, that doesn't match any file in your device folder"