使用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 ...
随机推荐
- Linux之cat tail less常见用法
1.cat 通常查找出错误日志 cat error.log | grep 'foo' , 这时候我们还有个需求就是输出当前这个日志的前后几行: cat error.log | grep -C 10 ' ...
- Dubbo系列讲解之扩展点实现原理分析【2万字分享】
Apache Dubbo 是一款微服务开发框架,它提供了 RPC通信 与 微服务治理 两大关键能力.这意味着,使用 Dubbo 开发的微服务,将具备相互之间的远程发现与通信能力, 同时利用 Dubbo ...
- SSM自学笔记(四)
8.面向切面编程AOP 1.Spring 的 AOP 简介 1.1 什么是 AOP AOP 为 Aspect Oriented Programming 的缩写,意思为面向切面编程,是通过预编译方式和运 ...
- windows下安装mysql5.6.47版本
详情转载地址:https://www.cnblogs.com/alan-lin/p/9966917.html
- Docker运行PostgreSQL
docker-compose.yml version: '3.1' services: db: image: postgres restart: always ports: - 5432:5432 e ...
- 踩坑记录--接口调用,传参DataTable报错
问题描述 服务端提供接口,接口参数包含DataTable类型,客户端调用显示请求报错,Postman调用显示Could not get response 解决 原因 接口实现基于wcf,而wcf参数类 ...
- WPF : ControlTemplate和DataTemplate的区别
ControlTemplate用于描述控件本身. 使用TemplateBinding来绑定控件自身的属性, 比如{TemplateBinding Background}DataTemplate用于描述 ...
- Django常用 命令
Django常用 命令: 安装: pip install django 指定版本 pip3 install django==2.0 新建项目: django-admin.py startproject ...
- 乌班图安装redis问题
ot@DESKTOP-5382063:/usr/local/redis/redis-3.0.4# make\ > cd src && make all make[1]: Ente ...
- WSL(Ubuntu)下安装Redis
一.安装 输入命令安装redis-server sudo apt-get install redis-server 安装完成后打开redis.conf文件,找到bind 127.0.0.1,更改为bi ...