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>
@@ -25,7 +27,6 @@
25
27
 
26
28
  module EnhanceRepo
27
29
  module RpmMd
28
-
29
30
  class Property
30
31
  attr_accessor :name
31
32
  def initialize(name)
@@ -47,40 +48,38 @@ module EnhanceRepo
47
48
  @value = value
48
49
  end
49
50
 
50
- def write(builder, pkgid)
51
+ def write(builder, _pkgid)
51
52
  builder.tag!(@name, @value)
52
53
  end
53
54
  end
54
55
 
55
56
  class DiskUsageProperty < Property
56
-
57
57
  def initialize(pkgid, rpmfile)
58
58
  super('diskusage')
59
59
  @pkgid = pkgid
60
60
  @rpmfile = rpmfile
61
61
  end
62
-
63
- def write(builder, pkgid)
64
- dirsizes = Hash.new
65
- dircount = Hash.new
62
+
63
+ def write(builder, _pkgid)
64
+ dirsizes = {}
65
+ dircount = {}
66
66
  `rpm -q --queryformat \"[%{FILENAMES} %{FILESIZES}\n]\" -p '#{@rpmfile}'`.each_line do |line|
67
67
  file, size = line.split
68
- dirsizes[File.dirname(file)] = 0 if not dirsizes.has_key?(File.dirname(file))
69
- dircount[File.dirname(file)] = 0 if not dircount.has_key?(File.dirname(file))
70
-
68
+ dirsizes[File.dirname(file)] = 0 unless dirsizes.key?(File.dirname(file))
69
+ dircount[File.dirname(file)] = 0 unless dircount.key?(File.dirname(file))
70
+
71
71
  dirsizes[File.dirname(file)] += size.to_i
72
72
  dircount[File.dirname(file)] += 1
73
73
  end
74
74
 
75
75
  builder.diskusage do |b|
76
- b.dirs do |b|
76
+ b.dirs do
77
77
  dirsizes.each do |k, v|
78
- b.dir('name' => k, 'size' => v, 'count' => dircount[k] )
78
+ b.dir('name' => k, 'size' => v, 'count' => dircount[k])
79
79
  end
80
80
  end
81
- end
81
+ end
82
82
  end
83
-
84
83
  end
85
84
 
86
85
  # represents SUSE extensions to
@@ -90,7 +89,6 @@ module EnhanceRepo
90
89
  # http://en.opensuse.org/Standards/Rpm_Metadata#SUSE_primary_data_.28susedata.xml.29
91
90
  #
92
91
  class SuseData < Data
93
-
94
92
  def initialize(dir)
95
93
  @dir = dir
96
94
  @diskusage_enabled = false
@@ -98,31 +96,27 @@ module EnhanceRepo
98
96
  # the following hash automatically creates a sub
99
97
  # hash for non found values
100
98
  # @properties = Hash.new { |h,v| h[v]= Hash.new }
101
- @properties = Hash.new
102
-
99
+ @properties = {}
103
100
  end
104
101
 
105
102
  # add an attribute named name for a
106
103
  # package identified with pkgid
107
104
  def add_attribute(pkgid, prop)
108
- if not @properties.has_key?(pkgid)
109
- @properties.store(pkgid, Hash.new)
110
- end
105
+ @properties.store(pkgid, {}) unless @properties.key?(pkgid)
111
106
  @properties[pkgid][prop.name] = prop
112
107
  end
113
-
108
+
114
109
  def add_eulas
115
110
  # add eulas
116
111
  Dir["#{@dir}/**/*.eula"].each do |eulafile|
117
112
  base = File.basename(eulafile, '.eula')
118
113
  # => look for all rpms with that name in that dir
119
- Dir["#{File.dirname(eulafile)}/#{base}*.rpm"].each do | rpmfile |
114
+ Dir["#{File.dirname(eulafile)}/#{base}*.rpm"].each do |rpmfile|
120
115
  pkgid = PackageId.new(rpmfile)
121
- if pkgid.matches(base)
122
- eulacontent = File.new(eulafile).read
123
- add_attribute(pkgid, ValueProperty.new('eula', eulacontent))
124
- log.info "Adding eula: #{eulafile.to_s} to #{pkgid.to_s}"
125
- end
116
+ next unless pkgid.matches(base)
117
+ eulacontent = File.new(eulafile).read
118
+ add_attribute(pkgid, ValueProperty.new('eula', eulacontent))
119
+ log.info "Adding eula: #{eulafile} to #{pkgid}"
126
120
  end
