def addentry(filepath): # autogen keys bibtool('-r', "bibtool/keygen.rsc", filepath, o=filepath) # merge with master database bibtool("-r", "bibtool/sanitize.rsc", filepath, defs.DB_MASTER, o=defs.DB_MASTER) # Update macro and refs file bibtool("-r", "bibtool/ref-extraction.rsc", defs.DB_MASTER, o="MacrosAndRefs.txt") # Then stage the new changes git.add(defs.DB_MASTER)
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)