使用github webhooks,我希望能够将任何更改提取到远程开发服务器.目前,在适当的目录中,git pull获取需要进行的任何更改.但是,我无法弄清楚如何从Python中调用该函数.我尝试过以下方法:
import subprocess
process = subprocess.Popen("git pull", stdout=subprocess.PIPE)
output = process.communicate()[0]
Run Code Online (Sandbox Code Playgroud)
但这会导致以下错误
回溯(最近调用最后一次):文件"",第1行,在文件"/usr/lib/python2.7/subprocess.py",第679行,在 init errread,errwrite)文件"/ usr/lib/python2. 7/subprocess.py",第1249行,在_execute_child中引发child_exception OSError:[Errno 2]没有这样的文件或目录
有没有办法可以在Python中调用这个bash命令?
我正在尝试编写一个 python 脚本,该脚本在运行时会将文件推送到我的 GitHub 存储库之一。我正在使用包 GitPython。我想使用访问令牌登录我的 GitHub 帐户(而不是输入我的用户名和密码),因为我有两步验证。我已经创建了令牌,但我不知道如何将它添加到我的 GitPython 代码中。
到目前为止,这是我的代码:
def push(repo_dir):
import os
from git import Repo
# set working directory
os.chdir("XXX")
#repo_dir = 'Pantone'
repo = Repo(repo_dir)
file_list = [
"index.html",
"Data/colors.csv"
]
commit_message = 'Adding new color'
repo.index.add(file_list)
repo.index.commit(commit_message)
origin = repo.remote('origin')
origin.push()
Run Code Online (Sandbox Code Playgroud)