127
121
  end
128
122
  # end of directory iteration
@@ -130,20 +124,19 @@ module EnhanceRepo
130
124
 
131
125
  def add_keywords
132
126
  # add keywords
133
- log.info "Adding repository keywords"
127
+ log.info 'Adding repository keywords'
134
128
  Dir["#{@dir}/**/*.keywords"].each do |keywordfile|
135
129
  base = File.basename(keywordfile, '.keywords')
136
130
  # => look for all rpms with that name in that dir
137
- Dir["#{File.dirname(keywordfile)}/#{base}*.rpm"].each do | rpmfile |
131
+ Dir["#{File.dirname(keywordfile)}/#{base}*.rpm"].each do |rpmfile|
138
132
  pkgid = PackageId.new(rpmfile)
139
- if pkgid.matches(base)
140
- f = File.new(keywordfile)
141
- f.each_line do |line|
142
- keyword = line.chop
143
- add_attribute(pkgid, ValueProperty.new('keyword', keyword)) if not keyword.empty?
144
- end
145
- log.info "`-> adding keyword: #{keywordfile.to_s} to #{pkgid.to_s}"
133
+ next unless pkgid.matches(base)
134
+ f = File.new(keywordfile)
135
+ f.each_line do |line|
136
+ keyword = line.chop
137
+ add_attribute(pkgid, ValueProperty.new('keyword', keyword)) unless keyword.empty?
146
138
  end
139
+ log.info "`-> adding keyword: #{keywordfile} to #{pkgid}"
147
140
  end
148
141
  end
149
142
  # end of directory iteration
@@ -159,33 +152,31 @@ module EnhanceRepo
159
152
 
160
153
  # write an extension file like other.xml
161
154
  def write(file)
162
- builder = Builder::XmlMarkup.new(:target=>file, :indent=>2)
155
+ builder = Builder::XmlMarkup.new(target: file, indent: 2)
163
156
  builder.instruct!
164
- xml = builder.tag!(name) do |b|
157
+ builder.tag!(name) do |b|
165
158
  @properties.each do |pkgid, props|
166
- #log.info "Dumping package #{pkgid.to_s}"
167
- b.package('pkgid' => pkgid.checksum, 'name' => pkgid.name) do |b|
168
- b.version('ver' => pkgid.version.v, 'rel' => pkgid.version.r, 'arch' => pkgid.arch, 'epoch' => 0.to_s )
169
- props.each do |propname, prop|
170
- #log.info " -> property #{prop.name}"
159
+ # log.info "Dumping package #{pkgid.to_s}"
160
+ b.package('pkgid' => pkgid.checksum, 'name' => pkgid.name) do
161
+ b.version('ver' => pkgid.version.v, 'rel' => pkgid.version.r, 'arch' => pkgid.arch, 'epoch' => 0.to_s)
162
+ props.each do |_propname, prop|
163
+ # log.info " -> property #{prop.name}"
171
164
  prop.write(builder, pkgid)
172
165
  end
173
- end # end package tag
166
+ end
174
167
  end # iterate over properties
175
- end #done builder
168
+ end
176
169
  end
177
-
170
+
178
171
  def add_disk_usage
179
172
  @diskusage_enabled = true
180
- log.info "Calculating disk usage..."
173
+ log.info 'Calculating disk usage...'
181
174
  # build the pkgid hash
182
175
  Dir["#{@dir}/**/*.rpm"].each do |rpmfile|
183
176
  pkgid = PackageId.new(rpmfile)
184
177
  add_attribute(pkgid, DiskUsageProperty.new(pkgid, rpmfile))
185
178
  end
186
179
  end
187
-
188
180
  end
189
-
190
181
  end
191
182
  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>
@@ -28,7 +30,6 @@ require 'builder'
28
30
 
29
31
  module EnhanceRepo
30
32
  module RpmMd
31
-
32
33
  # represents SUSE extensions to repository
33
34
  # metadata (not associated with packages)
34
35
  #
