enhancerepo 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +27 -0
  3. data/bin/enhancerepo +2 -3
  4. data/lib/enhance_repo.rb +8 -13
  5. data/lib/enhance_repo/array_arg.rb +85 -0
  6. data/lib/enhance_repo/cli.rb +23 -78
  7. data/lib/enhance_repo/config_opts.rb +207 -13
  8. data/lib/enhance_repo/logger.rb +14 -10
  9. data/lib/enhance_repo/other.rb +11 -12
  10. data/lib/enhance_repo/package_id.rb +21 -12
  11. data/lib/enhance_repo/pattern.rb +50 -0
  12. data/lib/enhance_repo/product_id.rb +3 -1
  13. data/lib/enhance_repo/rpm_md.rb +3 -1
  14. data/lib/enhance_repo/rpm_md/data.rb +6 -7
  15. data/lib/enhance_repo/rpm_md/delta_info.rb +58 -67
  16. data/lib/enhance_repo/rpm_md/extra_primary_data.rb +4 -4
  17. data/lib/enhance_repo/rpm_md/file_lists.rb +12 -13
  18. data/lib/enhance_repo/rpm_md/index.rb +32 -27
  19. data/lib/enhance_repo/rpm_md/other.rb +7 -8
  20. data/lib/enhance_repo/rpm_md/pattern_writer.rb +131 -0
  21. data/lib/enhance_repo/rpm_md/patterns.rb +158 -0
  22. data/lib/enhance_repo/rpm_md/primary.rb +32 -33
  23. data/lib/enhance_repo/rpm_md/products.rb +19 -24
  24. data/lib/enhance_repo/rpm_md/repo.rb +33 -36
  25. data/lib/enhance_repo/rpm_md/resource.rb +6 -6
  26. data/lib/enhance_repo/rpm_md/suse_data.rb +41 -50
  27. data/lib/enhance_repo/rpm_md/suse_info.rb +12 -15
  28. data/lib/enhance_repo/rpm_md/update.rb +65 -36
  29. data/lib/enhance_repo/rpm_md/update_info.rb +38 -42
  30. data/lib/enhance_repo/rpm_md/update_smart_fields.rb +24 -24
  31. data/lib/enhance_repo/susetags/pattern_reader.rb +142 -0
  32. data/lib/enhance_repo/version.rb +5 -0
  33. data/lib/enhance_repo/xml_comparer.rb +28 -24
  34. metadata +190 -221
  35. data/CHANGELOG.rdoc +0 -18
  36. data/Manifest.txt +0 -85
  37. data/README +0 -10
  38. data/README.rdoc +0 -15
  39. data/Rakefile +0 -48
  40. data/TODO.rdoc +0 -4
  41. data/lib/tempdir.rb +0 -62
  42. data/lib/tempdir/tempfile.rb +0 -21
  43. data/test/all_tests.rb +0 -27
  44. data/test/data/packages/a-1.0.spec +0 -19
  45. data/test/data/packages/a-2.0.spec +0 -24
  46. data/test/data/repodata/update-test-11.1/filelists.xml.gz +0 -0
  47. data/test/data/repodata/update-test-11.1/other.xml.gz +0 -0
  48. data/test/data/repodata/update-test-11.1/primary.xml.gz +0 -0
  49. data/test/data/repodata/update-test-11.1/repomd.xml +0 -21
  50. data/test/data/repomd.xml +0 -21
  51. data/test/data/rpms/repo-1/a-1.0-0.x86_64.rpm +0 -0
  52. data/test/data/rpms/repo-1/a-1.0_2.0-0_0.x86_64.delta.rpm +0 -0
  53. data/test/data/rpms/repo-1/a-2.0-0.x86_64.rpm +0 -0
  54. data/test/data/rpms/repo-1/repodata/deltainfo.xml.gz +0 -0
  55. data/test/data/rpms/repo-1/repodata/deltainfo.xml.gz.gz +0 -0
  56. data/test/data/rpms/repo-1/repodata/filelists.xml.gz +0 -0
  57. data/test/data/rpms/repo-1/repodata/other.xml.gz +0 -0
  58. data/test/data/rpms/repo-1/repodata/primary.xml.gz +0 -0
  59. data/test/data/rpms/repo-1/repodata/repomd.xml +0 -45
  60. data/test/data/rpms/repo-1/repodata/susedata.xml.gz +0 -0
  61. data/test/data/rpms/repo-1/repodata/updateinfo.xml.gz +0 -0
  62. data/test/data/rpms/repo-1/repoparts/update-a-1.xml +0 -22
  63. data/test/data/rpms/repo-with-product/a-1.0-0.x86_64.rpm +0 -0
  64. data/test/data/rpms/repo-with-product/openSUSE-release-11.2-1.6.i586.rpm +0 -0
  65. data/test/data/rpms/repo-with-product/openSUSE-release-dvd-11.2-1.6.i586.rpm +0 -0
  66. data/test/data/rpms/repo-with-product/repodata/filelists.xml.gz +0 -0
  67. data/test/data/rpms/repo-with-product/repodata/other.xml.gz +0 -0
  68. data/test/data/rpms/repo-with-product/repodata/primary.xml.gz +0 -0
  69. data/test/data/rpms/repo-with-product/repodata/products.xml.gz +0 -0
  70. data/test/data/rpms/repo-with-product/repodata/repomd.xml +0 -27
  71. data/test/data/rpms/update-test-11.1/update-test-affects-package-manager.rpm +0 -0
  72. data/test/data/rpms/update-test-11.1/update-test-interactive.rpm +0 -0
  73. data/test/data/rpms/update-test-11.1/update-test-optional.rpm +0 -0
  74. data/test/data/rpms/update-test-11.1/update-test-reboot-needed.rpm +0 -0
  75. data/test/data/rpms/update-test-11.1/update-test-security.rpm +0 -0
  76. data/test/data/rpms/update-test-11.1/update-test-trival.rpm +0 -0
  77. data/test/data/rpms/update-test-factory/update-test-affects-package-manager-0-9999.1.2.noarch.rpm +0 -0
  78. data/test/data/rpms/update-test-factory/update-test-interactive-0-9999.1.2.noarch.rpm +0 -0
  79. data/test/data/rpms/update-test-factory/update-test-optional-0-9999.1.2.noarch.rpm +0 -0
  80. data/test/data/rpms/update-test-factory/update-test-reboot-needed-0-9999.1.2.noarch.rpm +0 -0
  81. data/test/data/rpms/update-test-factory/update-test-relogin-suggested-0-9999.1.2.noarch.rpm +0 -0
  82. data/test/data/rpms/update-test-factory/update-test-security-0-9999.1.2.noarch.rpm +0 -0
  83. data/test/deltainfo_test.rb +0 -50
  84. data/test/extensions_test.rb +0 -31
  85. data/test/index_test.rb +0 -51
  86. data/test/primary_test.rb +0 -51
  87. data/test/products_test.rb +0 -51
  88. data/test/repo_test.rb +0 -72
  89. data/test/repomdindex_test.rb +0 -58
  90. data/test/rpmmd_test.rb +0 -60
  91. data/test/susedata_test.rb +0 -53
  92. data/test/tempdir_test.rb +0 -62
  93. data/test/test_helper.rb +0 -53
  94. data/test/update_test.rb +0 -80
  95. data/test/updateinfo_test.rb +0 -59
