Class: Chef::Provider::Package::Yum::PythonHelper
- Inherits:
-
Object
- Object
- Chef::Provider::Package::Yum::PythonHelper
- Includes:
- Mixin::ShellOut, Mixin::Which, Singleton
- Defined in:
- lib/chef/provider/package/yum/python_helper.rb
Constant Summary collapse
- YUM_HELPER =
::File.(::File.join(::File.dirname(__FILE__), "yum_helper.py")).freeze
Instance Attribute Summary collapse
-
#inpipe ⇒ Object
Returns the value of attribute inpipe.
-
#outpipe ⇒ Object
Returns the value of attribute outpipe.
-
#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
- #compare_versions(version1, version2) ⇒ Object
- #install_only_packages(name) ⇒ Object
- #options_params(options) ⇒ Object
-
#package_query(action, provides, version: nil, arch: nil, options: {}) ⇒ Object
NB: “options” here is the yum_package options hash and is deliberately not **opts.
- #reap ⇒ Object
- #restart ⇒ Object
- #start ⇒ Object
- #yum_command ⇒ 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
#inpipe ⇒ Object
Returns the value of attribute inpipe.
36 37 38 |
# File 'lib/chef/provider/package/yum/python_helper.rb', line 36 def inpipe @inpipe end |
#outpipe ⇒ Object
Returns the value of attribute outpipe.
37 38 39 |
# File 'lib/chef/provider/package/yum/python_helper.rb', line 37 def outpipe @outpipe end |
#stderr ⇒ Object
Returns the value of attribute stderr.
35 36 37 |
# File 'lib/chef/provider/package/yum/python_helper.rb', line 35 def stderr @stderr end |
#stdin ⇒ Object
Returns the value of attribute stdin.
33 34 35 |
# File 'lib/chef/provider/package/yum/python_helper.rb', line 33 def stdin @stdin end |
#stdout ⇒ Object
Returns the value of attribute stdout.
34 35 36 |
# File 'lib/chef/provider/package/yum/python_helper.rb', line 34 def stdout @stdout end |
#wait_thr ⇒ Object
Returns the value of attribute wait_thr.
38 39 40 |
# File 'lib/chef/provider/package/yum/python_helper.rb', line 38 def wait_thr @wait_thr end |
Instance Method Details
#check ⇒ Object
75 76 77 |
# File 'lib/chef/provider/package/yum/python_helper.rb', line 75 def check start if stdin.nil? end |
#compare_versions(version1, version2) ⇒ Object
79 80 81 |
# File 'lib/chef/provider/package/yum/python_helper.rb', line 79 def compare_versions(version1, version2) query("versioncompare", { "versions" => [version1, version2] }).to_i end |
#install_only_packages(name) ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/chef/provider/package/yum/python_helper.rb', line 83 def install_only_packages(name) query_output = query("installonlypkgs", { "package" => name }) if query_output == "False" return false elsif query_output == "True" return true end end |
#options_params(options) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/chef/provider/package/yum/python_helper.rb', line 92 def () .each_with_object({}) do |opt, h| if opt =~ /--enablerepo=(.+)/ $1.split(",").each do |repo| h["enablerepos"] ||= [] h["enablerepos"].push(repo) end end if opt =~ /--disablerepo=(.+)/ $1.split(",").each do |repo| h["disablerepos"] ||= [] h["disablerepos"].push(repo) end end end end |
#package_query(action, provides, version: nil, arch: nil, options: {}) ⇒ Object
NB: “options” here is the yum_package options hash and is deliberately not **opts
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/chef/provider/package/yum/python_helper.rb', line 111 def package_query(action, provides, version: nil, arch: nil, options: {}) parameters = { "provides" => provides, "version" => version, "arch" => arch } repo_opts = ( || {}) parameters.merge!(repo_opts) query_output = query(action, parameters) version = parse_response(query_output.lines.last) Chef::Log.trace "parsed #{version} from python helper" # XXX: for now we restart after every query with an enablerepo/disablerepo to clean the helpers internal state restart unless repo_opts.empty? version end |
#reap ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/chef/provider/package/yum/python_helper.rb', line 57 def reap unless wait_thr.nil? Process.kill("INT", wait_thr.pid) rescue nil begin Timeout.timeout(3) do wait_thr.value # this calls waitpid() end rescue Timeout::Error Process.kill("KILL", wait_thr.pid) rescue nil end stdin.close unless stdin.nil? stdout.close unless stdout.nil? stderr.close unless stderr.nil? inpipe.close unless inpipe.nil? outpipe.close unless outpipe.nil? end end |
#restart ⇒ Object
123 124 125 126 |
# File 'lib/chef/provider/package/yum/python_helper.rb', line 123 def restart reap start end |
#start ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/chef/provider/package/yum/python_helper.rb', line 48 def start ENV["PYTHONUNBUFFERED"] = "1" @inpipe, inpipe_write = IO.pipe outpipe_read, @outpipe = IO.pipe @stdin, @stdout, @stderr, @wait_thr = Open3.popen3("#{yum_command} #{outpipe_read.fileno} #{inpipe_write.fileno}", outpipe_read.fileno => outpipe_read, inpipe_write.fileno => inpipe_write, close_others: false) outpipe_read.close inpipe_write.close end |
#yum_command ⇒ Object
42 43 44 45 46 |
# File 'lib/chef/provider/package/yum/python_helper.rb', line 42 def yum_command @yum_command ||= which("python", "python2", "python2.7") do |f| shell_out("#{f} -c 'import yum'").exitstatus == 0 end + " #{YUM_HELPER}" end |