小编Sco*_*oby的帖子

ruby unzip - 未初始化的常量ZIP :: File失败

我有以下ruby代码:

require 'HTTPClient'
require 'rubygems'
require 'zip'

def self.unzip(data, dest_dir)
  ::Zip::File.open_buffer(data) do |fzip|
    fzip.each do |entry|
     path = File.join(dest_dir, entry.name)
     puts "here"
     FileUtils::mkdir_p(File.dirname(path))
     fzip.extract(entry, path) unless File.exist?(path)
   #fzip.close
    end
  end
end

def self.fetch_from_url(url, dest_dir)
  response = HTTPClient.get(url, follows_redirect: true)
  if response.status == 200
    unzip(response.body, dest_dir)
  else
    raise 'Could not fetch files from 3scale'
  end
end


url = 'link/artifactory/zip-release-local/djin/3Sroxy/1.0.5/configuration.zip'
fetch_from_url(url, "/Users/something/")
Run Code Online (Sandbox Code Playgroud)

当我在Mac ruby​​ 2.0.0p481中运行它时,它工作正常并解压缩文件夹,但是当我在ruby 1.8.7中运行相同的centOS 6.6时,它会失败并显示以下内容:

[root@ip-10-201-90-206 ~]# sudo ruby test/ex.rb 
test/ex.rb:7:in `unzip': uninitialized constant Zip::File (NameError)
    from test/ex.rb:20:in `fetch_from_url'
    from …
Run Code Online (Sandbox Code Playgroud)

ruby rubygems ruby-on-rails chef-infra ruby-on-rails-3

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

将"使用参数构建"从管道中的scm传递给Jenkinsfile

我在jenkins 2.x并使用管道.

我已将作业配置为使用param构建并具有字符串参数:

参数

我还从github获取了Jenkinsfile(来自脚本的管道):

现在在我的Jenkinsfile中,我使用的是param:$ {githubUrl},它会抛出错误:

stdout:stderr:致命:'$ {githubUrl}'似乎不是git存储库

因此,如果直接编写管道脚本,这可行,但从scm获取失败.任何想法如何解决它?

parameters groovy jenkins jenkins-plugins jenkins-pipeline

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

删除保存值的python dict中的一个级别

我有以下python字典:

'load_balancers': {'App': {'DJMatcher': {'security_group': 'sg-618d1c05', 'service_name': 'djmatcher/svc', 'certificateId': 'net', 'health_check_path': '/djmatcherstatus/ma.html', 'DNS': {'fde': {'record_name': 'platform-enrichment-djmatcher', 'ttl': 60}}}}}
Run Code Online (Sandbox Code Playgroud)

现在它基本上代表以下YAML:

 LoadBalancers:
    App:
        DJMatcher:
            certificateId: 'net'
            health_check_path: /djmatcherstatus/ma.html
            security_group: *svc_sg1
            service_name: *sn
            DNS:
                fde:
                    record_name: platform-enrichment-djmatcher
                    ttl: 60
Run Code Online (Sandbox Code Playgroud)

我想删除第二级密钥 - "App"并保持其余部分原样,这意味着生成的python字典应该成为我删除密钥App的地方,但现在该值变为其父密钥"load_balancers"的值:

'load_balancers': {'DJMatcher': {'security_group': 'sg-618d1c05', 'service_name': 'djmatcher/svc', 'certificateId': 'net', 'health_check_path': '/djmatcherstatus/ma.html', 'DNS': {'fde': {'record_name': 'platform-enrichment-djmatcher', 'ttl': 60}}}}
Run Code Online (Sandbox Code Playgroud)

有什么好办法实现这个目标吗?

python json dictionary python-2.7 python-3.x

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

从ruby中的数组中获取最新版本

我有一个名为unique_versions的版本号数组,它们不断增加:

1.7.16
1.7.14
1.7.13
1.7.12
1.7.9
1.7.7
1.7.5
1.7.4
1.7.2
1.6.2
1.2.1
1.2.0
1.1.0
0.0.1
Run Code Online (Sandbox Code Playgroud)

我需要从阵列中获取最新的(1.7.16).什么是最优雅的红宝石做法呢?我通过以下代码获取此数组:

require "json"
require "open-uri"
require 'openssl'

string_object = open("https://xxx", :http_basic_authentication=>["xxx"], :ssl_verify_mode=>OpenSSL::SSL::VERIFY_NONE)
json_file = JSON.parse(string_object.read)
version_array = Array.new
json_file["results"].each do |version|
    version_array.push(version["version"].sub /-.*$/, '')
end
unique_versions=(version_array.uniq)
Run Code Online (Sandbox Code Playgroud)

ruby rubygems ruby-on-rails chef-infra

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

在python中解析带有英语和印地语字符的csv文件

我试图解析一个csv文件,其中包含英语和印地语字符,我正在使用utf-16.它工作正常,但一旦它击中印地语charatcer它失败了.我在这里不知所措.

继承人代码 - >

import csv
import codecs

csvReader = csv.reader(codecs.open('/home/kuberkaul/Downloads/csv.csv', 'rb', 'utf-16'))
for row in csvReader:
        print row
Run Code Online (Sandbox Code Playgroud)

我得到的错误是Traceback(最近一次调用最后一次):

