使用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 ...
随机推荐
- docker 安装prometheus和grafna
一.拉取镜像 docker pull prom/prometheus 二.配置 sudo mkdir /etc/prometheus/ sudo vim /etc/prometheus/prometh ...
- Pikahu-SQL注入模块和sqlmap经典用法
一.概述 SQL注入漏洞主要形成的原因是在数据交互中,前端的数据传入到后台处理时,没有做严格的判断,导致其传入的"数据"拼接到SQL语句中后,被当作SQL语句的一部分执行. 从而导 ...
- 【设计模式】装饰者模式(DecoratorMode0
From: https://liudongdong1.github.io/ 装饰者模式(Decorator Pattern):动态地给一个对象增加一些额外的职责,增加对象功能来说,装饰模式比生成子类实 ...
- Zabbix邮箱告警
一.安装邮箱 yum install mailx 二.配置邮箱 vim /etc/mail.rc set from=875667601@qq.com set smtp=smtp.qq.com set ...
- 通俗易懂理解——dijkstra算法求最短路径
迪杰斯特拉(Dijkstra)算法是典型最短路径算法,用于计算一个节点到其他节点的最短路径.它的主要特点是以起始点为中心向外层层扩展(广度优先搜索思想),直到扩展到终点为止 ###基本思想 通过Dij ...
- 遇到的C++ cli 转 C++ native 为C# 程序提供接口。
接口文件 /*++ (do not edit the above line) ************************************************************* ...
- C++ 保存读取二进制
一.保存二进制 #include <iostream> #include <fstream> int main(){ float* output = new float[100 ...
- qt 中的自定义pushbutton
- Object--Date--calendar--System--StringBuilder--基本数据类型包装类型
Object java.lang.Object类是Java语言中的根类,即所有类的父类 默认toString()方法打印的是对象在堆中的地址值 默认equals()方法比较的也是地址(String中对 ...
- JDBC基础篇(MYSQL)——使用statement执行DQL语句(select)
注意:其中的JdbcUtil是我自定义的连接工具类:代码例子链接: package day02_statement; import java.sql.Connection; import java.s ...