使用metaweblog API实现通用博客发布 之 版本控制

接上一篇本地图片自动上传以及替换路径,继续解决使用API发布博客的版本控制问题。

当本地文档修订更新以后,如何发现版本更新,并自动发布到博客呢?我的解决方案是使用同一的git版本控制系统来实现版本监控。通过对比上一次发布的版本(commit版本),以及当前的版本(commit版本),发现两个版本间的文件差别,提供自动新建博文,或者更新博文的依据。

# encoding=utf-8
#!/bin/sh python3 import git #gitpython
import inspect class RepoScanner():
def __init__(self, repopath, branch):
self._root = repopath
self._branch = branch
try:
self._repo = git.Repo(self._root)
except git.exc.NoSuchPathError as error: #如果没有git库,先创建git库
self._repo = git.Repo.init(path=self._root)
except:
raise Exception('Fail to open git repo at: %s' % (repopath)) heads = self._repo.heads
gotbranch = False
for head in heads:
if head.name == branch:
gotbranch = True
self.head = head
break
if not gotbranch:
print('create branch:', branch)
self.head = self._repo.create_head(branch) def scanFiles(self, begin_hexsha=None):
all_commits = list(self._repo.iter_commits(self.head.name))
begin_commit = None
for commit in all_commits:
if commit.hexsha == begin_hexsha:
begin_commit = commit
break sourceFiles = {}
if begin_commit:
beginIndexFile = git.IndexFile.from_tree(self._repo, begin_commit)
for (path, stage), entry in beginIndexFile.entries.items():
sourceFiles[path] = entry.hexsha indexFile = git.IndexFile.from_tree(self._repo, self.head.commit)
files = {}
for (path, stage), entry in indexFile.entries.items():
if path in sourceFiles:
if entry.hexsha != sourceFiles[path]:
files[path] = { "hexsha": entry.hexsha, "from_hexsha": sourceFiles[path], "change": 'modify'}
else:
files[path] = { "hexsha": entry.hexsha, "change": 'new'} return { "head": self.head.commit.hexsha, "files": files }

使用metaweblog API实现通用博客发布 之 版本控制的更多相关文章

  1. 使用metaweblog API实现通用博客发布 之 API测试

    使用metaweblog API实现通用博客发布 之 API测试 使用博客比较少,一则是文笔有限,怕写出的东西狗屁不通,有碍观瞻, 二则是懒,很讨厌要登录到网站上写东西,也没有那么多时间(借口).个人 ...

  2. 使用metaweblog API实现通用博客发布 之 本地图片自动上传以及替换路径

    使用metaweblog API实现通用博客发布 之 本地图片自动上传以及替换路径 通过metaweblog API 发布博文的时候,由于markdown中的图片路径是本地路径,将导致发布的文章图片不 ...

  3. 使用Office-Word的博客发布功能(测试博文)

    本人打算在博客园开博,但平时收集和整理资料都在OneNote中,又不想在写博客时还要进行复制粘贴操作,于是就想到了Microsoft Office自带的博客发布功能.在此做了一下测试,发布了此博文. ...

  4. BlogPublishTool - 博客发布工具

    BlogPublishTool - 博客发布工具 这是一个发布博客的工具.本博客使用本工具发布. 本工具源码已上传至github:https://github.com/ChildishChange/B ...

  5. 修改vscode caipeiyu.writeCnblog ,简化博客发布

    修改vscode caipeiyu.writeCnblog ,简化博客发布 1. 安装caipeiyu.writeCnblog vscode的博客园文章发布插件WriteCnblog : https: ...

  6. longblogV1.0——我的静态博客发布系统

    longblogV1.0——我的静态博客发布系统 环境依赖: python3-markdown 作者:IT小小龙个人主页:http://long_python.gitcafe.com/电子邮箱:lon ...

  7. Mac端博客发布工具推荐

    引子 推荐一款好用的 Mac 端博客发布工具. 下载地址 echo 博客对接 这里以cnblog为例.接入类型为metawebblog,access point可以在cnblog的设置最下边找到,然后 ...

  8. 基于.NET Core开发的个人博客发布至CentOS小计

    早些时候,使用 .NET Framework 开发网站,只能部署在 Windows 服务器上面,近两年 .NET Core 如火如荼,乘此机会赶紧上车,最近将自己利用 .NET Core 开发的个人博 ...

  9. 多平台博客发布工具OpenWrite的使用

    1 介绍 OpenWrite官网 OpenWrite是一款便捷的多平台博客发布工具,可以在OpenWrite编写markdown文档,然后发布到其他博客平台,目前已经支持CSDN.SegmentFau ...

随机推荐

  1. nat转换技术,且用且珍惜

    一.NAT转换技术 1.1.NAT技术概述 随着Internet的发展和网络应用的增多,IPv4地址枯竭已经成为制约网络发展的瓶颈.尽管IPv6可以从根本上解决IPv4地址空间不足的问题,但目前众多的 ...

  2. 刚学spark

    https://blog.csdn.net/u013019431/article/details/80776662   在jupyter notebook import pysparkhttps:// ...

  3. MySQL-12-innodb引擎补充

    innodb引擎保证事务的ACID 概念 redo log ---> 重做日志 ib_logfile0~1 50M 轮询使用 redo log buffer ---> redo内存区域 i ...

  4. git根据项目地址使用不同代理服务器

    问题 由于公司访问GitHub只能走代理,但是内网gitlab服务器又不能走代理. 因此想找到一种方案,可以支持git自动根据项目地址使用不同代理. 方案 如下所示,可以指定GitHub地址使用指定的 ...

  5. 题解 park/chase

    传送门 这题考试的时候觉得时间复杂度假了,\(n \geqslant 1000\)的部分直接瞎写了个特殊性质上去,结果假的时间复杂度能有60pts-- 比较大的数组无论如何不要直接全部memset!如 ...

  6. noip模拟15

    T1 恶心的数学题,还卡空间... 于是考虑数组二次调用,用完memset 记录一手二维前缀和对不同询问离线修改,最后一块回答即可 Code #include<cstdio> #inclu ...

  7. 【springboot】知识点总结

    [springboot 基础编] 01.SpringBoot>01 - 第一个应用–HelloWorld 02.SpringBoot>02 - 整合 MyBatis 03.SpringBo ...

  8. C# 正则表达式的重点知识 1

  9. SpringCloud bootstrap.yml 和application.yml 加载原理

    Spring Cloud 官方文档:https://cloud.spring.io/spring-cloud-static/spring-cloud.html 一个Spring Cloud的操作是通过 ...

  10. git tag的用法及意义

    git tag 介绍 命令是用来给当前项目状态(在某次commit后)打标签的,目的是便于以后将项目状态回滚到当时打标签的状态.可以把它与虚拟机的snapshot(快照)进行类比. 回想当时在看< ...