Class: Chef::Provider::Package::Dnf::PythonHelper
- Inherits:
-
Object
- Object
- Chef::Provider::Package::Dnf::PythonHelper
show all
- Includes:
- Mixin::ShellOut, Mixin::Which, Singleton
- Defined in:
- lib/chef/provider/package/dnf/python_helper.rb
Constant Summary
collapse
- DNF_HELPER =
::File.expand_path(::File.join(::File.dirname(__FILE__), "dnf_helper.py")).freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
apply_default_env, maybe_add_timeout, #shell_out, #shell_out!
Instance Attribute Details
#stderr ⇒ Object
Returns the value of attribute stderr.
34
35
36
|
# File 'lib/chef/provider/package/dnf/python_helper.rb', line 34
def stderr
@stderr
end
|
#stdin ⇒ Object
Returns the value of attribute stdin.
32
33
34
|
# File 'lib/chef/provider/package/dnf/python_helper.rb', line 32
def stdin
@stdin
end
|
#stdout ⇒ Object
Returns the value of attribute stdout.
33
34
35
|
# File 'lib/chef/provider/package/dnf/python_helper.rb', line 33
def stdout
@stdout
end
|
#wait_thr ⇒ Object
Returns the value of attribute wait_thr.
35
36
37
|
# File 'lib/chef/provider/package/dnf/python_helper.rb', line 35
def wait_thr
@wait_thr
end
|
Instance Method Details
#check ⇒ Object
66
67
68
|
# File 'lib/chef/provider/package/dnf/python_helper.rb', line 66
def check
start if stdin.nil?
end
|
#compare_versions(version1, version2) ⇒ Object
70
71
72
73
74
75
76
77
|
# File 'lib/chef/provider/package/dnf/python_helper.rb', line 70
def compare_versions(version1, version2)
with_helper do
json = build_version_query("versioncompare", [version1, version2])
Chef::Log.trace "sending '#{json}' to python helper"
stdin.syswrite json + "\n"
stdout.sysread(4096).chomp.to_i
end
end
|
#dnf_command ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/chef/provider/package/dnf/python_helper.rb', line 39
def dnf_command
@dnf_command ||= begin
cmd = which("platform-python", "python", "python3", "python2", "python2.7", extra_path: "/usr/libexec") do |f|
shell_out("#{f} -c 'import dnf'").exitstatus == 0
end
raise Chef::Exceptions::Package, "cannot find dnf libraries, you may need to use yum_package" unless cmd
"#{cmd} #{DNF_HELPER}"
end
end
|
#query(action, provides, version = nil, arch = nil) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/chef/provider/package/dnf/python_helper.rb', line 80
def query(action, provides, version = nil, arch = nil)
with_helper do
json = build_query(action, provides, version, arch)
Chef::Log.trace "sending '#{json}' to python helper"
stdin.syswrite json + "\n"
output = stdout.sysread(4096).chomp
Chef::Log.trace "got '#{output}' from python helper"
version = parse_response(output)
Chef::Log.trace "parsed #{version} from python helper"
version
end
end
|
#reap ⇒ Object
56
57
58
59
60
61
62
63
64
|
# File 'lib/chef/provider/package/dnf/python_helper.rb', line 56
def reap
unless wait_thr.nil?
Process.kill("KILL", wait_thr.pid) rescue nil
stdin.close unless stdin.nil?
stdout.close unless stdout.nil?
stderr.close unless stderr.nil?
wait_thr.value end
end
|
#restart ⇒ Object
93
94
95
96
|
# File 'lib/chef/provider/package/dnf/python_helper.rb', line 93
def restart
reap
start
end
|
#start ⇒ Object
51
52
53
54
|
# File 'lib/chef/provider/package/dnf/python_helper.rb', line 51
def start
ENV["PYTHONUNBUFFERED"] = "1"
@stdin, @stdout, @stderr, @wait_thr = Open3.popen3(dnf_command)
end
|