예제 #1
0
def test_force_release_writer_lock_works(managed_tmpdir):
    repo = Repository(path=managed_tmpdir, exists=False)
    repo.init(user_name='tester', user_email='*****@*****.**', remove_old=True)
    co = repo.checkout(write=True)

    # try to release the writer lock with a process which has different uid
    with pytest.warns(ResourceWarning):
        repo.force_release_writer_lock()

    co._writer_lock == 'LOCK_AVAILABLE'
    co.close()
    # replace, but rest of object is closed
    repo._env._close_environments()
예제 #2
0
def test_cannot_operate_without_repo_init(managed_tmpdir):
    repo = Repository(path=managed_tmpdir, exists=False)

    with pytest.raises(RuntimeError):
        repo.writer_lock_held()
    with pytest.raises(RuntimeError):
        repo.checkout()
    with pytest.raises(RuntimeError):
        repo.writer_lock_held()
    with pytest.raises(RuntimeError):
        repo.log()
    with pytest.raises(RuntimeError):
        repo.summary()
    with pytest.raises(RuntimeError):
        repo.merge('fail', 'master', 'nonexistant')
    with pytest.raises(RuntimeError):
        repo.create_branch('test')
    with pytest.raises(RuntimeError):
        repo.list_branches()
    with pytest.raises(RuntimeError):
        repo.force_release_writer_lock()

    with pytest.raises(RuntimeError):
        repo.remote.add('origin', 'foo')
    with pytest.raises(RuntimeError):
        repo.remote.remove('origin')
    with pytest.raises(RuntimeError):
        repo.remote.fetch('origin', 'master')
    with pytest.raises(RuntimeError):
        repo.remote.fetch_data('origin', branch='master')
    with pytest.raises(RuntimeError):
        repo.remote.list_all()
    with pytest.raises(RuntimeError):
        repo.remote.ping('origin')
    with pytest.raises(RuntimeError):
        repo.remote.push('origin', 'master')
    with pytest.raises(RuntimeError):
        repo.remove_branch('master')

    with pytest.raises(RuntimeError):
        repo.path
    with pytest.raises(RuntimeError):
        repo.version
    with pytest.raises(RuntimeError):
        repo.writer_lock_held
    with pytest.raises(RuntimeError):
        repo.size_human
    with pytest.raises(RuntimeError):
        repo.size_nbytes

    assert repo._env.repo_is_initialized is False
예제 #3
0
파일: cli.py 프로젝트: stjordanis/hangar-py
def writer_lock_held(repo: Repository, force_release_):
    """Determine if the writer lock is held for a repository.

    Passing the ``--force-release`` flag will instantly release the writer lock,
    invalidating any process which currently holds it.
    """
    if force_release_:
        repo.force_release_writer_lock()
        click.echo(f'Success force release of writer lock.')
    else:
        if repo.writer_lock_held:
            click.echo(f'Writer lock is held.')
        else:
            click.echo(f'Writer lock is available.')
예제 #4
0
def liberate():
    """
    Release the writer lock forcefully and make the repository available for writing.

    Warning
    -------
    If another process, that has the writer lock, is writing to the repo, releasing the
    lock leads to an exception in that process. Use it carefully
    """
    repo = Repository(Path.cwd(), exists=True)
    if repo.force_release_writer_lock():
        click.echo("Writer lock released")
    else:
        click.echo("Error while attempting to release the writer lock")