@@ -36,7 +37,6 @@ module EnhanceRepo
36
37
  # http://en.opensuse.org/Standards/Rpm_Metadata#SUSE_repository_info_.28suseinfo.xml.29
37
38
  #
38
39
  class SuseInfo < Data
39
-
40
40
  # expiration time
41
41
  # the generated value is
42
42
  # still calculated from repomd.xml
@@ -53,36 +53,33 @@ module EnhanceRepo
53
53
  end
54
54
 
55
55
  def empty?
56
- @expire.nil? and @products.empty? and @keywords.empty?
56
+ @expire.nil? && @products.empty? && @keywords.empty?
57
57
  end
58
-
58
+
59
59
  def write(file)
60
- builder = Builder::XmlMarkup.new(:target=>file, :indent=>2)
60
+ builder = Builder::XmlMarkup.new(target: file, indent: 2)
61
61
  builder.instruct!
62
- xml = builder.suseinfo do |b|
63
-
62
+ builder.suseinfo do
64
63
  # add expire tag
65
- b.expire(@expire.to_i.to_s) if not @expire.nil?
64
+ b.expire(@expire.to_i.to_s) unless @expire.nil?
66
65
 
67
- if not @keywords.empty?
68
- b.keywords do |b|
66
+ unless @keywords.empty?
67
+ b.keywords do
69
68
  @keywords.each do |k|
70
69
  b.k(k)
71
70
  end
72
71
  end
73
72
  end
74
73
 
75
- if not @products.empty?
76
- b.products do |b|
74
+ unless @products.empty?
75
+ b.products do
77
76
  @products.each do |p|
78
77
  b.id(p)
79
78
  end
80
79
  end
81
80
  end
82
-
83
81
  end
84
82
  end
85
83
  end
86
-
87
84
  end
88
85
  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
  # Copyright (C) 2009, Jordi Massager Pla <jordi.massagerpla@opensuse.org>
@@ -27,7 +29,7 @@
27
29
  #
28
30
 
29
31
  require 'rubygems'
30
- require 'active_support/core_ext/module/attr_accessor_with_default'
32
+ require 'active_support/core_ext/module/attr_internal'
31
33
  require 'builder'
32
34
  require 'rexml/document'
33
35
  require 'yaml'
@@ -38,7 +40,6 @@ require 'enhance_repo/rpm_md/update_smart_fields'
38
40
 
39
41
  module EnhanceRepo
40
42
  module RpmMd
41
-
42
43
  #
43
44
  # Represents a reference to a external bugreport
44
45
  # feature or issue for a software update
@@ -55,41 +56,72 @@ module EnhanceRepo
55
56
  attr_accessor :title
56
57
 
57
58
  def to_s
58
- "#{type}##{referenceid}"
59
+ "#{type}##{referenceid}"
59
60
  end
60
-
61
+
61
62
  # initialize a reference, per default a novell
62
63
  # bugzilla type
63
64
  def initialize
64
- @href = "http://bugzilla.novell.com"
65
- @referenceid = "none"
66
- @title = ""
67
- @type = "bugzilla"
65
+ @href = 'http://bugzilla.novell.com'
66
+ @referenceid = 'none'
67
+ @title = ''
68
+ @type = 'bugzilla'
68
69
  end
69
70
  end
70
71
 
71
72
  # represents one update, which can consist of various packages
72
73
  # and references
73
74
  class Update
74
-
75
75
  # methods to automatically grab data from the
76
76
  # update description
77
77
  include UpdateSmartFields
78
-
79
- attr_accessor_with_default :updateid, "unknown"
80
- attr_accessor_with_default :status, "stable"
81
- attr_accessor_with_default :from, "#{ENV['USER']}@#{ENV['HOST']}"
82
- attr_accessor_with_default :type, "optional"
83
- attr_accessor_with_default :version, 1
84
- attr_accessor_with_default :release, "unknown"
85
- attr_accessor_with_default :issued, Time.now.to_i
86
- attr_accessor_with_default :references, []
87
- attr_accessor_with_default :description, ""
88
- attr_accessor_with_default :title, "untitled update"
89
- attr_accessor_with_default :packages, []
90
-
91
- def initialize
78
+
79
+ attr_writer :updateid
80
+ def updateid
81
+ @updateid ||= 'unknown'
82
+ end
83
+ attr_writer :status
84
+ def status
85
+ @status ||= 'stable'
86
+ end
87
+ attr_writer :from
88
+ def from
89
+ @from ||= "#{ENV['USER']}@#{ENV['HOST']}"
90
+ end
91
+ attr_writer :type
92
+ def type
93
+ @type ||= 'optional'
92
94
  end
