【问题标题】:How do you define the host for Fabric to push to GitHub?你如何定义 Fabric 推送到 GitHub 的主机?
【发布时间】: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


【解决方案1】:

您应该研究一下 Fabric。 http://docs.fabfile.org/en/1.4.1/index.html。自动化服务器部署工具。这个我用了很久了,效果很好。

这是我使用它的应用程序之一,https://github.com/kracekumar/sachintweets/blob/master/fabfile.py

【讨论】:

  • 听起来不错 - 谢谢。我使用 Python 的时间不长,昨天才开始使用 GitHub,所以我确信那里有很多我还没有找到的 :)
  • 这些是其他部署工具,但它们是 ruby​​ 和其他语言的。这是pythonic !!!!
  • 阅读了一些内容,但最终 Fabric 将我的更新推送到了 GitHub。获胜者:D
【解决方案2】:

看起来你可以这样做:

index = repo.index
index.add(['images'])
new_commit = index.commit("my commit message")

然后,假设您将 origin 作为默认遥控器:

origin = repo.remotes.origin
origin.push()

【讨论】:

  • 谢谢。我在索引对象文档中看到了这一点,但没有看到任何关于推送提交的提及。我不确定这是否是在 GitPython 中无法完成的事情。我可能必须让 Fabric 来做那部分。
  • 啊。我错过了那一点。编辑添加推送到原点
猜你喜欢
  • 1970-01-01
  • 2023-01-02
  • 2020-02-12
  • 2020-04-14
  • 1970-01-01
  • 1970-01-01
  • 2011-06-12
  • 2020-09-19
  • 2023-03-29
相关资源
最近更新 更多