小编Sim*_*eth的帖子

python:两个时间日期字符串的差异

我有两个日期字符串(取自用户输入,可能会有很大差异)

s1 = '2011:10:01:10:30:00'
s2 = '2011:10:01:11:15:00'
Run Code Online (Sandbox Code Playgroud)

我希望找到两者之间的差异作为分钟。

我应该如何着手解决这个问题?

python datetime datediff

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

ansible无法获得inventory_hostname

我正在尝试获取正在处理的服务器的简称.

我在jinja2中有这个:

ServerAlias graphite.{{ hostvars[inventory_hostname] }}
ServerAlias graphite.{{ hostvars[inventory_hostname] }}.{{dc}}.{{subnet}}
Run Code Online (Sandbox Code Playgroud)

上面只是溢出了整个事实,而不仅仅是短名称.

这就是hosts.yaml的样子:

graphite.experimental.com dc=lv1 subnet=coupons.lan
Run Code Online (Sandbox Code Playgroud)

jinja2 ansible ansible-playbook

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

烧瓶蓝图列出路线

我有一个带有以下树的烧瓶应用程序:

root/
  - modules/
    __init__.py
    - common/
        __init__.py
    - citrixlb/
        __init__.py # blueprint code
        citrixlb.py # module class
    - aws/
        __init__.py # blueprint code
        aws.py      # module class
Run Code Online (Sandbox Code Playgroud)

所以我想知道,有没有办法动态列出所有蓝图的所有路线?

我有这个root/__init__.py

# import our modules
from modules.citrixlb import *
from modules.aws import *

app.register_blueprint(aws)
app.register_blueprint(citrix)
Run Code Online (Sandbox Code Playgroud)

如果我可以动态列出所有蓝图的所有路由,我就可以自动生成链接。

例子:

落下: AWS

  • /aws

  • /aws/ec2

  • /aws/subnets

python blueprint flask python-2.7

5
推荐指数
1
解决办法
6815
查看次数

kubectl 创建带标签的命名空间

有没有一种方法可以使用一个标签创建名称空间 kubectl

例如

kubectl create ns <newnamespace> label=appid:foo12
Run Code Online (Sandbox Code Playgroud)

而不是使用kubectl apply -f <somefile>

kubernetes kubectl

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

在可变宽度列中打印数组内容

我希望以这样的方式修改我的代码,使列扩展以容纳数据.

下面是一个断行的示例

+========+=========+===============+=============+=============+
| Record | Cluster | Current Build | Current Use | Environment |
+--------+---------+---------------+-------------+-------------+
| 3      | 1       | v44           | v44 Live (currently - new company cluster)| PROD        |
+--------+---------+---------------+-------------+-------------+
Run Code Online (Sandbox Code Playgroud)

这是我正在使用的(kludgy)代码

sub printData {
   if (@_) {
      # print the data grid top border
      printf ("%10s%10s%15s%14s%14s",'+'.('=' x 8).'+',('=' x 9).'+',('=' x 15).'+',('=' x 13).'+',('=' x 13).'+');
      print "\n";
      # print the data grid column titles
      printf ("%-9s%-10s%-16s%-14s%-15s",'| Record ','| Cluster ','| Current Build ','| Current Use …
Run Code Online (Sandbox Code Playgroud)

arrays perl printf dynamic-columns

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

xslt 2.0 将当前日期与开始和结束日期进行比较

我有以下输出:

 <forms>
   <form id="15">
      <start>2013-12-09</start>
      <end>2014-01-05</end>
   </form>
</forms>
Run Code Online (Sandbox Code Playgroud)

我想测试一下当前日期是否等于或大于“开始”并且小于或等于“结束”

我将如何进行测试?

我想到的是:

<xsl:variable name="fstart">
   <xsl:value-of select="start" />
</xsl:variable>
<xsl:variable name="fend">
   <xsl:value-of select="end" />
</xsl:variable>

<xsl:choose>
   <xsl:when test="$fstart >= currentdate xor currentdate <= $fend ">
      <!-- do stuff -->
   </xsl:when>

   <xsl:otherwise>
   </xsl:otherwise>
</xsl:choose>
Run Code Online (Sandbox Code Playgroud)

xslt date xslt-2.0

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

XSLT 1.0比较日期

我想将当前日期与开始日期和结束日期进行比较.

XML是:

<forms>
  <form id="11">
     <start>somedate</start>
     <end>someotherdate</end>
   </form>
</forms>
Run Code Online (Sandbox Code Playgroud)

我目前正在尝试:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:ex="http://exslt.org/dates-and-times" extension-element-prefixes="ex" >

<xsl:choose>
   <xsl:when test="end != ''                
      and start != '' 
      and ex:date(start) &lt;= current-date() 
      and current-date() &lt;= ex:date(end)">
      <!-- Do Stuff -->
   </xsl:when>
</xsl:choose>
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

xmlXPathCompOpEval: function current-date not found
XPath error : Unregistered function
XPath error : Stack usage errror
<ul class="ccb_forms_ul"></ul>
Run Code Online (Sandbox Code Playgroud)

xslt date xslt-1.0

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

如何在ansible中处理未经验证的apt安装

从我们自己的repo安装apt软件包时,我在CLI上获得以下内容:

Install these packages without verification? [y/N]
Run Code Online (Sandbox Code Playgroud)

问题是,如何使用ansible成功安装这些软件包?

即使使用force选项,ansible也无法安装包.

我正在使用的命令是:

- apt: name=coupons-graphite dpkg_options='force' state=present
Run Code Online (Sandbox Code Playgroud)

apt apt-get ansible ansible-playbook

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

在ansible中列出切片的字符串

2.2 版

我想获得以下变量的切片,我该怎么做?

hostvars[inventory_hostname]['ansible_hostname']|list

基本上我有一个主机名,hostname001我希望检索最后两个字符。

How do I split it and slice it?

ansible ansible-2.x

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

如何在python中指定zip文件的压缩级别?

如何在python中压缩文件以及如何指定压缩级别?

到目前为止,我有以下代码,我得到的错误是:

Zip("log4j.dl-service.log.2013-05-03-22",9)
AttributeError: 'str' object has no attribute 'ZipFile'
Run Code Online (Sandbox Code Playgroud)

码:

import zipfile
import fileinput

def Zip(file,level):
    """
    This function uses the zip library native to python to compress files with
    Usage: Zip(file,level)
    """

    if file and level:
        try:
            zipfile = file+'.zip'
            output = zipfile.ZipFile(zipfile, 'wb')
            for line in fileinput.input(file):
                output.write(line)
            output.close()
            if os.path.exists(zipfile):
                return zipfile
            else:
                logMe('critical',"zip failed in Zip()")
                return False

        except Exception,e:
            logMe('critical',e)
Run Code Online (Sandbox Code Playgroud)

python zip zipfile

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