95
+ attr_writer :version
96
+ def version
97
+ @version ||= 1
98
+ end
99
+ attr_writer :release
100
+ def release
101
+ @release ||= 'unknown'
102
+ end
103
+ attr_writer :issued
104
+ def issued
105
+ @issued ||= Time.now.to_i
106
+ end
107
+ attr_writer :references
108
+ def references
109
+ @references ||= []
110
+ end
111
+ attr_writer :description
112
+ def description
113
+ @description ||= ''
114
+ end
115
+ attr_writer :title
116
+ def title
117
+ @title ||= 'untitled update'
118
+ end
119
+ attr_writer :packages
120
+ def packages
121
+ @packages ||= []
122
+ end
123
+
124
+ def initialize; end
93
125
 
94
126
  # an update is not empty if it
95
127
  # updates something
@@ -101,14 +133,13 @@ module EnhanceRepo
101
133
  "update-#{updateid}-#{version}"
102
134
  end
103
135
 
104
-
105
136
  # write a update out
106
137
  def write(file)
107
- builder = Builder::XmlMarkup.new(:target=>file, :indent=>2)
138
+ builder = Builder::XmlMarkup.new(target: file, indent: 2)
108
139
  append_to_builder(builder)
109
140
  end
110
-
111
- def append_to_builder(builder)
141
+
142
+ def append_to_builder(builder)
112
143
  builder.update('status' => 'stable', 'from' => from, 'version' => version, 'type' => type) do |b|
113
144
  b.title(title)
114
145
  b.id(updateid)
@@ -116,26 +147,24 @@ module EnhanceRepo
116
147
  b.release(release)
117
148
  b.description(description)
118
149
  # serialize attr_reader :eferences
119
- b.references do |b|
150
+ b.references do
120
151
  references.each do |r|
121
- b.reference('href' => r.href, 'id' => r.referenceid, 'title' => r.title, 'type' => r.type )
152
+ b.reference('href' => r.href, 'id' => r.referenceid, 'title' => r.title, 'type' => r.type)
122
153
  end
123
154
  end
124
155
  # done with references
125
- b.pkglist do |b|
126
- b.collection do |b|
156
+ b.pkglist do
157
+ b.collection do
127
158
  packages.each do |pkg|
128
- b.package('name' => pkg.name, 'arch'=> pkg.arch, 'version'=>pkg.version.v, 'release'=>pkg.version.r) do |b|
159
+ b.package('name' => pkg.name, 'arch' => pkg.arch, 'version' => pkg.version.v, 'release' => pkg.version.r) do
129
160
  b.filename(File.basename(pkg.path))
130
161
  end
131
162
  end
132
163
  end # </collection>
133
- end #</pkglist>
164
+ end # </pkglist>
134
165
  # done with the packagelist
135
166
  end
136
167
  end
137
-
138
168
  end
139
-
140
169
  end
141
170
  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
  # Copyright (C) 2009, Jordi Massager Pla <jordi.massagerpla@opensuse.org>
@@ -37,9 +39,7 @@ require 'enhance_repo/rpm_md/update'
37
39
 
38
40
  module EnhanceRepo
39
41
  module RpmMd
40
-
41
42
  class UpdateInfo < Data
42
-
43
43
  def initialize(config)
44
44
  @dir = config.dir
45
45
  @basedir = config.updatesbasedir
@@ -59,7 +59,7 @@ module EnhanceRepo
59
59
  # add all updates in a repoparts directory
60
60
  # by default look in repoparts/
61
61
  # otherwise pass the :repoparts_path option
62
- def read_repoparts(opts={})
62
+ def read_repoparts(opts = {})
63
63
  repoparts_path = opts[:repoparts_path] || File.join(@dir, 'repoparts')
64
64
  log.info "Reading update parts from #{repoparts_path}"
