Class: EnhanceRepo::RpmMd::Products
- Defined in:
- lib/enhance_repo/rpm_md/products.rb
Overview
products.xml metadata generator reads the release files from a repository
Defined Under Namespace
Classes: ProductData
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(dir) ⇒ Products
constructor
A new instance of Products.
- #products_in_file_in_rpm(rpmpath, path) ⇒ Object
-
#read_packages ⇒ Object
scan the products from the rpm files in the repository.
- #rpm_extract_file(rpmpath, path) ⇒ Object
- #size ⇒ Object
- #write(io) ⇒ Object
Methods inherited from Data
#metadata_filename, #name, #should_compress?
Methods included from Logger
Constructor Details
#initialize(dir) ⇒ Products
Returns a new instance of Products.
50 51 52 53 |
# File 'lib/enhance_repo/rpm_md/products.rb', line 50 def initialize(dir) @dir = dir @products = [] end |
Instance Method Details
#empty? ⇒ Boolean
105 106 107 |
# File 'lib/enhance_repo/rpm_md/products.rb', line 105 def empty? @products.empty? end |
#products_in_file_in_rpm(rpmpath, path) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/enhance_repo/rpm_md/products.rb', line 67 def products_in_file_in_rpm(rpmpath, path) products = [] rpm_extract_file(rpmpath, path) do |f| doc = Nokogiri::XML(f) # print doc.to_s product = ProductData.new # set attributes of the product based on the xml data %i[name version release arch vendor summary description].each do |attr| product.send("#{attr}=".to_sym, doc.root.xpath("./#{attr}").text) end products << product yield product if block_given? end products end |
#read_packages ⇒ Object
scan the products from the rpm files in the repository
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/enhance_repo/rpm_md/products.rb', line 84 def read_packages # log.info "Looking for product release packages" Dir["#{@dir}/**/*-release-*.rpm", "#{@dir}/**/*-migration-*.rpm"].each do |rpmfile| pkg = RPM::Package.new(rpmfile) # we dont care for packages not providing a product next if pkg.provides.select { |x| x.name == 'product()' }.empty? log.info "Found product release package #{rpmfile}" # this package contains a product # go over each product file pkg.files.map(&:path).each do |path| next unless File.extname(path) == '.prod' && File.dirname(path) == '/etc/products.d' # we have a product file. Extract it log.info "`-> product file : #{path}" products_in_file_in_rpm(File.(rpmfile), File.(path)) do |product| log.info "`-> found product : #{product.name}" @products << product end end end end |
#rpm_extract_file(rpmpath, path) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/enhance_repo/rpm_md/products.rb', line 55 def rpm_extract_file(rpmpath, path) Dir.mktmpdir do |tmppath| Dir.chdir(tmppath) do `rpm2cpio '#{rpmpath}' | cpio -iv --make-directories #{File.join('.', path)} 2>/dev/null` end File.open(File.join(tmppath, path)) do |f| yield f if block_given? return f.read end end end |
#size ⇒ Object
109 110 111 |
# File 'lib/enhance_repo/rpm_md/products.rb', line 109 def size @products.size end |
#write(io) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/enhance_repo/rpm_md/products.rb', line 113 def write(io) builder = Nokogiri::XML::Builder.new do |xml| xml.products do @products.each do |product| xml.product do xml.name product.name version = RPM::Version.new("#{product.version}-#{product.release}") epoch = version.e epoch ||= '0' xml.version epoch: epoch, ver: version.v, rel: version.r xml.arch product.arch xml.vendor product.vendor xml.summary product.summary xml.description product.description end end end end # write the result # io.write(builder.to_xml) io.write(builder.doc.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::AS_XML)) end |