@@ -1,5 +1,7 @@
1
+ # Encoding: utf-8
2
+
1
3
  #--
2
- #
4
+ #
3
5
  # enhancerepo is a rpm-md repository metadata tool.
4
6
  # Copyright (C) 2008, 2009 Novell Inc.
5
7
  # Author: Duncan Mac-Vicar P. <dmacvicar@suse.de>
@@ -32,92 +34,89 @@ module EnhanceRepo
32
34
  #
33
35
  class Primary < Data
34
36
  attr_accessor :indent
35
-
37
+
36
38
  def initialize(dir)
37
39
  @indent = false
38
40
  @dir = dir
39
41
  @rpmfiles = []
40
42
  end
41
-
43
+
42
44
  def read_packages
43
45
  Dir["#{@dir}/**/*.rpm"].each do |rpmfile|
44
46
  @rpmfiles << rpmfile
45
- end
47
+ end
46
48
  end
47
49
 
48
50
  def size
49
51
  @rpmfiles.size
50
52
  end
51
-
53
+
52
54
  def empty?
53
55
  @rpmfiles.empty?
54
56
  end
55
57
 
56
58
  def write_package(file, rpmfile)
57
- b = Builder::XmlMarkup.new(:target=>file, :indent=> @indent ? 2 : 0, :indent=> @indent ? 2 : 0)
58
- b.package('type' => 'rpm') do | b |
59
+ b = Builder::XmlMarkup.new(target: file, indent: @indent ? 2 : 0)
60
+ b.package('type' => 'rpm') do
59
61
  pkgid = PackageId.new(rpmfile)