>  File "csvreader.py", line 8, in <module>
>     for row in csvReader: UnicodeEncodeError: 'ascii' codec can't encode characters in position 11-18: ordinal not in range(128)
> kuberkaul@ubuntu:~/Desktop$
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

编辑1:

我尝试了解决方案,并使用了unicdoe csv阅读器,现在它给出了错误:

UnicodeDecodeError:'ascii'编解码器无法解码位置0的字节0xff:序数不在范围内(128)

代码是:

import csv
import codecs, io


def unicode_csv_reader(unicode_csv_data, dialect=csv.excel, **kwargs):
    # csv.py doesn't do Unicode; encode temporarily as UTF-8:
    csv_reader = csv.reader(utf_8_encoder(unicode_csv_data),
                            dialect=dialect, **kwargs)
    for row in csv_reader: …
Run Code Online (Sandbox Code Playgroud)

python csv utf-16 python-2.7

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

tar zxf 与 -xvf 之间的区别

我有http://agentzh.org/misc/nginx/openresty-1.9.7.3.tar的下载版本。我将其重命名为 openresty-1.9.7.3.tar.gz。

我正在尝试在 centOS-6.x 中执行以下操作:

tar zxf openresty-1.9.7.3.tar.gz
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
Run Code Online (Sandbox Code Playgroud)

然而 :

tar -xvf openresty-1.9.7.3.tar.gz 工作并解压到 openresty-1.9.7.3.tar.gz。

第一个不起作用的任何原因?它适用于我的个人笔记本电脑,但不适用于服务器。

linux zip gzip centos tar

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

使用jenkins API时,reconfig_job失败

我正在使用jenkins rest API通过作业递归,然后重新配置这一作业。除一种方法外,所有方法均有效。他是我的代码:

def get_server_instance():
    jenkins_url = 'xxxx'
    #server = Jenkins(jenkins_url, username = '', password = '')
    # Connect to instance - username and password are optional
    server = jenkins.Jenkins(jenkins_url, username = '', password = '')
    return server


def get_job_details():
    # Refer Example #1 for definition of function 'get_server_instance'
    server = get_server_instance()
    for job in server.get_jobs_list():
        if job == "GithubMigration":
            configuration = server.get_job(job).get_config().encode('utf-8')
            #server.reconfig_job(job, configuration)
            if server.has_job("GithubMigration"):
                server.reconfig_job('GithubMigration', config_xml)
Run Code Online (Sandbox Code Playgroud)

它获取我的configuration.xml,也找到了工作,但在server.reconfig_job('GithubMigration',config_xml)上失败并显示错误AttributeError:'Jenkins'对象没有属性'reconfig_job'

当显然此功能存在于jenkins rest API中并且是的时候,我正在从jenkinsapi.jenkins import Jenkins导入jenkins。

编辑1-我卸载了Jenkinsapi,只有python-jenkins模块,现在即使在说之前它也失败了

AttributeError:'module'对象没有属性'Jenkins'到行:AttributeError:'module'对象没有属性'Jenkins' …

python python-2.7 python-3.x jenkins jenkins-cli

0
推荐指数
1
解决办法
4730
查看次数

在bash中合并两个json(无jq)

我有两个json:

env.json

{  
   "environment":"INT"
}
Run Code Online (Sandbox Code Playgroud)

Roles.json

{  
   "run_list":[  
      "recipe[splunk-dj]",
      "recipe[tideway]",
      "recipe[AlertsSearch::newrelic]",
      "recipe[AlertsSearch]"
   ]
}
Run Code Online (Sandbox Code Playgroud)

预期的输出应该是这样的:

{  
       "environment":"INT",
    "run_list":[  
          "recipe[splunk-dj]",
          "recipe[tideway]",
          "recipe[AlertsSearch::newrelic]",
          "recipe[AlertsSearch]"
       ]
    }
Run Code Online (Sandbox Code Playgroud)

我只需要使用可用的内置bash命令将这两个json(以及其他类似这两个)合并为一个json。

我只能使用sed,cat,echo,tail,wc。

bash terminal cat

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

在python27中使用输入内部变量失败并出现语法问题

我有以下代码在py 27和36中都有效:

all_config_msgs = ['Okta App URL. E.g https://acme.okta.com/home/amazon_aws/b07384d113edec49eaa6/123: ','Organization username. E.g jane.doe@acme.com: ']
config_details = []
for config_msg in all_config_msgs:
    config_details.append(input(config_msg))
Run Code Online (Sandbox Code Playgroud)

在py 36和27中,我得到输入提示:

Okta App URL.例如https://acme.okta.com/home/amazon_aws/b07384d113edec49eaa6/123:

  • 在py 36中,我把:

any_reply

它成功了

  • 在py 27中,我把:

any_reply

失败了

config_details.append(input(config_msg))
File "<string>", line 1
https://acme.okta.com/home/amazon_aws/b07384d113edec49eaa6/123
     ^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)

仅供参考 - 在py 27中,如果我将响应设置为"any_reply",它就可以工作 但我需要有一种方法来回答没有双引号/引号.

我在py 27中理解,输入正在进行eval但是将输入提示作为变量而不会出现上述错误的好方法.

python input python-2.7 python-3.x

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