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) ⇒ Object
- #flush ⇒ Object
-
#initialize ⇒ YumCache
constructor
A new instance of YumCache.
- #installed_version(package_name) ⇒ Object
- #load_data ⇒ Object (also: #reload)
- #refresh ⇒ Object
- #stale? ⇒ Boolean
- #version(package_name, type) ⇒ Object
Methods included from Mixin::Command
handle_command_failures, not_if, only_if, output_of_command, popen4, run_command, run_command_with_systems_locale
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) ⇒ Object
100 101 102 |
# File 'lib/chef/provider/package/yum.rb', line 100 def candidate_version(package_name) version(package_name, :available) end |
#flush ⇒ Object
104 105 106 |
# File 'lib/chef/provider/package/yum.rb', line 104 def flush @data.clear end |
#installed_version(package_name) ⇒ Object
96 97 98 |
# File 'lib/chef/provider/package/yum.rb', line 96 def installed_version(package_name) version(package_name, :installed) 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 |
# 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 @data[name][type_sym] = { :epoch => epoch, :version => version, :release => release, :arch => arch } 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) ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/chef/provider/package/yum.rb', line 86 def version(package_name, type) if (x = @data[package_name]) if (y = x[type]) return "#{y[:version]}-#{y[:release]}" end end nil end |