60
62
  b.name pkgid.name
61
63
  b.arch pkgid.arch
62
- b.version('epoch' => pkgid.version.e.nil? ? "0" : pkgid.version.e.to_s, 'ver' => pkgid.version.v, 'rel' => pkgid.version.r)
63
- b.checksum(pkgid.checksum, 'type'=>'sha', 'pkgid'=>'YES')
64
+ b.version('epoch' => pkgid.version.e.nil? ? '0' : pkgid.version.e.to_s, 'ver' => pkgid.version.v, 'rel' => pkgid.version.r)
65
+ b.checksum(pkgid.checksum, 'type' => EnhanceRepo::ConfigOpts.instance.digest_name, 'pkgid' => 'YES')
64
66
  b.summary pkgid[RPM::TAG_SUMMARY]
65
67
  b.description pkgid[RPM::TAG_DESCRIPTION]
66
68
  b.packager pkgid[RPM::TAG_PACKAGER]
67
69
  b.url pkgid[RPM::TAG_URL]
68
- b.time('file'=>File.mtime(rpmfile).to_i, 'build'=>pkgid[RPM::TAG_BUILDTIME])
69
- b.tag!('size', 'archive'=>pkgid[RPM::TAG_ARCHIVESIZE], 'installed'=>pkgid[RPM::TAG_SIZE], 'package'=>File.size(rpmfile))
70
- b.location('href'=>File.basename(rpmfile))
70
+ b.time('file' => File.mtime(rpmfile).to_i, 'build' => pkgid[RPM::TAG_BUILDTIME])
71
+ b.tag!('size', 'archive' => pkgid[RPM::TAG_ARCHIVESIZE], 'installed' => pkgid[RPM::TAG_SIZE], 'package' => File.size(rpmfile))
72
+ b.location('href' => File.basename(rpmfile))
71
73
  # now the format tags
72
- b.format do |b|
74
+ b.format do
73
75
  b.tag!('rpm:license', pkgid[RPM::TAG_LICENSE])
74
76
  b.tag!('rpm:vendor', pkgid[RPM::TAG_VENDOR])
75
77
  b.tag!('rpm:group', pkgid[RPM::TAG_GROUP])
76
78
  b.tag!('rpm:buildhost', pkgid[RPM::TAG_BUILDHOST])
77
79
  b.tag!('rpm:sourcerpm', pkgid[RPM::TAG_SOURCERPM])
78
- #b.tag!('rpm:header-range', pkgid[RPM::TAG_SOURCERPM])
79
-
80
+ # b.tag!('rpm:header-range', pkgid[RPM::TAG_SOURCERPM])
81
+
80
82
  # serialize dependencies
81
- [:provides, :requires, :obsoletes, :conflicts, :obsoletes].each do |deptype|
82
- b.tag!("rpm:#{deptype}") do |b|
83
- pkgid.send(deptype).reverse.each { |dep|
83
+ %i[provides requires obsoletes conflicts obsoletes].each do |deptype|
84
+ b.tag!("rpm:#{deptype}") do
85
+ pkgid.send(deptype).reverse.each do |dep|
84
86
  flag = nil
85
87
  flag = 'LT' if dep.lt?
86
88
  flag = 'GT' if dep.gt?
87
89
  flag = 'EQ' if dep.eq?
88
90
  flag = 'LE' if dep.le?
89
91
  flag = 'GE' if dep.ge?
90
- attrs = {'name'=>dep.name}
91
- if not flag.nil?
92
- attrs['pre'] = 1 if (deptype == :requires) and dep.pre?
92
+ attrs = { 'name' => dep.name }
93
+ unless flag.nil?
94
+ attrs['pre'] = 1 if (deptype == :requires) && dep.pre?
93
95
  attrs['flags'] = flag
94
- attrs['ver'] =dep.version.v
95
- attrs['epoch'] = dep.version.e.nil? ? "0" : dep.version.e.to_s
96
- attrs['rel'] =dep.version.r
96
+ attrs['ver'] = dep.version.v
97
+ attrs['epoch'] = dep.version.e.nil? ? '0' : dep.version.e.to_s
98
+ attrs['rel'] = dep.version.r
97
99
  end
98
100
  b.tag!('rpm:entry', attrs)
99
- }
101
+ end
100
102
  end
