bversion/client.py
def update(session_token: str, test_overrides = None, include_unchanged = False):
    """ Compare changes on the client to changes on the server and update local files
    which have changed on the server. """

    # ===========================
    if test_overrides is None:
        testing = False
        test_overrides = {
            'resolve_to_override' : '',
            'kill_mid_update'     : 0
        }
    else:
        testing = True


    # Send the changes and the revision of the most recent update to the server to find changes
    client_changes = find_local_changes(include_unchanged)

    manifest_meta = cdb.get_system_meta()
    req_result, headers = server_connection.request("find_changed", {
        "session_token"        : session_token,
        'repository'           : config['repository'],
        "previous_revision"    : manifest_meta['have_revision'],
        "include_unchanged"    : str(int(include_unchanged))
        }, {
            "client_changes"       : json.dumps(client_changes)
        })

    if headers['status'] != 'ok':
        raise SystemExit('Server error:' + headers['msg'])

    result = json.loads(req_result)
    changes = result['sorted_changes']

    # Are there any changes?
    if all(v == [] for k,v in changes.items()):
        print('Nothing to update')
        return

    # Files which are in conflict
    if changes['conflict_files'] != []:
        changes = resolve_update_conflicts(session_token, changes, result['head'], testing, test_overrides)

    # Pull and delete from remote to local
    affected_files = {
        'pulled_files'  : [],
        'deleted_files' : [],
        'errors'        : []
    }

    if changes['client_pull_files'] != []:
        # Filter out pull ignore files
        filtered_pull_files = []
        for fle in changes['client_pull_files']:
            if not next((True for flter in config['pull_ignore_filters'] if fnmatch.fnmatch(fle['path'], flter)), False):
                filtered_pull_files.append(fle)

        if filtered_pull_files != []:
            print('Pulling files from server...')

        #----------
        pulled_items = 0
        for fle in filtered_pull_files:
            # ==============
            file_in_manifest = cdb.get_single_file_from_manifest(fle['path'])
            file_hash = fle['hash']

            # Chech we don't already have the file due to a previous run that failed mid-process
            have_file = False
            if file_in_manifest is not None and file_in_manifest['server_file_hash'] == file_hash:
                have_file = True

            # ===================
            if not have_file:
                req_result, headers = server_connection.request("pull_file", {
                    'session_token' : session_token,
                    'repository'    : config['repository'],
                    'path'          : fle['path'],
                    'use_head'      : str(int(False)),
                    'version_id'    : result['head']
                    }, gen = True)

                if headers['status'] != 'ok':
                    affected_files['errors'].append('Failed to pull file ' + fle['path'])

                else:
                    make_dirs_if_dont_exist(data_store.jfs.get_full_file_path(cpjoin(*fle['path'].split('/')[:-1]) + '/'))

                    print(colored('Pulling file: ' + fle['path'], 'green'))
                    data_store.fs_put(fle['path'], req_result, additional_manifest_data = {'server_file_hash' : file_hash})
                    affected_files['pulled_files'].append(fle['path'])

            # test override to allow testing of checkout being killed part completed
            if test_overrides['kill_mid_update'] > 0:
                if pulled_items == test_overrides['kill_mid_update']:
                    raise Exception('killed part way through update for testing')

            pulled_items += 1

    # Files which have been deleted on server and need deleting on client
    if changes['to_delete_on_client'] != []:
        print('Removing files deleted on the server...')

        for fle in changes['to_delete_on_client']:
            print(colored('Deleting file: ' + fle['path'], 'red'))

            try:
                data_store.fs_delete(fle['path'])
            except OSError:
                # If this happens, a file was deleted on the server which
                # never existed on this client, thus do nothing.
                pass

            affected_files['deleted_files'].append(fle['path'])

            # Delete the folder if it is now empty
            try: os.removedirs(os.path.dirname(data_store.jfs.get_full_file_path(fle['path'])))
            except OSError as e:
                if e.errno not in [errno.ENOTEMPTY, errno.ENOENT]: raise


    # Update the latest revision in the manifest
    manifest_meta = cdb.get_system_meta()
    manifest_meta['have_revision'] = result['head']
    cdb.update_system_meta(manifest_meta)
    cdb.commit()

    # Delete the conflicts resolution file and recursively delete any conflict files downloaded for comparison
    ignore(os.remove, config['conflict_resolution_file'])
    ignore(shutil.rmtree, config['conflict_comparison_file_root'])

    # ============================================
    for item in affected_files['errors']:
        print(item)

    # ==================
    print('\n-------------------------------\n')
    print(colored('At revision: ' + result['head'], 'yellow'))
    print('By ' + result['commit_by'] + ' on ' + result['commit_time'] + ' (UTC)')
    print('\n' + result['commit_msg'])

    # ==================
    if changes['to_delete_on_server'] != [] or changes['client_push_files'] != []:
        print('\nThere are local changes to commit')
    else:
        print('\nUpdate OK')

    return affected_files
 Compare changes on the client to changes on the server and update local files
    which have changed on the server. 
