Python的高级Git库 Gittle
Gittle是一个高级纯python git 库。构建在dulwich之上,提供了大部分的低层机制
Gittle是一个高级纯python git 库。构建在dulwich之上,提供了大部分的低层机制。
Install it
pip install gittle
Examples :
Clone a repository
|
1
2
3
4
5
6
|
from gittle import Gittle repo_path = '/tmp/gittle_bare'repo_url = 'git://github.com/FriendCode/gittle.git' repo = Gittle.clone(repo_url, repo_path) |
With authentication (see Authentication section for more information) :
|
1
2
|
auth = GittleAuth(pkey=key)Gittle.clone(repo_url, repo_path, auth=auth) |
Or clone bare repository (no working directory) :
repo = Gittle.clone(repo_url, repo_path, bare=True)
Init repository from a path
repo = Gittle.init(path)
Get repository information
|
1
2
3
4
5
6
7
8
9
10
11
|
# Get list of objectsrepo.commits # Get list of branchesrepo.branches # Get list of modified files (in current working directory)repo.modified_files # Get diff between latest commitsrepo.diff('HEAD', 'HEAD~1') |
Commit
|
1
2
3
4
5
6
7
8
|
# Stage single filerepo.stage('file.txt') # Stage multiple filesrepo.stage(['other1.txt', 'other2.txt']) # Do the commitrepo.commit(name="Samy Pesse", email="samy@friendco.de", message="This is a commit") |
Pull
|
1
2
3
4
5
6
7
8
|
repo = Gittle(repo_path, origin_uri=repo_url) # Authentication with RSA private keykey_file = open('/Users/Me/keys/rsa/private_rsa')repo.auth(pkey=key_file) # Do pullrepo.pull() |
Push
|
1
2
3
4
5
6
7
8
|
repo = Gittle(repo_path, origin_uri=repo_url) # Authentication with RSA private keykey_file = open('/Users/Me/keys/rsa/private_rsa')repo.auth(pkey=key_file) # Do pushrepo.push() |
Authentication for remote operations
|
1
2
3
4
5
6
|
# With a keykey_file = open('/Users/Me/keys/rsa/private_rsa')repo.auth(pkey=key_file) # With username and passwordrepo.auth(username="your_name", password="your_password") |
Branch
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# Create branch off masterrepo.create_branch('dev', 'master') # Checkout the branchrepo.switch_branch('dev') # Create an empty branch (like 'git checkout --orphan')repo.create_orphan_branch('NewBranchName') # Print a list of branchesprint(repo.branches) # Remove a branchrepo.remove_branch('dev') # Print a list of branchesprint(repo.branches) |
Get file version
|
1
2
|
versions = repo.get_file_versions('gittle/gittle.py')print("Found %d versions out of a total of %d commits" % (len(versions), repo.commit_count())) |
Get list of modified files (in current working directory)
repo.modified_files
Count number of commits
repo.commit_count
Get information for commits
List commits :
# Get 20 first commits repo.commit_info(start=0, end=20)
With a given commit :
commit = "a2105a0d528bf770021de874baf72ce36f6c3ccc"
Diff with another commit :
|
1
2
|
old_commit = repo.get_previous_commit(commit, n=1)print repo.diff(commit, old_commit) |
Explore commit files using :
|
1
2
3
4
5
6
7
8
9
10
|
commit = "a2105a0d528bf770021de874baf72ce36f6c3ccc" # Files treeprint repo.commit_tree(commit) # List files in a subpathprint repo.commit_ls(commit, "testdir") # Read a fileprint repo.commit_file(commit, "testdir/test.txt") |
Create a GIT server
|
1
2
3
4
5
6
7
|
from gittle import GitServer # Read onlyGitServer('/', 'localhost').serve_forever() # Read/WriteGitServer('/', 'localhost', perm='rw').serve_forever() |
Python的高级Git库 Gittle的更多相关文章
- 树莓派高级GPIO库,wiringpi2 for python使用笔记(一)安装
网上的教程,一般Python用RPi.GPIO来控制树莓派的GPIO,而C/C++一般用wringpi库来操作GPIO,RPi.GPIO过于简单,很多高级功能不支持,比如i2c/SPI库等,也缺乏高精 ...
- Python测试 ——开发工具库
Web UI测试自动化 splinter - web UI测试工具,基于selnium封装. selenium - web UI自动化测试. mechanize- Python中有状态的程序化Web浏 ...
- Python常用的标准库以及第三方库有哪些?
20个必不可少的Python库也是基本的第三方库 读者您好.今天我将介绍20个属于我常用工具的Python库,我相信你看完之后也会觉得离不开它们.他们是: Requests.Kenneth Reitz ...
- Python常用的标准库以及第三方库
Python常用的标准库以及第三方库有哪些? 20个必不可少的Python库也是基本的第三方库 读者您好.今天我将介绍20个属于我常用工具的Python库,我相信你看完之后也会觉得离不开它们.他们 ...
- Python 常用的标准库以及第三方库有哪些?
作者:史豹链接:https://www.zhihu.com/question/20501628/answer/223340838来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...
- python测试开发工具库汇总(转载)
Web UI测试自动化 splinter - web UI测试工具,基于selnium封装. selenium - web UI自动化测试. mechanize- Python中有状态的程序化Web浏 ...
- 进击的Python【第五章】:Python的高级应用(二)常用模块
Python的高级应用(二)常用模块学习 本章学习要点: Python模块的定义 time &datetime模块 random模块 os模块 sys模块 shutil模块 ConfigPar ...
- python的高级应用
记录一下Python函数式编程,高级的几个BIF,高级官方库方面的用法和心得. 函数式编程 函数式编程是使用一系列函数去解决问题,按照一般编程思维,面对问题时我们的思考方式是"怎么干&quo ...
- python下载安装requests库
一.python下载安装requests库 1.到git下载源码zip源码https://github.com/requests/requests 2.解压到python目录下: 3.“win+R”进 ...
随机推荐
- POJ 3693 (后缀数组) Maximum repetition substring
找重复次数最多的字串,如果有多解,要求字典序最小. 我也是跟着罗穗骞菊苣的论文才刷这道题的. 首先还是枚举一个循环节的长度L,如果它出现两次的话,一定会包含s[0], s[L], s[2L]这些相邻两 ...
- svn备份脚 本
一直用这套脚本备份,脚本主体虽不是原创,但是从网上得到后因为不能运行也进行了些修改,前两天看到有人问关于SVN备份的问题,今天又把脚本整理了一下,解决了不能循环备份多个配置库的问题.希望对大家有所帮助 ...
- android linux shell 日期设置
/************************************************************************ android linux shell 日期设置 * ...
- tornado 实践 - 目录结构
. ├── README.md └── store_management ├── Session.vim ├── auth │ ├── __init__.py │ ├── views.py ├ ...
- 【Sass初级】开始使用Sass和Compass
转自:http://www.w3cplus.com/preprocessor/beginner/getting-started-with-sass-and-compass.html 如果你的朋友.同事 ...
- js浮点数运算需要注意的问题
最近在js运算浮点数时发现了一个问题.问题是这样的:js函数中处理两个浮点数的相加,为了防止出现0.1+0.2=0.30000000000000004的问题,两个数都先乘以10000后再相加,得到结果 ...
- PHP中的cookie
第一次设置后,第二次访问才生效,决绝办法可以用js跳转首页实现刷新. 1.创建/更新cookie setCookie($cookieName,$value,time()+秒数): 例子:创建一个coo ...
- Jquery 设置style:display 通过ID隐藏区域
$("#id").css('display','none'); $("#id").css('display','block'); 或 $("#id&q ...
- 将垃圾送入无底洞,顺便整理dev知识
相信用过Linux的童鞋们都用过crontab来做定时任务,不需要额外的安装程序和配置,一条简单的语句搞定定时任务,但是小伙伴们发现了没,如果你的定时任务执行频率很高而且会产生大量的输出的话,你的老爷 ...
- 【LeetCode】118 & 119 - Pascal's Triangle & Pascal's Triangle II
118 - Pascal's Triangle Given numRows, generate the first numRows of Pascal's triangle. For example, ...