我怎么能叫'git的拉'从内部的Python? [英] How can I call 'git pull' from within Python?

查看:179
本文介绍了我怎么能叫'git的拉'从内部的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