bversion/server.py
def begin_commit(request: Request, context: ConnectionContext) -> Responce:
    """ Allow a client to begin a commit and acquire the write lock """

    session_token = request.headers['session_token'].encode('utf8')
    repository    = request.headers['repository']

    #===
    current_user = have_authenticated_user(request.remote_addr, repository, session_token)
    if current_user is False: return fail(user_auth_fail_msg)

    #===
    repository_path = config['repositories'][repository]['path']

    data_store = versioned_storage(repository_path,
                                   path_override = config['repositories'][repository]['transient_db_path_override'])

    # ==
    have_lock = data_store.lock()
    if not have_lock:
        return fail(lock_fail_msg)

    else:
        context.lock = True
        def unlock():
            if context.lock is True:
                data_store.unlock()
                context.lock = False

        context.shutdown_handler = unlock

    # Commits can only take place if the committing user has the latest revision,
    # as committing from an outdated state could cause unexpected results, and may
    # have conflicts. Conflicts are resolved during a client update so they are
    # handled by the client, and a server interface for this is not needed.
    if data_store.get_head() != request.headers["previous_revision"]:
        if data_store.get_active_commit() is not None: data_store.rollback()
        return fail(need_to_update_msg)

    # if the last active commit was by the same user and ip, get the partial committed files
    # and send them back to allow resume, otherwise do rollback if needed.
    active_commit = data_store.get_active_commit()

    commit_files = {}

    if active_commit is not None:
        if active_commit['user'] == request.headers['user'] and active_commit['ip'] == request.remote_addr:
            commit_files = data_store.get_active_commit_changes()
            commit_files = [it for it in commit_files if it['status'] != 'deleted']
            data_store.begin(request.headers['user'], request.remote_addr, session_token, resume = True)

        else:
            data_store.rollback()
            data_store.begin(request.headers['user'], request.remote_addr, session_token)

    else:
        data_store.begin(request.headers['user'], request.remote_addr, session_token)

    #------------
    return success(data={'partial_commit' : commit_files})
 Allow a client to begin a commit and acquire the write lock 
Allow a client to begin a commit and acquire the write lock
Allow a client to begin a commit and acquire the write lock
def begin_commit(request: Request, context: ConnectionContext) -> Responce:
    session_token = request.headers['session_token'].encode('utf8')
    repository    = request.headers['repository']
    current_user = have_authenticated_user(request.remote_addr, repository, session_token)
    if current_user is False: return fail(user_auth_fail_msg)
    repository_path = config['repositories'][repository]['path']
    data_store = versioned_storage(repository_path,
                                   path_override = config['repositories'][repository]['transient_db_path_override'])
    have_lock = data_store.lock()
    if not have_lock:
        return fail(lock_fail_msg)
    else:
        context.lock = True
        def unlock():
            if context.lock is True:
                data_store.unlock()
                context.lock = False
        context.shutdown_handler = unlock
    if data_store.get_head() != request.headers["previous_revision"]:
        if data_store.get_active_commit() is not None: data_store.rollback()
        return fail(need_to_update_msg)
    active_commit = data_store.get_active_commit()
    commit_files = {}
    if active_commit is not None:
        if active_commit['user'] == request.headers['user'] and active_commit['ip'] == request.remote_addr:
            commit_files = data_store.get_active_commit_changes()
            commit_files = [it for it in commit_files if it['status'] != 'deleted']
            data_store.begin(request.headers['user'], request.remote_addr, session_token, resume = True)
        else:
            data_store.rollback()
            data_store.begin(request.headers['user'], request.remote_addr, session_token)
    else:
        data_store.begin(request.headers['user'], request.remote_addr, session_token)
    return success(data={'partial_commit' : commit_files})
def begin_commit ( request : Request , context : ConnectionContext ) -> Responce : session_token = request . headers [ 'session_token' ] . encode ( 'utf8' ) repository = request . headers [ 'repository' ] current_user = have_authenticated_user ( request . remote_addr , repository , session_token ) if current_user is False : return fail ( user_auth_fail_msg ) repository_path = config [ 'repositories' ] [ repository ] [ 'path' ] data_store = versioned_storage ( repository_path , path_override = config [ 'repositories' ] [ repository ] [ 'transient_db_path_override' ] ) have_lock = data_store . lock ( ) if not have_lock : return fail ( lock_fail_msg ) else : context . lock = True def unlock ( ) : if context . lock is True : data_store . unlock ( ) context . lock = False context . shutdown_handler = unlock if data_store . get_head ( ) != request . headers [ "previous_revision" ] : if data_store . get_active_commit ( ) is not None : data_store . rollback ( ) return fail ( need_to_update_msg ) active_commit = data_store . get_active_commit ( ) commit_files = { } if active_commit is not None : if active_commit [ 'user' ] == request . headers [ 'user' ] and active_commit [ 'ip' ] == request . remote_addr : commit_files = data_store . get_active_commit_changes ( ) commit_files = [ it for it in commit_files if it [ 'status' ] != 'deleted' ] data_store . begin ( request . headers [ 'user' ] , request . remote_addr , session_token , resume = True ) else : data_store . rollback ( ) data_store . begin ( request . headers [ 'user' ] , request . remote_addr , session_token ) else : data_store . begin ( request . headers [ 'user' ] , request . remote_addr , session_token ) return success ( data = { 'partial_commit' : commit_files } )
Allow a client to begin a commit and acquire the write lock
Allow a client to begin a commit and acquire the write lock
""" Allow a client to begin a commit and acquire the write lock """ #=== #=== # == # Commits can only take place if the committing user has the latest revision, # as committing from an outdated state could cause unexpected results, and may # have conflicts. Conflicts are resolved during a client update so they are # handled by the client, and a server interface for this is not needed. # if the last active commit was by the same user and ip, get the partial committed files # and send them back to allow resume, otherwise do rollback if needed. #------------
request
Request
context
ConnectionContext