Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python wrapper to access Hg, Git and possibly Bazaar repositories?

I'm looking for a Python library that can do basic manipulation of repositories, but is independent of the backend version control system.

By basic manipulation, I'm referring to: initialize a repo, add files, commit, pull, push, get current revision number.

Users of the library could do something this:

import dvcs_wrapper as dvcs
dvcs.set_backend('hg')  # could choose 'git', 'bzr'

repo = dvcs.init('/home/me/my_repo')
repo.add('/home/me/my_repo/*.py')
repo.commit('Initial commit')
repo.push('http://bitbucket.org/....')
print('At revision %d' % repo.revision_num)

Any pointers to something like the above? My Google searches turn up nothing...

Update: for what it's worth, I've started working on something like this: code is here with unit tests for Hg repositories. I might get around to Git and Bazaar; contributions welcome.

like image 792
Kevin Dunn Avatar asked May 10 '11 01:05

Kevin Dunn


2 Answers

There's also the VCS module, which advertises:

vcs is abstraction layer over various version control systems. It is designed as feature-rich Python library with clean API.

like image 115
RyanWilcox Avatar answered Oct 11 '22 06:10

RyanWilcox


I think you are out of luck.

There are Python wrappers for git but according to this the quality is still less than optimal. Hg and bzr are Python projects but their infrastructure is quite different, so API level integration is not easy. Also different SCMs have different design philosophies, which makes a unified wrapper less plausible.

That being said, if you do need a simple wrapper, you can use the subprocess module and wrap the command lines to get the result you want.

like image 43
Wang Dingwei Avatar answered Oct 11 '22 07:10

Wang Dingwei