使用metaweblog API实现通用博客发布 之 版本控制
使用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实现通用博客发布 之 版本控制的更多相关文章
- 使用metaweblog API实现通用博客发布 之 API测试
使用metaweblog API实现通用博客发布 之 API测试 使用博客比较少,一则是文笔有限,怕写出的东西狗屁不通,有碍观瞻, 二则是懒,很讨厌要登录到网站上写东西,也没有那么多时间(借口).个人 ...
- 使用metaweblog API实现通用博客发布 之 本地图片自动上传以及替换路径
使用metaweblog API实现通用博客发布 之 本地图片自动上传以及替换路径 通过metaweblog API 发布博文的时候,由于markdown中的图片路径是本地路径,将导致发布的文章图片不 ...
- 使用Office-Word的博客发布功能(测试博文)
本人打算在博客园开博,但平时收集和整理资料都在OneNote中,又不想在写博客时还要进行复制粘贴操作,于是就想到了Microsoft Office自带的博客发布功能.在此做了一下测试,发布了此博文. ...
- BlogPublishTool - 博客发布工具
BlogPublishTool - 博客发布工具 这是一个发布博客的工具.本博客使用本工具发布. 本工具源码已上传至github:https://github.com/ChildishChange/B ...
- 修改vscode caipeiyu.writeCnblog ,简化博客发布
修改vscode caipeiyu.writeCnblog ,简化博客发布 1. 安装caipeiyu.writeCnblog vscode的博客园文章发布插件WriteCnblog : https: ...
- longblogV1.0——我的静态博客发布系统
longblogV1.0——我的静态博客发布系统 环境依赖: python3-markdown 作者:IT小小龙个人主页:http://long_python.gitcafe.com/电子邮箱:lon ...
- Mac端博客发布工具推荐
引子 推荐一款好用的 Mac 端博客发布工具. 下载地址 echo 博客对接 这里以cnblog为例.接入类型为metawebblog,access point可以在cnblog的设置最下边找到,然后 ...
- 基于.NET Core开发的个人博客发布至CentOS小计
早些时候,使用 .NET Framework 开发网站,只能部署在 Windows 服务器上面,近两年 .NET Core 如火如荼,乘此机会赶紧上车,最近将自己利用 .NET Core 开发的个人博 ...
- 多平台博客发布工具OpenWrite的使用
1 介绍 OpenWrite官网 OpenWrite是一款便捷的多平台博客发布工具,可以在OpenWrite编写markdown文档,然后发布到其他博客平台,目前已经支持CSDN.SegmentFau ...
随机推荐
- Greenplum数仓监控解决方案(开源版本)
Greenplum监控解决方案 基于Prometheus+Grafana+greenplum_exporter+node_exporter实现 关联图 一.基本概念 1.Prometheus Pr ...
- MySQL高级查询 & 事务机制
1.基础查询where 高级条件查询Where子句 SELECT empno,ename,sal,hiredate FROM t_tmp WHERE deptno=10 AND (sal+IFNULL ...
- Golang语言系列-04-运算符
运算符 Go语言内置的运算符有 算术运算符 关系运算符 逻辑运算符 位运算符 赋值运算符 算术运算符 package main import "fmt" func main() { ...
- 轻松上手SpringBoot+SpringSecurity+JWT实RESTfulAPI权限控制实战
前言 我们知道在项目开发中,后台开发权限认证是非常重要的,springboot 中常用熟悉的权限认证框架有,shiro,还有就是springboot 全家桶的 security当然他们各有各的好处,但 ...
- 尝试通过 JDBC 将 UTF-8 插入 MySQL 时出现“乱码”
这是我的连接设置方式: Connection conn = DriverManager.getConnection(url + dbName + "?useUnicode=true& ...
- 【原创】JavaFx程序解决Jupyter Notebook导出PDF不显示中文
0.ATTENTION!!! JavaFx里是通过Java调用控制台执行的的jupyter和xelatex指令, 这些个指令需要在本地安装Jupyter和MikTeX之后才能正常在电脑上运行 1.[问 ...
- Java线程池中submit()和execute()方法有什么区别
两个方法都可以向线程池提交任务,execute()方法的返回类型是void,它定义在Executor接口中,而submit()方法返回有计算结构的Future对象,它定义在ExecutorServic ...
- nginx 部署vue
server { listen 80; server_name localhost; root /www/meiduo_admin/dist; access_log /var/log/nginx/ad ...
- flutter添加启动图及设置启动时间
首先贴个官方的设置方法,看这里:https://flutterchina.club/assets-and-images/#%E6%9B%B4%E6%96%B0%E5%90%AF%E5%8A%A8%E9 ...
- UWP AppConnection.
https://www.cnblogs.com/manupstairs/p/14582794.html