コード例 #1
0
ファイル: switch.py プロジェクト: lingbib/lingbib-app
def switch_to_dbedit(do_reset=False):
    if config.current_branch() == BRANCH_DBEDIT:
        print("Already on branch 'dbedit'.")
        return

    # fetch updates
    if not config.remote_lingbib_url_is_set():
        config.set_remote_lingbib_url()
    fetch_lingbib()

    if do_reset:
        reset_dbedit_and_switch()
    else:
        if config.branch_dbedit_exists():
            prompt_to_reset_dbedit()
        else:
            create_dbedit_and_switch()
コード例 #2
0
ファイル: update.py プロジェクト: lingbib/lingbib-app
def update_personal_db(personal_db_path, skip_backup):
    """
    Reimplementation of scripts/update_personal_db.sh.
    """
    # ensure that personal database exists
    if os.path.isfile(personal_db_path):
        info("Using '{db}' as personal database.".format(db=personal_db_path))
    else:
        error("Personal database '{db}' does not exist.".format(
              db=personal_db_path))
        exit(1)

    # force the master branch to be used
    if not config.current_branch() == defs.BRANCH_MASTER:
        info("Not currently on 'master' branch. Switching now.")
        try:
            git.checkout("master")
        except sh.ErrorReturnCode as e:
            gitout(e.stderr)
            error("Unable to switch branches. "
                  "Please fix any Git problems and try again.")
            exit(1)

    # make sure remote 'lingbib' is set
    if not config.remote_lingbib_url_is_set():
        config.set_remote_lingbib_url()
    
    # fetch updates from lingbib/master
    info("Pulling updates to master database...")
    try:
        git.pull("--rebase lingbib master".split())
    except sh.ErrorReturnCode as e:
        gitout(e.stderr)
        error("Please run 'git pull --rebase lingbib master' and resolve "
              "the conflicts, then try again.")
        exit(1)
    else:
        info("Update complete.")

    # fetch updates from remote "personal"
    # TODO
    
    # backup current personal bibfile
    if not skip_backup:
        backup_path = personal_db_path + ".old"
        try:
            sh.cp(personal_db_path, backup_path)
        except sh.ErrorReturnCode as e:
            error("Unable to make a backup of the current personal database.")
            error(e.stderr)
            exit(1)
        else:
            info("Backed up current personal database as '{old}'.".format(
                 old=backup_path))

    # invoke BibTool to merge master and personal databases, overwriting personal
    # Note: BibTool considers things that should be errors as warnings, and
    #   doesn't return an error code so for now just print warnings
    info("Merging master database with personal database.")
    try:
        cmd_status = bibtool("-r", "bibtool/personal-merge.rsc",
        personal_db_path, defs.DB_MASTER, o=personal_db_path,
        _out=handle_bibtool_output, _err=handle_bibtool_output)
    except sh.ErrorReturnCode as e:
        error("Call to BibTool failed.")
        error(e.stderr)
        exit(1)