65
65
  Dir[File.join(repoparts_path, 'update-*.xml')].each do |updatefile|
@@ -75,14 +75,13 @@ module EnhanceRepo
75
75
  #
76
76
  # outputdir is the directory where to save the patch to.
77
77
  def generate_update(packages, outputdir)
78
-
79
78
  # make a hash name -> array of packages
80
- log.info "Generating update part to #{outputdir} for packages #{packages.join(", ")}"
79
+ log.info "Generating update part to #{outputdir} for packages #{packages.join(', ')}"
81
80
  package_index = {}
82
81
 
83
82
  # look all rpms in the old packages base directory plus
84
83
  # the ones in the current one
85
- rpmfiles = [ Dir["#{@dir}/**/*.rpm"], @basedir.nil? ? [] : Dir["#{@basedir}/**/*.rpm"]].flatten
84
+ rpmfiles = [Dir["#{@dir}/**/*.rpm"], @basedir.nil? ? [] : Dir["#{@basedir}/**/*.rpm"]].flatten
86
85
  log.info "`-> #{rpmfiles.size} rpm packages"
87
86
  # reject unwanted files
88
87
  rpmfiles.reject! do |rpmfile|
@@ -99,18 +98,18 @@ module EnhanceRepo
99
98
 
100
99
  log.info "`-> #{rpmfiles.size} rpm packages were not discarded"
101
100
  log.debug " #{rpmfiles.map { |x| File.basename(x) }.join(', ')}"
102
-
101
+
103
102
  # now index all rpms per package name in a hash table
104
103
  # which goes from name => list of versions
105
104
  rpmfiles.each do |rpmfile|
106
105
  rpm = PackageId.new(rpmfile)
107
106
  # now that we have the real name, reject if it is not part
108
107
  # of the requested packages to generate updates for
109
- next if not packages.include?(rpm.name)
110
-
111
- package_index[rpm.name] = Array.new if not package_index.has_key?(rpm.name)
108
+ next unless packages.include?(rpm.name)
109
+
110
+ package_index[rpm.name] = [] unless package_index.key?(rpm.name)
112
111
  # add the rpm if there is no other rpm with the same version
113
- package_index[rpm.name] << rpm if not package_index[rpm.name].select { |x| x.version == rpm.version && x.name == rpm.name }.first
112
+ package_index[rpm.name] << rpm unless package_index[rpm.name].select { |x| x.version == rpm.version && x.name == rpm.name }.first
114
113
  end
115
114
 
116
115
  log.info "`-> indexed #{package_index.size} unique packages from #{rpmfiles.size} rpms"
@@ -118,7 +117,7 @@ module EnhanceRepo
118
117
  # do our package hash include every package?
119
118
  packages.reject! do |pkg|
120
119
  reject = false
121
- if not package_index.has_key?(pkg)
120
+ unless package_index.key?(pkg)
122
121
  log.warn "`-> the package '#{pkg}' is not available in the repository."
123
122
  reject = true
124
123
  end
@@ -126,59 +125,58 @@ module EnhanceRepo
126
125
  end
127
126
 
128
127
  update = Update.new
129
-
128
+
130
129
  packages.each do |pkgname|
131
130
  pkglist = package_index[pkgname]
132
131
  log.info "`-> #{pkglist.size} versions for '#{pkgname}'"
133
- log.debug " #{package_index[pkgname].map {|x| x.version}.join(", ")}"
132
+ log.debug " #{package_index[pkgname].map(&:version).join(', ')}"
134
133
  # sort them by version
135
- pkglist.sort! { |a,b| a.version <=> b.version }
134
+ pkglist.sort! { |a, b| a.version <=> b.version }
136
135
  pkglist.reverse!
137
136
  # now that the list is sorted, the new rpm is the first
138
137
 
139
138
  # if there is only one package then we don't need changelog
140
139
  if pkglist.size > 1
141
140
  # we know that there are no duplicate versions so we can
142
- # take the first and the second
141
+ # take the first and the second
143
142
  first = pkglist.shift
144
143
  second = pkglist.shift
145
144
  diff = first.changelog - second.changelog || []
146
- #diff = first.changelog[0, first.changelog.size - second.changelog.size] || []
145
+ # diff = first.changelog[0, first.changelog.size - second.changelog.size] || []
147
146
  log.info "`-> found change #{first.ident} and #{second.ident}."
