Class: Chef::Provider::Package::Yum::YumCache
- Inherits:
-
Object
- Object
- Chef::Provider::Package::Yum::YumCache
- Includes:
- Mixin::Command, Singleton
- Defined in:
- lib/chef/provider/package/yum.rb
Instance Method Summary collapse
- #candidate_version(package_name, arch) ⇒ Object
- #flush ⇒ Object
-
#initialize ⇒ YumCache
constructor
A new instance of YumCache.
- #installed_version(package_name, arch) ⇒ Object
- #load_data ⇒ Object (also: #reload)
- #refresh ⇒ Object
- #stale? ⇒ Boolean
- #version(package_name, type, arch) ⇒ Object
Methods included from Mixin::Command
#chdir_or_tmpdir, #handle_command_failures, #not_if, #only_if, #output_of_command, #run_command, #run_command_with_systems_locale
Methods included from Mixin::Command::Windows
Methods included from Mixin::Command::Unix
Constructor Details
#initialize ⇒ YumCache
Returns a new instance of YumCache.
33 34 35 |
# File 'lib/chef/provider/package/yum.rb', line 33 def initialize load_data end |
Instance Method Details
#candidate_version(package_name, arch) ⇒ Object
111 112 113 |
# File 'lib/chef/provider/package/yum.rb', line 111 def candidate_version(package_name, arch) version(package_name, :available, arch) end |
#flush ⇒ Object
115 116 117 |
# File 'lib/chef/provider/package/yum.rb', line 115 def flush @data.clear end |
#installed_version(package_name, arch) ⇒ Object
107 108 109 |
# File 'lib/chef/provider/package/yum.rb', line 107 def installed_version(package_name, arch) version(package_name, :installed, arch) end |
#load_data ⇒ Object Also known as: reload
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/chef/provider/package/yum.rb', line 58 def load_data @data = Hash.new error = String.new helper = ::File.join(::File.dirname(__FILE__), 'yum-dump.py') status = popen4("python #{helper}", :waitlast => true) do |pid, stdin, stdout, stderr| stdout.each do |line| line.chomp! name, type, epoch, version, release, arch = line.split(',') type_sym = type.to_sym if !@data.has_key?(name) @data[name] = Hash.new end if !@data[name].has_key?(type_sym) @data[name][type_sym] = Hash.new end @data[name][type_sym][arch] = { :epoch => epoch, :version => version, :release => release } end error = stderr.readlines end unless status.exitstatus == 0 raise Chef::Exceptions::Package, "yum failed - #{status.inspect} - returns: #{error}" end @updated_at = Time.now end |
#refresh ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/chef/provider/package/yum.rb', line 50 def refresh if @data.empty? reload elsif stale? reload end end |
#stale? ⇒ Boolean
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/chef/provider/package/yum.rb', line 37 def stale? interval = Chef::Config[:interval].to_f # run once mode if interval == 0 return false elsif (Time.now - @updated_at) > interval return true end false end |
#version(package_name, type, arch) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/chef/provider/package/yum.rb', line 89 def version(package_name, type, arch) if (x = @data[package_name]) if (y = x[type]) if arch if (z = y[arch]) return "#{z[:version]}-#{z[:release]}" end else # no arch specified - take the first match z = y.to_a[0][1] return "#{z[:version]}-#{z[:release]}" end end end nil end |