# File lib/yumrepo.rb, line 115 def primary pl = [] @repomd.xpath("/xmlns:repomd/xmlns:data[@type=\"primary\"]/xmlns:location").each do |p| pl << File.join(@url, p['href']) end if not @primary_xml or @primary_xml.closed? @primary_xml = _open_file("primary.xml.gz", @url_digest, pl.first) end @primary_xml end
class YumRepo::Repomd
Public Class Methods
new(url)
click to toggle source
Rasises exception if can't retrieve repomd.xml
# File lib/yumrepo.rb, line 79 def initialize(url) @settings = Settings.instance @settings.init @url = url if @url =~ /\/repodata\/?/ @url.gsub! '/repodata', '' end @url_digest = Digest::MD5.hexdigest(@url) @repomd_file = File.join(@settings.cache_path, @url_digest, 'repomd.xml') if @settings.cache_enabled and File.exist?(@repomd_file) @settings.log.debug "Using catched repomd.xml at #{@repomd_file}" f = open @repomd_file else @settings.log.debug "Fetching repomd.xml from #{@url}" f = open "#{@url}/repodata/repomd.xml" if @settings.cache_enabled FileUtils.mkdir_p File.join(@settings.cache_path, @url_digest) @settings.log.debug "Caching repomd.xml for #{@url} at #{@repomd_file}" File.open(File.join(@settings.cache_path, @url_digest, 'repomd.xml'), 'w') do |xml| xml.puts f.read end f = open(@repomd_file) end end @repomd = Nokogiri::XML(f) end
Public Instance Methods
filelists()
click to toggle source
# File lib/yumrepo.rb, line 107 def filelists fl = [] @repomd.xpath("/xmlns:repomd/xmlns:data[@type=\"filelists\"]/xmlns:location").each do |f| fl << File.join(@url, f['href']) end fl end
meta()
click to toggle source
# File lib/yumrepo.rb, line 127 def meta def to_sym(h) h.inject({}) { |result, (key, value)| new_key = case key when String then key.to_sym else key end new_value = case value when Hash then to_sym(value) else value end result[new_key] = new_value result } end Hash[Hash.from_xml(@repomd.to_s)["repomd"]["data"].map {|h| [h["type"].to_sym, to_sym(h)] }] end
other()
click to toggle source
# File lib/yumrepo.rb, line 145 def other pl = [] @repomd.xpath("/xmlns:repomd/xmlns:data[@type=\"other\"]/xmlns:location").each do |p| pl << File.join(@url, p['href']) end if not @other_xml or @other_xml.closed? @other_xml = _open_file("other.xml.gz", @url_digest, pl.first) end @other_xml end
primary()
click to toggle source
to_sym(h)
click to toggle source
# File lib/yumrepo.rb, line 128 def to_sym(h) h.inject({}) { |result, (key, value)| new_key = case key when String then key.to_sym else key end new_value = case value when Hash then to_sym(value) else value end result[new_key] = new_value result } end
Private Instance Methods
_open_file(filename, cache_dir_name, data_url)
click to toggle source
# File lib/yumrepo.rb, line 158 def _open_file(filename, cache_dir_name, data_url) cache_file_name = File.join(@settings.cache_path, cache_dir_name, filename) if @settings.cache_enabled and File.exist?(cache_file_name) and File.mtime(cache_file_name) > Time.now() - @settings.cache_expire @settings.log.debug "Using catched #{filename} at #{cache_file_name}" return File.open(cache_file_name, 'r') end FileUtils.mkdir_p File.join(@settings.cache_path, cache_dir_name) if @settings.cache_enabled if @settings.cache_enabled f = File.open(cache_file_name, "w+") else f = Tempfile.new(filename) f.unlink # see tempfile documentation end f.binmode @settings.log.debug "Caching #{filename} for #{data_url} at #{f.path}" f.puts open(data_url).read f.pos = 0 return f end