def test_update():
    # prepare work to be updated
    update_path = data_path / 'update'
    if update_path.is_dir(): shutil.rmtree(str(update_path))
    shutil.copytree(str(data_path / 'v1'), str(update_path))

    srcbl = (update_path / 'v1.opf' / 'base.txt').read_text()
    dstbl = (data_path / 'v2' / 'v2.opf' / 'base.txt').read_text()

    updater = Blupdate(srcbl, dstbl)

    updater.update_annotations(update_path / 'v1.opf')

    for layer in ['title', 'yigchung', 'quotes', 'tsawa', 'sapche']:
        update_result, v2_result = get_layer(layer, 'update', 'v2')
        assert update_result == v2_result
Example #2
0
def update(**kwargs):
    """
    Command to update the base text with your edits.
    """
    work_id = get_pecha_id(kwargs['work_number'])
    if work_id:
        if work_id in pecha_list():
            repo_path = config["OP_DATA_PATH"] / work_id
            repo = Repo(str(repo_path))

            # if edited branch exists, then to check for changes in edited branch
            branch_name = 'edited'
            if branch_name in repo.heads:
                current = repo.heads[branch_name]
                current.checkout()

            is_changed, srcbl, dstbl = check_edits(work_id)
            if is_changed:
                msg = f'Updating {work_id} base text.'
                click.echo(INFO.format(msg))

                # Update layer annotations
                updater = Blupdate(srcbl, dstbl)
                opfpath = repo_path / f'{work_id}.opf'
                updater.update_annotations(opfpath)

                # Update base-text
                src = get_data_path() / f'{work_id}.txt'
                dst = opfpath / 'base.txt'
                shutil.copy(str(src), str(dst))

                # Create edited branch and push to Github
                status = github_push(repo, branch_name)

                # logging
                if status:
                    msg = f'Pecha edits {work_id} are uploaded for futher validation'
                    click.echo(INFO.format(msg))
                else:
                    repo_reset(repo, branch_name)
            else:
                msg = f'There are no changes in Pecha {work_id}'
                click.echo(ERROR.format(msg))
        else:
            msg = f'{work_id} does not exits, check the work-id'
            click.echo(ERROR.format(msg))