148
-
147
+
149
148
  log.info "`-> '#{pkgname}' has #{diff.size} change entries (#{first.changelog.size}/#{second.changelog.size})"
150
149
  update.packages << first
151
150
  diff.each do |entry|
152
- update.description << entry.text << "\n"
151
+ update.description << entry.text << "\n"
153
152
  end
154
153
  else
155
154
  # jump to next pkgname
156
155
  next
157
156
  end
158
-
159
157
  end
160
158
 
161
159
  # do not save it if there are no packages
162
160
  if update.empty?
163
161
 
164
162
  end
165
-
163
+
166
164
  # before writing the update, figure out more
167
165
  # information
168
166
  update.smart_fill_blank_fields
169
167
 
170
168
  log.info "`-> update has #{update.references.size} references"
171
169
  log.debug " #{update.references.join(',')} "
172
-
173
- filename = ""
170
+
171
+ filename = ''
174
172
 
175
173
  FileUtils.mkdir_p outputdir
176
174
  # increase version until version is available
177
- while ( File.exists?(filename = File.join(outputdir, update.suggested_filename + ".xml") ))
175
+ while File.exist?(filename = File.join(outputdir, update.suggested_filename + '.xml'))
178
176
  update.version += 1
179
177
  end
180
178
  log.info "Saving update part to '#{filename}'."
181
-
179
+
182
180
  File.open(filename, 'w') do |f|
183
181
  update.write(f)
184
182
  end
@@ -193,52 +191,50 @@ module EnhanceRepo
193
191
  #
194
192
  # outputdir is the directory where to save the patch to.
195
193
  def split_updates(outputdir)
196
- FileUtils.mkdir_p outputdir
194
+ FileUtils.mkdir_p outputdir
197
195
  updateinfofile = File.join(@dir, metadata_filename)
198
196
 
199
197
  # we can't split without an updateinfo file
200
- raise "#{updateinfofile} does not exist" if not File.exist?(updateinfofile)
201
- Zlib::GzipReader.open(updateinfofile) do |gz|
198
+ raise "#{updateinfofile} does not exist" unless File.exist?(updateinfofile)
199
+ Zlib::GzipReader.open(updateinfofile) do |gz|
202
200
  document = REXML::Document.new(gz)
203
201
  root = document.root
204
- root.each_element("update") do |updateElement|
202
+ root.each_element('update') do |updateElement|
205
203
  id = nil
206
- updateElement.each_element("id") do |elementId|
204
+ updateElement.each_element('id') do |elementId|
207
205
  id = elementId.text
208
206
  end
209
- if id == nil
207
+ if id.nil?
210
208
  log.warning 'No id found. Setting id to NON_ID_FOUND'
211
209
  id = 'NON_ID_FOUND'
212
210
  end
213
211
  version = 0
214
- updatefilename = ""
215
- while ( File.exists?(updatefilename = File.join(outputdir, "update-#{id}_splited_#{version.to_s}.xml") ) )
212
+ updatefilename = ''
213
+ while File.exist?(updatefilename = File.join(outputdir, "update-#{id}_splited_#{version}.xml"))
216
214
  version += 1
217
215
  end
218
216
  log.info "Saving update part to '#{updatefilename}'."
219
217
  File.open(updatefilename, 'w') do |updatefile|
220
218
  updatefile << updateElement
219
+ updatefile << "\n"
221
220
  end
222
221
  end
223
222
  end
224
223
  end
225
-
224
+
226
225
  # write a update out
227
226
  def write(file)
228
- builder = Builder::XmlMarkup.new(:target=>file, :indent=>2)
227
+ builder = Builder::XmlMarkup.new(target: file, indent: 2)
229
228
  builder.instruct!
230
- xml = builder.updates do |b|
229
+ builder.updates do |_b|
231
230
  @updates.each do |update|
232
231
  File.open(update) do |f|
233
232
  file << f.read
234
233
  end
235
- #update.append_to_builder(b)
234
+ # update.append_to_builder(b)
236
235
  end
237
- end #done builder
236
+ end # done builder
238
237
  end
239
-
240
238
  end
241
-
242
-
243
239
  end
244
240
  end