原始问题
我有一些 python 脚本,这些脚本一直在使用 Amazon S3 上传脚本中 Selenium 测试后拍摄的屏幕截图。
现在我们正在从 S3 转向使用 GitHub,因此我找到了 GitPython,但看不到如何使用它来实际提交到本地存储库并推送到服务器。
我的脚本在工作区中构建了一个类似于 \images\228M\View_Use_Case\1.png
的目录结构,上传到 S3 时这是一个简单的过程;
for root, dirs, files in os.walk(imagesPath):
for name in files:
filename = os.path.join(root, name)
k = bucket.new_key('{0}/{1}/{2}'.format(revisionNumber, images_process, name)) # returns a new key object
k.set_contents_from_filename(filename, policy='public-read') # opens local file buffers to key on S3
k.set_metadata('Content-Type', 'image/png')
是否有类似的东西,或者是否有像 GitPython 中的 bash type git add images
命令一样简单但我完全错过了的东西?
使用 Fabric 更新
所以我根据 kracekumar 的推荐安装了 Fabric,但我找不到有关如何定义 (GitHub) 主机的文档。 我的脚本非常简单,只需尝试让上传工作即可;
from __future__ import with_statement
from fabric.api import *
from fabric.contrib.console import confirm
import os
def git_server():
env.hosts = ['github.com']
env.user = 'git'
env.passowrd = 'password'
def test():
process = 'View Employee'
os.chdir('\Work\BPTRTI\main\employer_toolkit')
with cd('\Work\BPTRTI\main\employer_toolkit'):
result = local('ant viewEmployee_git')
if result.failed and not confirm("Tests failed. Continue anyway?"):
abort("Aborting at user request.")
def deploy():
process = "View Employee"
os.chdir('\Documents and Settings\markw\GitTest')
with cd('\Documents and Settings\markw\GitTest'):
local('git add images')
local('git commit -m "Latest Selenium screenshots for %s"' % (process))
local('git push -u origin master')
def viewEmployee():
#test()
deploy()
它有效\o/万岁。
最佳答案
你应该研究一下 Fabric。 http://docs.fabfile.org/en/1.4.1/index.html 。自动化服务器部署工具。我已经使用这个相当长一段时间了,效果非常好。
这是我使用它的应用程序之一,https://github.com/kracekumar/sachintweets/blob/master/fabfile.py
关于python - 如何定义Fabric推送到GitHub的主机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10226618/