101
- #####
102
103
  end
103
- end
104
+ end #####
104
105
  # done with format section
105
106
  end
106
107
  # done package tag
107
108
  end
108
-
109
+
109
110
  # write primary.xml
110
111
  def write(file)
111
- builder = Builder::XmlMarkup.new(:target=>file, :indent=> @indent ? 2 : 0)
112
+ builder = Builder::XmlMarkup.new(target: file, indent: @indent ? 2 : 0)
112
113
  builder.instruct!
113
- builder.tag!("metadata", 'xmlns' => 'http://linux.duke.edu/metadata/common', 'xmlns:rpm' => 'http://linux.duke.edu/metadata/rpm', 'xmlns:suse'=>'http://novell.com/package/metadata/suse/common', 'packages'=> @rpmfiles.size ) do |b|
114
+ builder.tag!('metadata', 'xmlns' => 'http://linux.duke.edu/metadata/common', 'xmlns:rpm' => 'http://linux.duke.edu/metadata/rpm', 'xmlns:suse' => 'http://novell.com/package/metadata/suse/common', 'packages' => @rpmfiles.size) do |_b|
114
115
  @rpmfiles.each do |rpmfile|
115
116
  write_package(file, rpmfile)
116
117
  end
117
- end# next package
118
+ end # next package
118
119
  end
119
-
120
120
  end
121
-
122
121
  end
123
122
  end
@@ -1,5 +1,7 @@
1
+ # Encoding: utf-8
2
+
1
3
  #--
2
- #
4
+ #
3
5
  # enhancerepo is a rpm-md repository metadata tool.
4
6
  # Copyright (C) 2008, 2009 Novell Inc.
5
7
  # Author: Duncan Mac-Vicar P. <dmacvicar@suse.de>
@@ -23,18 +25,15 @@
23
25
  #++
24
26
  #
25
27
  require 'rpm'
26
- require 'tempdir'
27
28
  require 'pathname'
28
29
  require 'nokogiri'
29
- require 'ftools'
30
+ # require 'ftools'
30
31
 
31
32
  module EnhanceRepo
32
33
  module RpmMd
33
-
34
34
  # products.xml metadata generator
35
35
  # reads the release files from a repository
36
36
  class Products < Data
37
-
38
37
  # Holder for products we read from the
39
38
  # release files
40
39
  class ProductData
@@ -47,17 +46,16 @@ module EnhanceRepo
47
46
  attr_accessor :summary
48
47
  attr_accessor :description
49
48
  end
50
-
49
+
51
50
  def initialize(dir)
52
51
  @dir = dir
53
52
  @products = []
54
53
  end
55
54
 
56
55
  def rpm_extract_file(rpmpath, path)
57
- Tempdir.open do |tmppath|
58
- File.makedirs(tmppath)
56
+ Dir.mktmpdir do |tmppath|
59
57
  Dir.chdir(tmppath) do
60
- `rpm2cpio '#{rpmpath}' | cpio -iv --make-directories #{File.join(".", path)} 2>/dev/null`
58
+ `rpm2cpio '#{rpmpath}' | cpio -iv --make-directories #{File.join('.', path)} 2>/dev/null`
61
59
  end
62
60
  File.open(File.join(tmppath, path)) do |f|
63
61
  yield f if block_given?
@@ -70,10 +68,10 @@ module EnhanceRepo
70
68
  products = []
71
69
  rpm_extract_file(rpmpath, path) do |f|
72
70
  doc = Nokogiri::XML(f)
73
- #print doc.to_s
71
+ # print doc.to_s
74
72
  product = ProductData.new
