我怎么能叫'git的拉'从内部的Python? [英] How can I call 'git pull' from within Python?
问题描述
使用GitHub的网络挂接,我希望能拉的任何更改到远程开发服务器。此刻,当相应的目录, git的拉
获取需要进行任何更改。但是,我想不出如何调用该函数从Python中。我曾尝试以下内容:
Using the github webhooks, I would like to be able to pull any changes to a remote development server. At the moment, when in the appropriate directory, git pull
gets any changes that need to be made. However, I can't figure out how to call that function from within Python. I have tried the following:
import subprocess
process = subprocess.Popen("git pull", stdout=subprocess.PIPE)
output = process.communicate()[0]
但是,这将导致以下的错误
But this results in the following error
回溯(最近通话最后一个):文件,1号线,在
文件/usr/lib/python2.7/subprocess.py,线路679,在
的init
errread,ERRWRITE)文件/usr/lib/python2.7/subprocess.py,1249线,在_execute_child
提高child_exception OSERROR:[错误2]没有这样的文件或目录
Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/subprocess.py", line 679, in init errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory
有没有办法,我可以从Python中调用这个bash命令的方式?
Is there a way that I can call this bash command from within Python?
推荐答案
你有没有考虑过使用GitPython?它的设计处理了这么多废话你。
Have you considered using GitPython? It's designed to handle all this nonsense for you.
import git
g = git.cmd.Git(git_dir)
g.pull()
<一个href=\"https://github.com/gitpython-developers/GitPython\">https://github.com/gitpython-developers/GitPython
这篇关于我怎么能叫'git的拉'从内部的Python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!