小编ibl*_*vic的帖子

YAML中的Ansible整型变量

我正在使用Ansible来部署webapp.我想通过检查给定页面返回具有给定键/值的JSON来等待应用程序运行.

我希望在失败之前尝试几次任务.因此我使用了until/ retries/ delaykeybwords 的组合.

问题是,我想要retries从变量中获取数量.如果我写:

  retries: {{apache_test_retries}}
Run Code Online (Sandbox Code Playgroud)

我陷入了通常的Yaml Gotcha(http://docs.ansible.com/YAMLSyntax.html#gotchas).

相反,如果我写:

  retries: "{{apache_test_retries}}"
Run Code Online (Sandbox Code Playgroud)

我被说是价值不是整数.

ValueError:int()的基数为10的无效文字:'{{apache_test_retries}}'

这是我的完整代码:

- name: Wait for the application to be running
  local_action:
    uri
    url=http://{{webapp_url}}/health
    timeout=60
  register: res
  sudo: false
  when: updated.changed and apache_test_url is defined
  until: res.status == 200 and res['json'] is defined and res['json']['status'] == 'UP'
  retries: "{{apache_test_retries}}"
  delay: 1
Run Code Online (Sandbox Code Playgroud)

关于如何解决这个问题的任何想法?谢谢.

yaml jinja2 ansible

16
推荐指数
2
解决办法
4万
查看次数

django createsuperuser无法正常工作

.bash_profile中

export PATH="/Applications/MAMP/bin:/usr/local/bin:/usr/local/sbin:usr/local/$
export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"

export LANG="en_US.UTF-8"
Run Code Online (Sandbox Code Playgroud)

.轮廓

export PATH="/Applications/MAMP/bin:/usr/local/bin:/usr/local/sbin:usr/local/my$
export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"
export LANG="en_US.UTF-8"
Run Code Online (Sandbox Code Playgroud)

错误

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/Library/Python/2.6/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 70, in handle
    default_username = get_default_username()
  File "/Library/Python/2.6/site-packages/django/contrib/auth/management/__init__.py", line 105, in get_default_username
    default_username = get_system_username()
  File "/Library/Python/2.6/site-packages/django/contrib/auth/management/__init__.py", line …
Run Code Online (Sandbox Code Playgroud)

python eclipse django

8
推荐指数
2
解决办法
3931
查看次数

解析python中的json字段

是否有一个很好的教程解析python中的json属性?我希望能够解析"ok"字段的真实值.以及名为"client_ind_1"的索引.我不明白这个主题的python文档报道.如果有人可以向我解释或指出更好的资源,那就太棒了.

我的json字符串如下所示:

{
    "ok": true,
    "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
    },
    "indices": {
        "client_ind_2": {
            "index": {
                "primary_size": "2.5mb",
                "primary_size_in_bytes": 2710326,
                "size": "2.5mb",
                "size_in_bytes": 2710326
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

先感谢您.

python django simplejson

8
推荐指数
1
解决办法
3万
查看次数

乘以django模板

我正在循环推车项目,并希望将数量乘以单位价格,如下所示:

{% for cart_item in cart.cartitem_set.all %}
{{cart_item.quantity}}*{{cart_item.unit_price}}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

有可能做那样的事吗?任何其他方式!谢谢

python django django-templates

8
推荐指数
3
解决办法
2万
查看次数

用scrapy下载图片

我从scrapy开始,我有第一个真正的问题.它正在下载图片.所以这是我的蜘蛛.

from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.selector import HtmlXPathSelector
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from example.items import ProductItem
from scrapy.utils.response import get_base_url

import re

class ProductSpider(CrawlSpider):
    name = "product"
    allowed_domains = ["domain.com"]
    start_urls = [
            "http://www.domain.com/category/supplies/accessories.do"
    ]

    def parse(self, response):
        hxs = HtmlXPathSelector(response)
        items = []
        sites = hxs.select('//td[@class="thumbtext"]')
        number = 0
        for site in sites:
            item = ProductItem()
            xpath = '//div[@class="thumb"]/img/@src'
            item['image_urls'] = site.select(xpath).extract()[number]
            item['image_urls'] = 'http://www.domain.com' + item['image_urls']
            items.append(item)
            number = number + 1
        return items
Run Code Online (Sandbox Code Playgroud)

当我引用ITEM_PIPELINES …

python scrapy

7
推荐指数
2
解决办法
1万
查看次数

测试$ broadcast事件

角度测试有问题.我正试图测试$ broadcast被成功解雇了.我试图使用spyOn有一些奇怪的行为.如果您有任何建议,请帮助我一直试图解决这个问题几个小时.我的测试看起来像这样:

describe('Signup controller', function() {

  beforeEach(module('myApp'));

  describe('SignupCtrl', function(){
    var $scope, ctrl, $httpBackend, AUTH_EVENTS, $rootScope;

    beforeEach(inject(function($injector, $controller,
      _$httpBackend_, _apiUrl_, _AUTH_EVENTS_){

        $rootScope = $injector.get('$rootScope');
        $scope = $rootScope.$new();
        ctrl = $controller('SignupCtrl', {$scope: $scope});
        $httpBackend = _$httpBackend_;
        apiUrl = _apiUrl_;
        AUTH_EVENTS = _AUTH_EVENTS_;
        spyOn($rootScope, "$broadcast");
      }
    ));

    afterEach(function() {
      $httpBackend.verifyNoOutstandingExpectation();
      $httpBackend.verifyNoOutstandingRequest();
    });

    it('should show error message from API', function() {
      var apiMessage = 'That email already exists.';
      $httpBackend.expectPOST('/users').respond(400, {
        message: apiMessage
      });

      // call controller register function with mock empty credentials
      $scope.register({});

      $httpBackend.flush(); …
Run Code Online (Sandbox Code Playgroud)

jasmine angularjs

4
推荐指数
1
解决办法
3191
查看次数

Python从webservice中保存xml

我正在使用webservice从中获取某个xml文件.它与urllib2工作正常我得到xml作为fileobject.所以我想知道什么是最快的方式存储在内存中的某个地方甚至不存储只是解析它.

我在该对象上尝试了iterparse并且它需要太长时间,除非我先将它保存在文件中,然后iterparse花费的时间要少得多.

所以现在我首先使用这个代码将它存储在本地,然后使用我想要的那个文件,我想知道是否有最快的方法,最快的方式存储文件.

url = "webservice"
s = urllib2.urlopen(url)

file = open("export.xml",'wb+')
for line in s:
    file.write(line)
Run Code Online (Sandbox Code Playgroud)

谢谢

python

3
推荐指数
1
解决办法
9956
查看次数