结构错误:致命错误:执行“git commit -m”消息“时,local() 遇到错误(返回代码 2)”

发布于 2024-08-14 06:48:28 字数 1047 浏览 4 评论 0原文

我正在尝试设置 fabfile 来部署我的 Django 应用程序。

我不明白为什么会出现此错误:

致命错误:执行“git commit -m '更改了 prodserver 的设置”时,local() 遇到错误(返回代码 2)

$ fab create_branch_deploy_to_prodserver
[localhost] run: git checkout prodserver_server
[localhost] run: git merge master
[localhost] run: cp settings_prodserver.py settings.py
[localhost] run: git add settings.py
[localhost] run: git commit -m 'changed settings for prodserver'

Fatal error: local() encountered an error (return code 1) while executing 'git commit -m 'changed settings for prodserver''

Aborting.

这里如果 Fabric 函数:

def create_branch_deploy_to_prodserver():  
    local("git checkout prodserver_server")  
    local("git merge master")  
    local('cp settings_prodserver.py settings.py') # 
    #local('git rm fabfile.py') #This is also creating error so it's commented out
    local('git add settings.py')  
    local("git commit -m 'changed settings for prodserver'")  

是否可以从 Fabric 进行 git 提交?

I'm trying to setup a fabfile to deploy my Django app.

I can't figure out why I'm getting this error:

Fatal error: local() encountered an error (return code 2) while executing 'git commit -m 'changed settings for prodserver'

$ fab create_branch_deploy_to_prodserver
[localhost] run: git checkout prodserver_server
[localhost] run: git merge master
[localhost] run: cp settings_prodserver.py settings.py
[localhost] run: git add settings.py
[localhost] run: git commit -m 'changed settings for prodserver'

Fatal error: local() encountered an error (return code 1) while executing 'git commit -m 'changed settings for prodserver''

Aborting.

Here if the Fabric function:

def create_branch_deploy_to_prodserver():  
    local("git checkout prodserver_server")  
    local("git merge master")  
    local('cp settings_prodserver.py settings.py') # 
    #local('git rm fabfile.py') #This is also creating error so it's commented out
    local('git add settings.py')  
    local("git commit -m 'changed settings for prodserver'")  

Is it possible to make a git commit from Fabric?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

面犯桃花 2024-08-21 06:48:28

当我在声明中添加 capture=False 时,我能够诊断问题:

local('git rm fabfile.py', capture=False)
local('git add settings.py', capture=False)

这允许更详细地显示错误。

显然,Fabric 的维护者将在 1.0 中将 local 的行为恢复为默认不捕获。

I was able to diagnose the issue when I added capture=False to the declaration:

local('git rm fabfile.py', capture=False)
local('git add settings.py', capture=False)

This allowed the error to be displayed more verbosely.

Apparently, the maintainer of Fabric will to revert local's behavior back to not capturing by default, in 1.0.

对岸观火 2024-08-21 06:48:28

这是一个与 python 相关的问题,就像 此线程中描述的问题一样

主要问题是 stdout/stderr 捕获是按运行/sudo 调用而不是按任务进行的。

如果您能向我解释如何通过仅修改名为 fabfile_runner.py的文件来收集输出错误,那就太好了代码>。
理想情况下,结构任务本身可以不被修改,这将允许向工厂上传您手动测试过的相同文件。

查看 Fabric 源代码并查看“tests”文件夹,特别是tests/utils.py。它包含一个装饰器 @mock_streams,它能够包装一个函数(任何 Python 代码中的任何函数——正如我提到的,它不是特定于 Fabric 的)并重定向 sys.stdout< /code> 和/或 sys.stderr 用于捕获/检查。

它是为围绕函数使用而设计的,是一个装饰器,因此您可以通过修改 fabfile_runner.py 直接使用它,如下所示:

fabfile_runner.py

from StringIO import StringIO
import sys
from test_fabfile import hello_world

def execute(task):
    output = StringIO()
    error = StringIO()
    sys.stdout = output
    sys.stderr = error
    task()
    sys.stdout = sys.__stdout__
    sys.stderr = sys.__stderr__
    return (output.getvalue(), error.getvalue())

output, error = execute(hello_world)
print "output : %s" %output
print "error : %s" %error

Is this a python-related issue like the one described in this thread?

The main problem with this is that the stdout/stderr capturing is per-run/sudo invocation and not per-task.

It would be wonderful if you could explain me how I could collect outputand error by only modifying the file called fabfile_runner.py.
Idealy the fabric task itself could be unmodified, this would allow to upload the the factory the same file that you have tested manually.

Check out the Fabric source and look in the 'tests' folder, specifically tests/utils.py. It contains a single decorator, @mock_streams, which is capable of wrapping a function (any function in any Python code -- it's not Fabric specific, as I mentioned) and redirecting sys.stdout and/or sys.stderr for capture/examination.

It's designed for use around functions, being a decorator, so you could use it directly by modifying your fabfile_runner.py like so:

fabfile_runner.py

from StringIO import StringIO
import sys
from test_fabfile import hello_world

def execute(task):
    output = StringIO()
    error = StringIO()
    sys.stdout = output
    sys.stderr = error
    task()
    sys.stdout = sys.__stdout__
    sys.stderr = sys.__stderr__
    return (output.getvalue(), error.getvalue())

output, error = execute(hello_world)
print "output : %s" %output
print "error : %s" %error
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文