使用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. 日志导致jvm内存溢出相关问题

    生产环境日志级别为info,请看如下这行代码: LOGGER.debug("the DTO info: {}", JSON.toJSONString(DTO)); 这段代码主要有两 ...

  2. 【ShardingSphere技术专题】「ShardingJDBC」SpringBoot之整合ShardingJDBC实现分库分表(JavaConfig方式)

    前提介绍 ShardingSphere介绍 ShardingSphere是一套开源的分布式数据库中间件解决方案组成的生态圈,它由Sharding-JDBC.Sharding-Proxy和Shardin ...

  3. Linux下基于SQLite3 实现商店商品管理系统

    文章目录 一.SQLite相关C接口 重要接口 打开数据库 插入信息 查询 二.程序要求 三.程序说明 四.实现代码 水果店账单管理系统 一.SQLite相关C接口 如果第一次直接在命令行安装sqli ...

  4. NOIP 模拟 $28\; \rm 割海成路之日$

    题解 \(by\;zj\varphi\) 用两个集合分别表示 \(1\) 边联通块,\(1,2\) 边联通块 . \(\rm son_x\) 表示当前节点通过 \(3\) 类边能到的 \(2\) 联通 ...

  5. 题解 Smooth

    传送门 咕了蚯蚓这题+前一天被蚊子折腾了半宿没睡=全场几乎就我这题分最低-- 发现这里光滑数是不断乘出来的--记得这是一个很经典的套路,然而当时我咕了 求一个每个值都是 \(\{p_i\}\) 中至少 ...

  6. 目录-理解ASP.NET Core

    <理解ASP.NET Core>基于.NET5进行整理,旨在帮助大家能够对ASP.NET Core框架有一个清晰的认识. 目录 [01] Startup [02] Middleware [ ...

  7. Go定时器--Timer

    目录 前言 Timer 定时器 简介 使用场景 1. 设定超时时间 2. 延迟执行某个方法 Timer对外接口 1. 创建定时器 2. 停止定时器 3. 重置定时器 其他接口 1. After() 2 ...

  8. 使用spring向service里面注入dao不成功。

    因为原来的程序没有使用spring.后来加spring的时候action有个地方的new没有改!!! new了个新的实现层 不是spring管理的对象.

  9. Python3-sqlalchemy-orm 创建多表关联表带外键

    #-*-coding:utf-8-*- #__author__ = "logan.xu" import sqlalchemy from sqlalchemy import crea ...

  10. Robot framework随机文件

    *** Variables *** @{Example} One Two Three *** Test Cases *** Example ${value}= Evaluate random.choi ...