75
73
  # set attributes of the product based on the xml data
76
- [:name, :version, :release, :arch, :vendor, :summary, :description].each do |attr|
74
+ %i[name version release arch vendor summary description].each do |attr|
77
75
  product.send("#{attr}=".to_sym, doc.root.xpath("./#{attr}").text)
78
76
  end
79
77
  products << product
@@ -84,16 +82,16 @@ module EnhanceRepo
84
82
 
85
83
  # scan the products from the rpm files in the repository
86
84
  def read_packages
87
- # log.info "Looking for product release packages"
85
+ # log.info "Looking for product release packages"
88
86
  Dir["#{@dir}/**/*-release-*.rpm", "#{@dir}/**/*-migration-*.rpm"].each do |rpmfile|
89
87
  pkg = RPM::Package.new(rpmfile)
90
88
  # we dont care for packages not providing a product
91
- next if pkg.provides.select{|x| x.name == "product()"}.empty?
89
+ next if pkg.provides.select { |x| x.name == 'product()' }.empty?
92
90
  log.info "Found product release package #{rpmfile}"
93
91
  # this package contains a product
94
92
  # go over each product file
95
- pkg.files.map {|x| x.to_s }.each do |path|
96
- next if not ( File.extname(path) == ".prod" && File.dirname(path) == "/etc/products.d" )
93
+ pkg.files.map(&:path).each do |path|
94
+ next unless File.extname(path) == '.prod' && File.dirname(path) == '/etc/products.d'
97
95
  # we have a product file. Extract it
98
96
  log.info "`-> product file : #{path}"
99
97
  products_in_file_in_rpm(File.expand_path(rpmfile), File.expand_path(path)) do |product|
@@ -111,7 +109,7 @@ module EnhanceRepo
111
109
  def size
112
110
  @products.size
113
111
  end
114
-
112
+
115
113
  def write(io)
116
114
  builder = Nokogiri::XML::Builder.new do |xml|
117
115
  xml.products do
@@ -120,23 +118,20 @@ module EnhanceRepo
120
118
  xml.name product.name
121
119
  version = RPM::Version.new("#{product.version}-#{product.release}")
122
120
  epoch = version.e
123
- epoch ||= "0"
124
- xml.version :epoch => epoch, :ver => version.v, :rel => version.r
121
+ epoch ||= '0'
122
+ xml.version epoch: epoch, ver: version.v, rel: version.r
125
123
  xml.arch product.arch
126
124
  xml.vendor product.vendor
127
125
  xml.summary product.summary
128
- xml.description product.description
126
+ xml.description product.description
129
127
  end
130
128
  end
131
129
  end
132
130
  end
133
131
  # write the result
134
- #io.write(builder.to_xml)
135
- io.write(builder.doc.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XML))
132
+ # io.write(builder.to_xml)
133
+ io.write(builder.doc.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::AS_XML))
136
134
  end
137
-
138
-
139
135
  end
140
-
141
136
  end
142
137
  end
@@ -1,5 +1,7 @@
1
+ # Encoding: utf-8
2
+
1
3
  #--
2
- #
4
+ #
3
5
  # enhancerepo is a rpm-md repository metadata tool.
4
6
  # Copyright (C) 2008, 2009 Novell Inc.
5
7
  # Author: Duncan Mac-Vicar P. <dmacvicar@suse.de>
@@ -25,7 +27,6 @@
25
27
  require 'rubygems'
26
28
  require 'builder'
27
29
  require 'rexml/document'
28
- require 'digest/sha1'
29
30
  require 'zlib'
30
31
  require 'yaml'
31
32
 
@@ -35,6 +36,7 @@ require 'enhance_repo/rpm_md/primary'
35
36
  require 'enhance_repo/rpm_md/file_lists'
36
37
  require 'enhance_repo/rpm_md/other'
37
38
  require 'enhance_repo/rpm_md/update_info'
39
+ require 'enhance_repo/rpm_md/patterns'
38
40
  require 'enhance_repo/rpm_md/suse_info'
39
41
  require 'enhance_repo/rpm_md/suse_data'
40
42
  require 'enhance_repo/rpm_md/delta_info'
@@ -43,17 +45,15 @@ require 'enhance_repo/rpm_md/index'
43
45
 
