class RightPublish::ZyppRepo::SuseMetadata

en.opensuse.org/openSUSE:Standards_Rpm_Metadata#SUSE_primary_data_.28susedata.xml.29.2C_extensions_to_primary.xml

Public Class Methods

new() click to toggle source
# File lib/right_publish/repos/zypp.rb, line 35
def initialize
  @packages = Dir["*.rpm"].map { |rpmfile| Package.new(rpmfile) }
end

Public Instance Methods

add() click to toggle source
# File lib/right_publish/repos/zypp.rb, line 77
def add
  create
  update_repomd
end
create() click to toggle source
# File lib/right_publish/repos/zypp.rb, line 56
def create
  susedata_file = File.join("repodata", "susedata.xml.gz")
  Zlib::GzipWriter.open(susedata_file) { |file| file.write(suse_data) }
  @checksum = Digest::SHA256.hexdigest(File.open(susedata_file).read)
  @open_checksum = Digest::SHA256.hexdigest(suse_data)
end
href() click to toggle source
# File lib/right_publish/repos/zypp.rb, line 39
def href 
  "repodata/susedata.xml.gz"
end
suse_data() click to toggle source
# File lib/right_publish/repos/zypp.rb, line 43
def suse_data
  @suse_data ||= Nokogiri::XML::Builder.new do |xml|
    xml.susedata("packages" => @packages.length) do |susedata|
      @packages.each do |package|
        susedata.package('pkgid' => package.checksum, 'name' => package.name) do |pkg|
          pkg.version('ver' => package.ver, 'rel' => package.rel, 'arch' => package.arch, 'epoch' => 0)
          pkg.keyword("support_l3")
        end
      end
    end
  end.to_xml
end
update_repomd() click to toggle source
# File lib/right_publish/repos/zypp.rb, line 63
def update_repomd
  repomd = File.join("repodata", "repomd.xml")
  doc = Nokogiri::XML(File.open(repomd))
  Nokogiri::XML::Builder.with(doc.at_css("repomd")) do |xml|
    xml.data('type' => 'susedata') do |data|
      data.timestamp(File.ctime(href).to_i)
      data.checksum({ 'type' => 'sha256' },  @checksum)
      data.location('href' => href)
      data.send(:"open-checksum", { 'type' => 'sha256' }, @open_checksum)
    end
  end
  File.open(repomd, "w") { |f| doc.write_xml_to f }
end