Compare changes on the client to changes on the server and update local files
which have changed on the server.
Compare changes on the client to changes on the server and update local files which have changed on the server .
def update(session_token: str, test_overrides = None, include_unchanged = False):
    if test_overrides is None:
        testing = False
        test_overrides = {
            'resolve_to_override' : '',
            'kill_mid_update'     : 0
        }
    else:
        testing = True
    client_changes = find_local_changes(include_unchanged)
    manifest_meta = cdb.get_system_meta()
    req_result, headers = server_connection.request("find_changed", {
        "session_token"        : session_token,
        'repository'           : config['repository'],
        "previous_revision"    : manifest_meta['have_revision'],
        "include_unchanged"    : str(int(include_unchanged))
        }, {
            "client_changes"       : json.dumps(client_changes)
        })
    if headers['status'] != 'ok':
        raise SystemExit('Server error:' + headers['msg'])
    result = json.loads(req_result)
    changes = result['sorted_changes']
    if all(v == [] for k,v in changes.items()):
        print('Nothing to update')
        return
    if changes['conflict_files'] != []:
        changes = resolve_update_conflicts(session_token, changes, result['head'], testing, test_overrides)
    affected_files = {
        'pulled_files'  : [],
        'deleted_files' : [],
        'errors'        : []
    }
    if changes['client_pull_files'] != []:
        filtered_pull_files = []
        for fle in changes['client_pull_files']:
            if not next((True for flter in config['pull_ignore_filters'] if fnmatch.fnmatch(fle['path'], flter)), False):
                filtered_pull_files.append(fle)
        if filtered_pull_files != []:
            print('Pulling files from server...')
        pulled_items = 0
        for fle in filtered_pull_files:
            file_in_manifest = cdb.get_single_file_from_manifest(fle['path'])
            file_hash = fle['hash']
            have_file = False
            if file_in_manifest is not None and file_in_manifest['server_file_hash'] == file_hash:
                have_file = True
            =====
            if not have_file:
                req_result, headers = server_connection.request("pull_file", {
                    'session_token' : session_token,
                    'repository'    : config['repository'],
                    'path'          : fle['path'],
                    'use_head'      : str(int(False)),
                    'version_id'    : result['head']
                    }, gen = True)
                if headers['status'] != 'ok':
                    affected_files['errors'].append('Failed to pull file ' + fle['path'])
                else:
                    make_dirs_if_dont_exist(data_store.jfs.get_full_file_path(cpjoin(*fle['path'].split('/')[:-1]) + '/'))
                    print(colored('Pulling file: ' + fle['path'], 'green'))
                    data_store.fs_put(fle['path'], req_result, additional_manifest_data = {'server_file_hash' : file_hash})
                    affected_files['pulled_files'].append(fle['path'])
            if test_overrides['kill_mid_update'] > 0:
                if pulled_items == test_overrides['kill_mid_update']:
                    raise Exception('killed part way through update for testing')
            pulled_items += 1
    if changes['to_delete_on_client'] != []:
        print('Removing files deleted on the server...')
        for fle in changes['to_delete_on_client']:
            print(colored('Deleting file: ' + fle['path'], 'red'))
            try:
                data_store.fs_delete(fle['path'])
            except OSError:
                pass
            affected_files['deleted_files'].append(fle['path'])
            try: os.removedirs(os.path.dirname(data_store.jfs.get_full_file_path(fle['path'])))
            except OSError as e:
                if e.errno not in [errno.ENOTEMPTY, errno.ENOENT]: raise
    manifest_meta = cdb.get_system_meta()
    manifest_meta['have_revision'] = result['head']
    cdb.update_system_meta(manifest_meta)
    cdb.commit()
    ignore(os.remove, config['conflict_resolution_file'])
    ignore(shutil.rmtree, config['conflict_comparison_file_root'])
    =================
    for item in affected_files['errors']:
        print(item)
    ====
    print('\n-------------------------------\n')
    print(colored('At revision: ' + result['head'], 'yellow'))
    print('By ' + result['commit_by'] + ' on ' + result['commit_time'] + ' (UTC)')
    print('\n' + result['commit_msg'])
    ====
    if changes['to_delete_on_server'] != [] or changes['client_push_files'] != []:
        print('\nThere are local changes to commit')
    else:
        print('\nUpdate OK')
    return affected_files
