繁体   English   中英

使用Fabric进行Django部署-TypeError:prepare_deployment()恰好接受1个参数(给定0)

[英]django deployment using fabric - TypeError: prepare_deployment() takes exactly 1 argument (0 given)

我正在使用此指南: http : //www.jeffknupp.com/blog/2012/02/09/starting-a-django-project-the-right-way/

设置我的django项目。 但是我被困在部署部分。 我在virtualenv中使用pip安装了fabric。 我在myproject目录中创建了此文件:

from fabric.api import local

def prepare_deployment(branch_name):
    local('python manage.py test finance')
    local('git add -p && git commit')
    local('git checkout master && git merge ' + branchname)

from fabric.api import lcd

def deploy():
    with lcd('home/andrius/djcode/myproject/'):
        local('git pull /home/andrius/djcode/dev/')
        local('python manage.py migrate finance')
        local('python manage.py test finance')
        local('/my/command/to/restart/webserver')

但是,当我输入此命令时(如指南中所示):

晶圆厂prepare_deployment

我收到此错误:

Traceback (most recent call last):
  File "/home/andrius/env/local/lib/python2.7/site-packages/fabric/main.py", line 732, in main
    *args, **kwargs
  File "/home/andrius/env/local/lib/python2.7/site-packages/fabric/tasks.py", line 345, in execute
    results['<local-only>'] = task.run(*args, **new_kwargs)
  File "/home/andrius/env/local/lib/python2.7/site-packages/fabric/tasks.py", line 121, in run
    return self.wrapped(*args, **kwargs)
TypeError: prepare_deployment() takes exactly 1 argument (0 given)

因此,即使它没有在指南中指定输入参数,我想它也需要我的分支名称。 因此输入:

fab prepare_deployment v0.1

(v0.1是我的分支名称)所以现在出现此错误:

Warning: Command(s) not found:
    v0.1

Available commands:
    deploy
    prepare_deployment

我也在函数prepare_deployment的fabfile.py文件指南中注意到,输入写为'branch_name',函数内部有参数'branchname'。 因此,我认为应该相同,并将“ branchname”重命名为“ branch_name”,但仍然收到相同的错误。

所以我想我在这里做错了。 可能是什么问题呢?

更新:我尝试使用以下命令在fabfile.py中调用函数:

prepare_deployment(“ v0.1”)

输出是这样的:

[localhost] local: python manage.py test finance
Creating test database for alias 'default'...
Got an error creating the test database: permission denied to create database

Type 'yes' if you would like to try deleting the test database 'test_finance', or 'no' to cancel: yes
Destroying old test database 'default'...
Got an error recreating the test database: database "test_finance" does not exist


Fatal error: local() encountered an error (return code 2) while executing 'python manage.py test finance'

Aborting.

我想我还应该提到我的应用程序名称是“ finance”,而数据库名称是“ finance”。 也许那些冲突?

Fabric使用特定的语法从命令行将参数传递给任务。 在bash shell中,您需要使用

fab prepare_deployment:v0.1

您可以在Fabric文档中的每个任务参数上阅读有关它的信息

如果您确实需要在bash命令中使用方括号,则需要对其进行转义。

如您所述,此功能应如下所示...

def prepare_deployment(branch_name):
    local('python manage.py test finance')
    local('git add -p && git commit')
    local('git checkout master && git merge ' + branch_name)

然后您只需致电...

fab prepare_deployment("v0.1")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM