Python的高级Git库 Gittle

gittle是一个高级纯python git 库。构建在dulwich之上,提供了大部分的低层机制。

Install it

pip install gittle

登录后复制

Examples :

Clone a repository

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) :

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

# 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

# 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

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

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

# 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

# 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

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 :

立即学习“Python免费学习笔记(深入)”;

commit = "a2105a0d528bf770021de874baf72ce36f6c3ccc" 

登录后复制

Diff with another commit :

old_commit = repo.get_previous_commit(commit, n=1)print repo.diff(commit, old_commit)

登录后复制

Explore commit files using :

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

from gittle import GitServer # Read onlyGitServer('/', 'localhost').serve_forever() # Read/WriteGitServer('/', 'localhost', perm='rw').serve_forever()

登录后复制

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2291068.html

(0)
上一篇 2025年2月28日 00:45:23
下一篇 2025年2月24日 07:21:28

AD推荐 黄金广告位招租... 更多推荐

相关推荐

  • Python多进程编程技术实例分析

    本文以实例形式分析了python多进程编程技术,有助于进一步python程序设计技巧。分享给大家供大家参考。具体分析如下: 一般来说,由于Python的线程有些限制,例如多线程不能充分利用多核CPU等问题,因此在Python中我们更倾向使用…

    编程技术 2025年2月28日
    200
  • Python专用方法与迭代机制实例分析

    本文实例讲述了python专用方法与迭代机制,分享给大家供大家参考之用。具体分析如下: 众所周知,Python 设计哲学是“优雅”、“明确”、“简单”,对于一件事只用一种最好的方法来做,而这种优雅在于背后很自然的隐藏了很多细节。比如对一些对…

    编程技术 2025年2月28日
    200
  • python中执行shell命令的几个方法小结

    最近有个需求就是页面上执行shell命令,第一想到的就是os.system, 复制代码 代码如下:os.system(‘cat /proc/cpuinfo’) 但是发现页面上打印的命令执行结果 0或者1,当然不满足需…

    编程技术 2025年2月28日
    200
  • Python threading多线程编程实例

    python 的多线程有两种实现方法: 函数,线程类 1.函数 调用 thread 模块中的 start_new_thread() 函数来创建线程,以线程函数的形式告诉线程该做什么 复制代码 代码如下: 立即学习“Python免费学习笔记(…

    编程技术 2025年2月28日
    200
  • Python显示进度条的方法

    本文实例讲述了python显示进度条的方法,是python程序设计中非常实用的技巧。分享给大家供大家参考。具体方法如下: 首先,进度条和一般的print区别在哪里呢? 答案就是print会输出一个,也就是换行符,这样光标移动到了下一行行首,…

    2025年2月28日
    200
  • Python中用Descriptor实现类级属性(Property)详解

    上篇文章简单介绍了python中描述器(descriptor)的概念和使用,有心的同学估计已经get√了该技能。本篇文章通过一个descriptor的使用场景再次给出一个案例,让不了解情况的同学可以更容易理解。 先说说decorator 这…

    编程技术 2025年2月28日
    200
  • Python实现的检测web服务器健康状况的小程序

    对web服务器做健康检查,一般我们都是用curl库(不管是php,perl的还是shell的),大致的方法一致: 复制代码 代码如下:curl -I -s www.qq.com  |head -1|awk ‘{ health =…

    2025年2月28日
    200
  • python写的一个squid访问日志分析的小程序

    这两周组里面几位想学习python,于是我们就创建了一个这样的环境和氛围来给大家学习。 昨天在群里,贴了一个需求,就是统计squid访问日志中ip 访问数和url的访问数并排序,不少同学都大体实现了相应的功能,我把我简单实现的贴出来,欢迎拍…

    2025年2月28日
    200
  • python里大整数相乘相关技巧指南

    问题 大整数相乘 思路说明 对于大整数计算,一般都要用某种方法转化,否则会溢出。但是python无此担忧了。 Python支持“无限精度”的整数,一般情况下不用考虑整数溢出的问题,而且Python Int类型与任意精度的Long整数类可以无…

    编程技术 2025年2月28日
    200
  • python里将list中元素依次向前移动一位

    问题 定义一个int型的一维数组,包含10个元素,分别赋值为1~10, 然后将数组中的元素都向前移一个位置, 即,a[0]=a[1],a[1]=a[2],…最后一个元素的值是原来第一个元素的值,然后输出这个数组。 解决(Python) #!…

    编程技术 2025年2月28日
    200

发表回复

登录后才能评论