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
#a_to_s, #clean_array, #shell_out, #shell_out!, #shell_out_compact, #shell_out_compact!, #shell_out_compact_timeout, #shell_out_compact_timeout!, #shell_out_with_systems_locale, #shell_out_with_systems_locale!
#enforce_path_sanity, #sanitized_path
#where, #which
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
60
61
62
|
# File 'lib/chef/provider/package/dnf/python_helper.rb', line 60
def check
start if stdin.nil?
end
|
#compare_versions(version1, version2) ⇒ Object
64
65
66
67
68
69
70
71
|
# File 'lib/chef/provider/package/dnf/python_helper.rb', line 64
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
|
# File 'lib/chef/provider/package/dnf/python_helper.rb', line 39
def dnf_command
@dnf_command ||= which("python", "python3", "python2", "python2.7") do |f|
shell_out("#{f} -c 'import dnf'").exitstatus == 0
end + " #{DNF_HELPER}"
end
|
#query(action, provides, version = nil, arch = nil) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/chef/provider/package/dnf/python_helper.rb', line 74
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
50
51
52
53
54
55
56
57
58
|
# File 'lib/chef/provider/package/dnf/python_helper.rb', line 50
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
87
88
89
90
|
# File 'lib/chef/provider/package/dnf/python_helper.rb', line 87
def restart
reap
start
end
|
#start ⇒ Object
45
46
47
48
|
# File 'lib/chef/provider/package/dnf/python_helper.rb', line 45
def start
ENV["PYTHONUNBUFFERED"] = "1"
@stdin, @stdout, @stderr, @wait_thr = Open3.popen3(dnf_command)
end
|