44
46
  module EnhanceRepo
45
47
  module RpmMd
46
-
47
48
  include REXML
48
-
49
- class Repo
50
49
 
50
+ class Repo
51
51
  include Logger
52
-
52
+
53
53
  attr_accessor :index
54
54
 
55
55
  # extensions
56
- attr_reader :primary, :other, :filelists, :susedata, :suseinfo, :deltainfo, :updateinfo, :products
56
+ attr_reader :primary, :other, :filelists, :susedata, :suseinfo, :deltainfo, :updateinfo, :products, :patterns
57
57
  def initialize(config)
58
58
  @dir = config.dir
59
59
  @outputdir = config.outputdir
@@ -61,13 +61,11 @@ module EnhanceRepo
61
61
  @index = Index.new
62
62
  repomdfile = File.join(@dir, @index.metadata_filename)
63
63
  # populate the index
64
- if File.exist?(repomdfile)
65
- @index.read_file(File.new(repomdfile))
66
- end
67
-
64
+ @index.read_file(File.new(repomdfile)) if File.exist?(repomdfile)
65
+
68
66
  @primary = Primary.new(config.dir)
69
67
  @primary.indent = config.indent
70
-
68
+
71
69
  @filelists = FileLists.new(config.dir)
72
70
  @other = Other.new(config.dir)
73
71
  @susedata = SuseData.new(config.dir)
@@ -75,17 +73,16 @@ module EnhanceRepo
75
73
  @suseinfo = SuseInfo.new(config.dir)
76
74
  @deltainfo = DeltaInfo.new(config.dir)
77
75
  @products = Products.new(config.dir)
76
+ @patterns = Patterns.new(config)
78
77
  end
79
78
 
80
79
  def sign(keyid)
81
80
  # check if the index is written to disk
82
81
  repomdfile = File.join(@dir, @index.metadata_filename)
83
- if not File.exist?(repomdfile)
84
- raise "#{repomdfile} does not exist."
85
- end
82
+ raise "#{repomdfile} does not exist." unless File.exist?(repomdfile)
86
83
  # call gpg to sign the repository
87
84
  `gpg -sab -u #{keyid} -o '#{repomdfile}.asc' '#{repomdfile}'`
88
- if not File.exists?("#{repomdfile}.asc")
85
+ if !File.exist?("#{repomdfile}.asc")
89
86
  log.info "Could't not generate signature #{repomdfile}.asc"
90
87
  exit(1)
91
88
  else
@@ -95,7 +92,7 @@ module EnhanceRepo
95
92
  # now export the public key
96
93
  `gpg --export -a -o '#{repomdfile}.key' #{keyid}`
97
94
 
98
- if not File.exists?("#{repomdfile}.key")
95
+ if !File.exist?("#{repomdfile}.key")
99
96
  log.info "Could't not generate public key #{repomdfile}.key"
100
97
  exit(1)
101
98
  else
@@ -104,39 +101,38 @@ module EnhanceRepo
104
101
  end
105
102
 
106
103
  def write
107
-
108
104
  datas = [@primary, @filelists, @other, @updateinfo,
109
- @susedata, @suseinfo, @deltainfo, @products ]
105
+ @susedata, @suseinfo, @deltainfo, @products, @patterns]
110
106
 
111
107
  # select the datas that are not empty
112
108
  # those need to be saved
113
- non_empty_data = datas.reject { |x| x.empty? }
109
+ non_empty_data = datas.reject(&:empty?)
114
110
  # files present in the index, which were changed
115
111
  changed_files = []
116
112
  # files present on disk, but not in the index
117
113
  missing_files = []
118
114
  # files present in the index, but not on disk
119
115
  superflous_files = []
120
-
116
+
121
117
  # now look for files that changed or dissapeared
122
118
  Dir.chdir(@dir) do
123
119
  # look all files except the index itself
124
- metadata_files = Dir["repodata/*.xml*"].reject do |x|
125
- x =~ /#{@index.metadata_filename}/ ||
126
- x =~ /\.key$/ ||
127
- x =~ /\.asc$/
120
+ metadata_files = Dir['repodata/*.xml*'].reject do |x|
121
+ x =~ /#{@index.metadata_filename}/ ||
122
+ x =~ /\.key$/ ||
123
+ x =~ /\.asc$/
128
124
  end
