Class: EnhanceRepo::RpmMd::SuseData
- Defined in:
- lib/enhance_repo/rpm_md/suse_data.rb
Overview
represents SUSE extensions to primary data
See: en.opensuse.org/Standards/Rpm_Metadata#SUSE_primary_data_.28susedata.xml.29
Instance Method Summary collapse
-
#add_attribute(pkgid, prop) ⇒ Object
add an attribute named name for a package identified with pkgid.
- #add_disk_usage ⇒ Object
- #add_eulas ⇒ Object
- #add_keywords ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(dir) ⇒ SuseData
constructor
A new instance of SuseData.
- #size ⇒ Object
-
#write(file) ⇒ Object
write an extension file like other.xml.
Methods inherited from Data
#metadata_filename, #name, #should_compress?
Methods included from Logger
Constructor Details
#initialize(dir) ⇒ SuseData
Returns a new instance of SuseData.
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/enhance_repo/rpm_md/suse_data.rb', line 94 def initialize(dir) @dir = dir @diskusage_enabled = false # the following hash automatically creates a sub # hash for non found values # @properties = Hash.new { |h,v| h[v]= Hash.new } @properties = Hash.new end |
Instance Method Details
#add_attribute(pkgid, prop) ⇒ Object
add an attribute named name for a package identified with pkgid
107 108 109 110 111 112 |
# File 'lib/enhance_repo/rpm_md/suse_data.rb', line 107 def add_attribute(pkgid, prop) if not @properties.has_key?(pkgid) @properties.store(pkgid, Hash.new) end @properties[pkgid][prop.name] = prop end |
#add_disk_usage ⇒ Object
178 179 180 181 182 183 184 185 186 |
# File 'lib/enhance_repo/rpm_md/suse_data.rb', line 178 def add_disk_usage @diskusage_enabled = true log.info "Calculating disk usage..." # build the pkgid hash Dir["#{@dir}/**/*.rpm"].each do |rpmfile| pkgid = PackageId.new(rpmfile) add_attribute(pkgid, DiskUsageProperty.new(pkgid, rpmfile)) end end |
#add_eulas ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/enhance_repo/rpm_md/suse_data.rb', line 114 def add_eulas # add eulas Dir["#{@dir}/**/*.eula"].each do |eulafile| base = File.basename(eulafile, '.eula') # => look for all rpms with that name in that dir Dir["#{File.dirname(eulafile)}/#{base}*.rpm"].each do | rpmfile | pkgid = PackageId.new(rpmfile) if pkgid.matches(base) eulacontent = File.new(eulafile).read add_attribute(pkgid, ValueProperty.new('eula', eulacontent)) log.info "Adding eula: #{eulafile.to_s} to #{pkgid.to_s}" end end end # end of directory iteration end |
#add_keywords ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/enhance_repo/rpm_md/suse_data.rb', line 131 def add_keywords # add keywords log.info "Adding repository keywords" Dir["#{@dir}/**/*.keywords"].each do |keywordfile| base = File.basename(keywordfile, '.keywords') # => look for all rpms with that name in that dir Dir["#{File.dirname(keywordfile)}/#{base}*.rpm"].each do | rpmfile | pkgid = PackageId.new(rpmfile) if pkgid.matches(base) f = File.new(keywordfile) f.each_line do |line| keyword = line.chop add_attribute(pkgid, ValueProperty.new('keyword', keyword)) if not keyword.empty? end log.info "`-> adding keyword: #{keywordfile.to_s} to #{pkgid.to_s}" end end end # end of directory iteration end |
#empty? ⇒ Boolean
152 153 154 |
# File 'lib/enhance_repo/rpm_md/suse_data.rb', line 152 def empty? @properties.empty? end |
#size ⇒ Object
156 157 158 |
# File 'lib/enhance_repo/rpm_md/suse_data.rb', line 156 def size @properties.size end |
#write(file) ⇒ Object
write an extension file like other.xml
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/enhance_repo/rpm_md/suse_data.rb', line 161 def write(file) builder = Builder::XmlMarkup.new(:target=>file, :indent=>2) builder.instruct! xml = builder.tag!(name) do |b| @properties.each do |pkgid, props| #log.info "Dumping package #{pkgid.to_s}" b.package('pkgid' => pkgid.checksum, 'name' => pkgid.name) do |b| b.version('ver' => pkgid.version.v, 'rel' => pkgid.version.r, 'arch' => pkgid.arch, 'epoch' => 0.to_s ) props.each do |propname, prop| #log.info " -> property #{prop.name}" prop.write(builder, pkgid) end end # end package tag end # iterate over properties end #done builder end |