def update ( session_token : str , test_overrides = None , include_unchanged = False ) : if test_overrides is None : testing = False test_overrides = { 'resolve_to_override' : '' , 'kill_mid_update' : 0 } else : testing = True client_changes = find_local_changes ( include_unchanged ) manifest_meta = cdb . get_system_meta ( ) req_result , headers = server_connection . request ( "find_changed" , { "session_token" : session_token , 'repository' : config [ 'repository' ] , "previous_revision" : manifest_meta [ 'have_revision' ] , "include_unchanged" : str ( int ( include_unchanged ) ) } , { "client_changes" : json . dumps ( client_changes ) } ) if headers [ 'status' ] != 'ok' : raise SystemExit ( 'Server error:' + headers [ 'msg' ] ) result = json . loads ( req_result ) changes = result [ 'sorted_changes' ] if all ( v == [ ] for k , v in changes . items ( ) ) : print ( 'Nothing to update' ) return if changes [ 'conflict_files' ] != [ ] : changes = resolve_update_conflicts ( session_token , changes , result [ 'head' ] , testing , test_overrides ) affected_files = { 'pulled_files' : [ ] , 'deleted_files' : [ ] , 'errors' : [ ] } if changes [ 'client_pull_files' ] != [ ] : filtered_pull_files = [ ] for fle in changes [ 'client_pull_files' ] : if not next ( ( True for flter in config [ 'pull_ignore_filters' ] if fnmatch . fnmatch ( fle [ 'path' ] , flter ) ) , False ) : filtered_pull_files . append ( fle ) if filtered_pull_files != [ ] : print ( 'Pulling files from server...' ) pulled_items = 0 for fle in filtered_pull_files : file_in_manifest = cdb . get_single_file_from_manifest ( fle [ 'path' ] ) file_hash = fle [ 'hash' ] have_file = False if file_in_manifest is not None and file_in_manifest [ 'server_file_hash' ] == file_hash : have_file = True if not have_file : req_result , headers = server_connection . request ( "pull_file" , { 'session_token' : session_token , 'repository' : config [ 'repository' ] , 'path' : fle [ 'path' ] , 'use_head' : str ( int ( False ) ) , 'version_id' : result [ 'head' ] } , gen = True ) if headers [ 'status' ] != 'ok' : affected_files [ 'errors' ] . append ( 'Failed to pull file ' + fle [ 'path' ] ) else : make_dirs_if_dont_exist ( data_store . jfs . get_full_file_path ( cpjoin ( * fle [ 'path' ] . split ( '/' ) [ : - 1 ] ) + '/' ) ) print ( colored ( 'Pulling file: ' + fle [ 'path' ] , 'green' ) ) data_store . fs_put ( fle [ 'path' ] , req_result , additional_manifest_data = { 'server_file_hash' : file_hash } ) affected_files [ 'pulled_files' ] . append ( fle [ 'path' ] ) if test_overrides [ 'kill_mid_update' ] > 0 : if pulled_items == test_overrides [ 'kill_mid_update' ] : raise Exception ( 'killed part way through update for testing' ) pulled_items += 1 if changes [ 'to_delete_on_client' ] != [ ] : print ( 'Removing files deleted on the server...' ) for fle in changes [ 'to_delete_on_client' ] : print ( colored ( 'Deleting file: ' + fle [ 'path' ] , 'red' ) ) try : data_store . fs_delete ( fle [ 'path' ] ) except OSError : pass affected_files [ 'deleted_files' ] . append ( fle [ 'path' ] ) try : os . removedirs ( os . path . dirname ( data_store . jfs . get_full_file_path ( fle [ 'path' ] ) ) ) except OSError as e : if e . errno not in [ errno . ENOTEMPTY , errno . ENOENT ] : raise manifest_meta = cdb . get_system_meta ( ) manifest_meta [ 'have_revision' ] = result [ 'head' ] cdb . update_system_meta ( manifest_meta ) cdb . commit ( ) ignore ( os . remove , config [ 'conflict_resolution_file' ] ) ignore ( shutil . rmtree , config [ 'conflict_comparison_file_root' ] ) for item in affected_files [ 'errors' ] : print ( item ) print ( '\n-------------------------------\n' ) print ( colored ( 'At revision: ' + result [ 'head' ] , 'yellow' ) ) print ( 'By ' + result [ 'commit_by' ] + ' on ' + result [ 'commit_time' ] + ' (UTC)' ) print ( '\n' + result [ 'commit_msg' ] ) if changes [ 'to_delete_on_server' ] != [ ] or changes [ 'client_push_files' ] != [ ] : print ( '\nThere are local changes to commit' ) else : print ( '\nUpdate OK' ) return affected_files
Compare changes on the client to changes on the server and update local files
which have changed on the server.
Compare changes on the client to changes on the server and update local files which have changed on the server .
""" Compare changes on the client to changes on the server and update local files
    which have changed on the server. """ # =========================== # Send the changes and the revision of the most recent update to the server to find changes # Are there any changes? # Files which are in conflict # Pull and delete from remote to local # Filter out pull ignore files #---------- # ============== # Chech we don't already have the file due to a previous run that failed mid-process # =================== # test override to allow testing of checkout being killed part completed # Files which have been deleted on server and need deleting on client # If this happens, a file was deleted on the server which # never existed on this client, thus do nothing. # Delete the folder if it is now empty # Update the latest revision in the manifest # Delete the conflicts resolution file and recursively delete any conflict files downloaded for comparison # ============================================ # ================== # ==================
session_token
str
test_overrides
include_unchanged