예제 #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 mount_folder(devices=[]):
    '''
    Mount folder linked to given device.
    '''
    if len(devices) == 0:
        devices = local_config.get_default_devices()

    for name in devices:
        try:
            (url, path) = local_config.get_config(name)
            # try to create the directory if it does not exist
            try:
                os.makedirs(path)
                couchmount.unmount(path)
            except OSError as e:
                if e.errno == errno.EACCES:
                    print 'You do not have sufficient access, ' \
                          'try running sudo %s' % (' '.join(sys.argv[:]))
                    sys.exit(1)
                elif e.errno == errno.EEXIST:
                    pass
                else:
                    continue
            couchmount.mount(name, path)
        except KeyboardInterrupt:
            unmount_folder(name)
예제 #3
0
def unset_default(devices=[]):
    '''
    Remove configuration parameter for the given device, to avoid
    synchronization and mounting by default
    '''
    if len(devices) == 0:
        devices = local_config.get_default_devices()

    for name in devices:
        local_config.set_default_device_config(name, False)
예제 #4
0
def unmount_folder(devices=[], path=None):
    '''
    Unmount folder linked to given device.
    '''
    if len(devices) == 0:
        devices = local_config.get_default_devices()

    for name in devices:
        if path is None:
            (url, path) = local_config.get_config(name)
        couchmount.unmount(path)