129
125
  # remove datas in the index not present in the disk
130
126
  @index.resources.reject! do |resource|
131
- reject = ! metadata_files.include?(resource.location)
127
+ reject = !metadata_files.include?(resource.location)
132
128
  log.info "Removing not existing #{resource.location} from index" if reject
133
129
  reject
134
130
  end
135
-
136
- non_empty_files = non_empty_data.map { |x| x.metadata_filename }
131
+
132
+ non_empty_files = non_empty_data.map(&:metadata_filename)
137
133
  # ignore it if it is already in the non_empty_list
138
134
  # as it will be added to the index anyway
139
- metadata_files.reject!{ |x| non_empty_files.include?(x) }
135
+ metadata_files.reject! { |x| non_empty_files.include?(x) }
140
136
  metadata_files.each do |metadata_file|
141
137
  # find the indexed resource for this file
142
138
  indexed_resource = @index.resources.select { |x| x.location == metadata_file }.first
@@ -151,7 +147,7 @@ module EnhanceRepo
151
147
  end
152
148
  end
153
149
  end
154
-
150
+
155
151
  # write down changed datas
156
152
  non_empty_data.each do |data|
157
153
  write_gz_extension_file(data)
@@ -167,14 +163,17 @@ module EnhanceRepo
167
163
  log.info "Adding missing #{f} to #{@index.metadata_filename} index"
168
164
  @index.add_file_resource(File.join(@outputdir, f), f)
169
165
  end
170
-
166
+
171
167
  changed_files.each do |f|
172
168
  log.info "Replacing changed #{f} on #{@index.metadata_filename} index"
173
169
  @index.add_file_resource(File.join(@outputdir, f), f)
174
170
  end
175
-
171
+
176
172
  # now write the index
177
- File.open((@outputdir + @index.metadata_filename), 'w') do |f|
173
+ unless File.exist?(File.dirname(File.join(@outputdir, @index.metadata_filename)))
174
+ FileUtils.mkdir_p(File.dirname(File.join(@outputdir, @index.metadata_filename)))
175
+ end
176
+ File.open(File.join(@outputdir, @index.metadata_filename), 'w') do |f|
178
177
  log.info "Saving #{@index.metadata_filename} .."
179
178
  @index.write(f)
180
179
  end
@@ -186,7 +185,7 @@ module EnhanceRepo
186
185
  filename = Pathname.new(File.join(@outputdir, data.metadata_filename))
187
186
  FileUtils.mkdir_p filename.dirname
188
187
  log.info "Saving #{filename} .."
189
- if not filename.dirname.exist?
188
+ unless filename.dirname.exist?
190
189
  log.info "Creating non existing #{filename.dirname} .."
191
190
  filename.dirname.mkpath
192
191
  end
@@ -195,8 +194,6 @@ module EnhanceRepo
195
194
  data.write(gz)
196
195
  end
197
196
  end
198
-
199
197
  end
200
-
201
198
  end
202
199
  end
@@ -1,5 +1,7 @@
1
+ # Encoding: utf-8
2
+
1
3
  #--
2
- #
4
+ #
3
5
  # enhancerepo is a rpm-md repository metadata tool.
4
6
  # Copyright (C) 2008, 2009 Novell Inc.
5
7
  # Author: Duncan Mac-Vicar P. <dmacvicar@suse.de>
@@ -25,20 +27,18 @@
25
27
 
26
28
  module EnhanceRepo
27
29
  module RpmMd
28
-
29
30
  # represents a resource in repomd.xml
30
31
  class Resource
31
32
  attr_accessor :type
32
- attr_accessor :location, :checksum, :timestamp, :openchecksum
33
+ attr_accessor :location, :checksum, :timestamp, :openchecksum, :size, :opensize, :database_version
33
34
 
34
35
  # define equality based on the location
35
36
  # as it has no sense to have two resources for the
36
- #same location
37
+ # same location
37
38
  def ==(other)
38
39
  return (location == other.location) if other.is_a?(Resource)
39
40
  false
40
- end
41
+ end
41
42
  end
42
-
43
43
  end
44
44
  end