Class: Chef::Provider::Package::Dnf::PythonHelper
- Inherits:
-
Object
- Object
- Chef::Provider::Package::Dnf::PythonHelper
- Includes:
- Mixin::ShellOut, Mixin::Which, Singleton
- Defined in:
- lib/chef/provider/package/dnf/python_helper.rb
Constant Summary collapse
- DNF_HELPER =
::File.(::File.join(::File.dirname(__FILE__), "dnf_helper.py")).freeze
Instance Attribute Summary collapse
-
#stderr ⇒ Object
Returns the value of attribute stderr.
-
#stdin ⇒ Object
Returns the value of attribute stdin.
-
#stdout ⇒ Object
Returns the value of attribute stdout.
-
#wait_thr ⇒ Object
Returns the value of attribute wait_thr.
Instance Method Summary collapse
- #check ⇒ Object
- #dnf_command ⇒ Object
- #query(action, provides, version = nil, arch = nil) ⇒ Object
- #reap ⇒ Object
- #restart ⇒ Object
- #start ⇒ Object
Methods included from Mixin::ShellOut
#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!
Methods included from Mixin::PathSanity
#enforce_path_sanity, #sanitized_path
Methods included from Mixin::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 |
#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
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/chef/provider/package/dnf/python_helper.rb', line 65 def query(action, provides, version = nil, arch = nil) with_helper do json = build_query(action, provides, version, arch) Chef::Log.debug "sending '#{json}' to python helper" stdin.syswrite json + "\n" output = stdout.sysread(4096).chomp Chef::Log.debug "got '#{output}' from python helper" version = parse_response(output) Chef::Log.debug "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 # this calls waitpit() end end |
#restart ⇒ Object
78 79 80 81 |
# File 'lib/chef/provider/package/dnf/python_helper.rb', line 78 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 |