Пример #1
0
 def post_update(self, local=False, rebuild=False):
     """强制更新数据库数据
     """
     user_id = unicode(request.me["id"])
     with db_session:
         u = model.BlogUser.get(user_id=user_id)
         if not u:
             abort(404)
         repo_url = u.article_repo
         old_commit = u.latest_commit
     if rebuild:
         clear_db(user_id)
         old_commit = ""
     msg = "local"
     err = None
     if not local:
         __, owner, __ = gitutil.parse_giturl(repo_url)
         err, ret = update_local(repo_url, owner)
         msg = err.message if err else ret
     if not err:
         mddir = get_mddir(repo_url)
         update_db(mddir, user_id, old_commit)
         logs = gitutil.git_log(mddir)
         if logs:
             latest_commit = logs[0][0]
             with db_session:
                 u = model.BlogUser.get(user_id=user_id)
                 u.latest_commit = latest_commit
     return {"message": msg, "success": bool(not err)}
Пример #2
0
def get_mddir(repo_url, dest=None):
    if dest is None:
        dest = current_app.config["ARTICLE_DEST"]
    host, owner, repo = gitutil.parse_giturl(repo_url)
    return os.path.join(dest, owner, repo)