【发布时间】:2012-04-19 10:59:49
【问题描述】:
原始问题
我有一些 python 脚本一直在使用 Amazon S3 来上传脚本中 Selenium 测试后拍摄的屏幕截图。
现在我们正在从 S3 迁移到使用 GitHub,所以我找到了 GitPython,但看不到您如何使用它来实际提交到本地 repo 并推送到服务器。
我的脚本在工作区中构建了一个类似于\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 类型 git add images 命令?
用织物更新
所以我根据 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/ 万岁。
【问题讨论】:
-
如果你创建一个 repo 和
git remote详细信息,并使用具有git push -u origin master的结构创建一个 func,它只会询问密码。
标签: python github fabric gitpython