yumrepo 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format nested
2
+ --color
data/Gemfile CHANGED
@@ -5,9 +5,17 @@ source "http://rubygems.org"
5
5
 
6
6
  # Add dependencies to develop your gem here.
7
7
  # Include everything needed to run rake, tests, features, etc.
8
+
8
9
  group :development do
9
- gem "shoulda", ">= 0"
10
- gem "bundler", "~> 1.0.0"
11
- gem "jeweler", "~> 1.5.2"
12
- gem "rcov", ">= 0"
10
+ gem 'nokogiri', '~> 1.5.0'
11
+ gem 'bundler', '~> 1.0.0'
12
+ gem 'jeweler', '~> 1.5.2'
13
+ gem 'guard'
14
+ end
15
+
16
+ group :test do
17
+ gem 'rspec', '~> 2.6'
18
+ gem 'shoulda'
19
+ gem 'fakeweb'
20
+ gem 'simplecov'
13
21
  end
@@ -0,0 +1,42 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ fakeweb (1.3.0)
6
+ git (1.2.5)
7
+ guard (0.8.4)
8
+ thor (~> 0.14.6)
9
+ jeweler (1.5.2)
10
+ bundler (~> 1.0.0)
11
+ git (>= 1.2.5)
12
+ rake
13
+ multi_json (1.0.3)
14
+ nokogiri (1.5.0)
15
+ rake (0.9.2.2)
16
+ rspec (2.7.0)
17
+ rspec-core (~> 2.7.0)
18
+ rspec-expectations (~> 2.7.0)
19
+ rspec-mocks (~> 2.7.0)
20
+ rspec-core (2.7.1)
21
+ rspec-expectations (2.7.0)
22
+ diff-lcs (~> 1.1.2)
23
+ rspec-mocks (2.7.0)
24
+ shoulda (2.11.3)
25
+ simplecov (0.5.4)
26
+ multi_json (~> 1.0.3)
27
+ simplecov-html (~> 0.5.3)
28
+ simplecov-html (0.5.3)
29
+ thor (0.14.6)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ bundler (~> 1.0.0)
36
+ fakeweb
37
+ guard
38
+ jeweler (~> 1.5.2)
39
+ nokogiri (~> 1.5.0)
40
+ rspec (~> 2.6)
41
+ shoulda
42
+ simplecov
@@ -0,0 +1,9 @@
1
+ # A Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/test_data/.*$})
6
+ watch(%r{^spec/.+_spec\.rb$})
7
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
8
+ watch('spec/spec_helper.rb') { "spec" }
9
+ end
@@ -1,4 +1,5 @@
1
- Copyright (c) 2011 Sergio Rubio
1
+ Copyright (c) 2011 Sergio Rubio <rubiojr@frameos.org>
2
+ Copyright (c) 2011 Matt Stump <mstump@sourceninja.com>
2
3
 
3
4
  Permission is hereby granted, free of charge, to any person obtaining
4
5
  a copy of this software and associated documentation files (the
@@ -0,0 +1,17 @@
1
+ # yumrepo
2
+
3
+ Ruby library to deal with YUM repositories.
4
+
5
+ # Usage
6
+
7
+ Unfortunately yumrepo is pretty much undocummented at the moment. Have a look at the examples/ directory.
8
+
9
+
10
+ # Authors
11
+
12
+ Copyright (c) 2011 Sergio Rubio <rubiojr@frameos.org>
13
+ Copyright (c) 2011 Matt Stump <mstump@sourceninja.com>
14
+
15
+ See LICENSE.txt for
16
+ further details.
17
+
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
- require 'lib/yumrepo'
3
+ require './lib/yumrepo'
4
4
 
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
@@ -17,7 +17,9 @@ Jeweler::Tasks.new do |gem|
17
17
  # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
18
18
  # gem.add_runtime_dependency 'jabber4r', '> 0.1'
19
19
  gem.add_runtime_dependency 'nokogiri'
20
- # gem.add_development_dependency 'rspec', '> 1.2.3'
20
+ gem.add_development_dependency 'rspec'
21
+ gem.add_development_dependency 'simplecov'
22
+ gem.add_development_dependency 'fakeweb'
21
23
  end
22
24
  Jeweler::RubygemsDotOrgTasks.new
23
25
 
@@ -8,10 +8,11 @@ require 'singleton'
8
8
  require 'digest/md5'
9
9
  require 'fileutils'
10
10
  require 'logger'
11
+ require 'tempfile'
11
12
 
12
13
  module YumRepo
13
14
 
14
- VERSION = '0.1'
15
+ VERSION = '0.2'
15
16
 
16
17
  def self.bench(msg)
17
18
  if defined? $yumrepo_perf_debug
@@ -26,7 +27,7 @@ module YumRepo
26
27
 
27
28
  class Settings
28
29
  include Singleton
29
- attr_accessor :cache_path, :cache_expire, :cache_enabled, :log_level
30
+ attr_accessor :cache_path, :cache_expire, :log_level, :cache_enabled
30
31
 
31
32
  def initialize
32
33
  @cache_path = "#{ENV['HOME']}/.yumrepo/cache/"
@@ -40,7 +41,7 @@ module YumRepo
40
41
  def log_level=(level)
41
42
  case level
42
43
  when :warn
43
- level = Logger::WARN
44
+ level = Logger::WARN
44
45
  when :debug
45
46
  level = Logger::DEBUG
46
47
  when :info
@@ -66,13 +67,11 @@ module YumRepo
66
67
  end
67
68
  log.debug "Initializing settings"
68
69
  @initialized = true
69
- log.debug "Creating cache path #{@cache_path}"
70
- FileUtils.mkdir_p @cache_path if not File.exist? @cache_path
71
70
  end
72
71
  end
73
72
 
74
73
  class Repomd
75
-
74
+
76
75
  #
77
76
  # Rasises exception if can't retrieve repomd.xml
78
77
  #
@@ -86,7 +85,7 @@ module YumRepo
86
85
  @url_digest = Digest::MD5.hexdigest(@url)
87
86
  @repomd_file = File.join(@settings.cache_path, @url_digest, 'repomd.xml')
88
87
 
89
- if File.exist?(@repomd_file) and @settings.cache_enabled
88
+ if @settings.cache_enabled and File.exist?(@repomd_file)
90
89
  @settings.log.debug "Using catched repomd.xml at #{@repomd_file}"
91
90
  f = open @repomd_file
92
91
  else
@@ -111,60 +110,78 @@ module YumRepo
111
110
  end
112
111
  fl
113
112
  end
114
-
113
+
115
114
  def primary
116
115
  pl = []
117
116
  @repomd.xpath("/xmlns:repomd/xmlns:data[@type=\"primary\"]/xmlns:location").each do |p|
118
117
  pl << File.join(@url, p['href'])
119
118
  end
120
- @primary_xml = File.join(@settings.cache_path, @url_digest, "primary.xml.gz")
121
- if File.exist?(@primary_xml) and @settings.cache_enabled
122
- @settings.log.debug "Using catched primary.xml.gz at #{@primary_xml}"
123
- f = open @primary_xml
124
- else
125
- @settings.log.debug "Fetching primary.xml.gz from #{pl.first}"
126
- f = open pl.first
127
- if @settings.cache_enabled
128
- FileUtils.mkdir_p File.join(@settings.cache_path, @url_digest)
129
- @settings.log.debug "Caching primary.xml.gz for #{@url} at #{@primary_xml}"
130
- File.open(@primary_xml, 'w') do |xml|
131
- xml.puts f.read
132
- end
133
- end
134
- end
119
+
120
+ @primary_xml ||= _open_file("primary.xml.gz", @url_digest, pl.first)
135
121
  @primary_xml
136
122
  end
137
- end
138
123
 
139
- class PackageList
124
+ def other
125
+ pl = []
126
+ @repomd.xpath("/xmlns:repomd/xmlns:data[@type=\"other\"]/xmlns:location").each do |p|
127
+ pl << File.join(@url, p['href'])
128
+ end
140
129
 
141
- def initialize(url)
142
- @url = url
143
- @xml_file = open(Repomd.new(url).primary)
130
+ @other_xml ||= _open_file("other.xml.gz", @url_digest, pl.first)
131
+ @other_xml
144
132
  end
145
133
 
146
- def each
147
- all.each do |p|
148
- yield p
134
+ private
135
+ def _open_file(filename, cache_dir_name, data_url)
136
+ cache_file_name = File.join(@settings.cache_path, cache_dir_name, filename)
137
+
138
+ if @settings.cache_enabled and File.exist?(cache_file_name) and File.mtime(cache_file_name) > Time.now() - @settings.cache_expire
139
+ @settings.log.debug "Using catched #{filename} at #{cache_file_name}"
140
+ return File.open(cache_file_name, 'r')
149
141
  end
142
+
143
+ FileUtils.mkdir_p File.join(@settings.cache_path, cache_dir_name) if @settings.cache_enabled
144
+ f = File.open(cache_file_name, "w+") if @settings.cache_enabled
145
+ f ||= Tempfile.new(filename)
146
+ f.binmode
147
+ @settings.log.debug "Caching #{filename} for #{data_url} at #{f.path}"
148
+ f.puts open(data_url).read
149
+ f.pos = 0
150
+ return f
150
151
  end
151
152
 
152
- def all
153
+ end
154
+
155
+ class PackageList
156
+
157
+ def initialize(url)
158
+ @url = url
159
+ @xml_file = Repomd.new(url).primary
160
+ @packages = []
161
+
153
162
  buf = ''
154
163
  YumRepo.bench("Zlib::GzipReader.read") do
155
164
  buf = Zlib::GzipReader.new(@xml_file).read
156
165
  end
157
166
 
158
- packages = []
159
167
  YumRepo.bench("Building Package Objects") do
160
168
  d = Nokogiri::XML::Reader(buf)
161
169
  d.each do |n|
162
170
  if n.name == 'package' and not n.node_type == Nokogiri::XML::Reader::TYPE_END_ELEMENT
163
- packages << Package.new(n.outer_xml)
171
+ @packages << Package.new(n.outer_xml)
164
172
  end
165
173
  end
166
174
  end
167
- packages
175
+ end
176
+
177
+ def each
178
+ all.each do |p|
179
+ yield p
180
+ end
181
+ end
182
+
183
+ def all
184
+ @packages
168
185
  end
169
186
  end
170
187
 
@@ -178,30 +195,144 @@ module YumRepo
178
195
  end
179
196
 
180
197
  def name
181
- doc.xpath('/xmlns:package/xmlns:name').text
198
+ doc.xpath('/xmlns:package/xmlns:name').text.strip
199
+ end
200
+
201
+ def summary
202
+ doc.xpath('/xmlns:package/xmlns:summary').text.strip
203
+ end
204
+
205
+ def description
206
+ doc.xpath('/xmlns:package/xmlns:description').text.strip
207
+ end
208
+
209
+ def url
210
+ doc.xpath('/xmlns:package/xmlns:url').text.strip
211
+ end
212
+
213
+ def location
214
+ doc.xpath('/xmlns:package/xmlns:location/@href').text.strip
182
215
  end
183
216
 
184
217
  def version
185
- doc.xpath('/xmlns:package/xmlns:version/@ver').text
218
+ doc.xpath('/xmlns:package/xmlns:version/@ver').text.strip
186
219
  end
187
- def release
188
- doc.xpath('/xmlns:package/xmlns:version/@rel').text
220
+
221
+ def release
222
+ doc.xpath('/xmlns:package/xmlns:version/@rel').text.strip
223
+ end
224
+
225
+ def src_rpm
226
+ doc.xpath('/xmlns:package/xmlns:format/rpm:sourcerpm').text.strip
227
+ end
228
+
229
+ def group
230
+ doc.xpath('/xmlns:package/xmlns:format/rpm:group').text.strip
231
+ end
232
+
233
+ def vendor
234
+ doc.xpath('/xmlns:package/xmlns:format/rpm:vendor').text.strip
235
+ end
236
+
237
+ def license
238
+ doc.xpath('/xmlns:package/xmlns:format/rpm:license').text.strip
189
239
  end
190
240
 
191
241
  def provides
192
242
  doc.xpath('/xmlns:package/xmlns:format/rpm:provides/rpm:entry').map do |pr|
193
243
  {
194
- :name => pr.at_xpath('./@name').text
244
+ :name => pr.at_xpath('./@name').text.strip
195
245
  }
196
246
  end
197
247
  end
198
- def requires
248
+
249
+ def requires
199
250
  doc.xpath('/xmlns:package/xmlns:format/rpm:requires/rpm:entry').map do |pr|
200
251
  {
201
- :name => pr.at_xpath('./@name').text
252
+ :name => pr.at_xpath('./@name').text.strip
202
253
  }
203
254
  end
204
255
  end
205
256
  end
206
257
 
258
+ class PackageChangelogList
259
+ def initialize(url)
260
+ @url = url
261
+ @xml_file = Repomd.new(url).other
262
+ @changelogs = []
263
+
264
+ buf = ''
265
+ YumRepo.bench("Zlib::GzipReader.read") do
266
+ buf = Zlib::GzipReader.new(@xml_file).read
267
+ end
268
+
269
+ YumRepo.bench("Building PackageChangelog Objects") do
270
+ d = Nokogiri::XML::Reader(buf)
271
+ d.each do |n|
272
+ if n.name == 'package' and not n.node_type == Nokogiri::XML::Reader::TYPE_END_ELEMENT
273
+ @changelogs << PackageChangelog.new(n.outer_xml)
274
+ end
275
+ end
276
+ end
277
+ end
278
+
279
+ def each
280
+ all.each do |p|
281
+ yield p
282
+ end
283
+ end
284
+
285
+ def all
286
+ @changelogs
287
+ end
288
+ end
289
+
290
+
291
+ class PackageChangelog
292
+ attr_reader :current_version, :current_release, :name, :arch
293
+
294
+ @@version_regex_std = /(^|\:|\s+|v|r|V|R)(([0-9]+\.){1,10}[a-zA-Z0-9\-]+)/
295
+ @@version_regex_odd = /(([a-zA-Z0-9\-]+)\-[a-zA-Z0-9\-]{1,10})/
296
+
297
+ def initialize(xml)
298
+ doc = Nokogiri::XML(xml)
299
+ doc.remove_namespaces!
300
+ @name = doc.xpath('/package/@name').text.strip
301
+ @arch = doc.xpath('/package/@arch').text.strip
302
+ @current_version = doc.xpath('/package/version/@ver').text.strip
303
+ @current_release = doc.xpath('/package/version/@rel').text.strip
304
+
305
+ @releases = doc.xpath('/package/changelog').map do |pr|
306
+ {
307
+ :author => pr.at_xpath('./@author').text.strip,
308
+ :version => _get_version_string(pr.at_xpath('./@author').text),
309
+ :date => Time.at(pr.at_xpath('./@date').text.strip.to_i),
310
+ :summary => pr.text.sub(/^- /, '')
311
+ }
312
+ end
313
+ end
314
+
315
+ def each
316
+ all.each do |r|
317
+ yield r
318
+ end
319
+ end
320
+
321
+ def all
322
+ @releases
323
+ end
324
+
325
+ private
326
+
327
+ def _get_version_string(input)
328
+ m = @@version_regex_std.match(input)
329
+ return m[2].to_s.strip() if m
330
+
331
+ m = @@version_regex_odd.match(input)
332
+ return m[1].to_s.strip() if m
333
+ end
334
+
335
+ end
336
+
337
+
207
338
  end
@@ -0,0 +1,11 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'rubygems'
5
+ require 'fakeweb'
6
+
7
+ FakeWeb.allow_net_connect = false
8
+
9
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
10
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
11
+ require 'yumrepo'
@@ -0,0 +1,42 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <repomd xmlns="http://linux.duke.edu/metadata/repo">
3
+ <data type="other_db">
4
+ <location href="repodata/other.sqlite.bz2"/>
5
+ <checksum type="sha">362f8116e1baac16b29a608bbe5a8f41676c51da</checksum>
6
+ <timestamp>1314646198</timestamp>
7
+ <open-checksum type="sha">6c6bb9991506cdf4e2b87e540a35da18b049a8d4</open-checksum>
8
+ <database_version>10</database_version>
9
+ </data>
10
+ <data type="other">
11
+ <location href="repodata/other.xml.gz"/>
12
+ <checksum type="sha">ea20b148a776d36f31728a1021bf8627dc0645c7</checksum>
13
+ <timestamp>1314646191</timestamp>
14
+ <open-checksum type="sha">37df3e70da5efa2c7bef05e7c78df2a02542c0c5</open-checksum>
15
+ </data>
16
+ <data type="filelists_db">
17
+ <location href="repodata/filelists.sqlite.bz2"/>
18
+ <checksum type="sha">83431aebe4ed9836582e0dc99c5cce094f20b5e2</checksum>
19
+ <timestamp>1314646199</timestamp>
20
+ <open-checksum type="sha">9cd7c1d306e81e866091fef247404885d3f9eb8a</open-checksum>
21
+ <database_version>10</database_version>
22
+ </data>
23
+ <data type="filelists">
24
+ <location href="repodata/filelists.xml.gz"/>
25
+ <checksum type="sha">03d31094e61757621a0660e1e4be4f63c6af56cf</checksum>
26
+ <timestamp>1314646191</timestamp>
27
+ <open-checksum type="sha">d2f1d9049ac433c4ed7382bb2803873dd425072c</open-checksum>
28
+ </data>
29
+ <data type="primary_db">
30
+ <location href="repodata/primary.sqlite.bz2"/>
31
+ <checksum type="sha">ec5a8b60bdda4eda5a913ecfeee8406dc989e9d8</checksum>
32
+ <timestamp>1314646200</timestamp>
33
+ <open-checksum type="sha">1230630496cb2899261e26d026352a426573c04a</open-checksum>
34
+ <database_version>10</database_version>
35
+ </data>
36
+ <data type="primary">
37
+ <location href="repodata/primary.xml.gz"/>
38
+ <checksum type="sha">7ae73bdcb5961b03a0ca22419bd8da19ddc8c241</checksum>
39
+ <timestamp>1314646191</timestamp>
40
+ <open-checksum type="sha">76e012b3f40ec9f882805d579028076a88e03fe0</open-checksum>
41
+ </data>
42
+ </repomd>
@@ -0,0 +1,204 @@
1
+ require 'rspec'
2
+ require 'net/http'
3
+ require 'spec_helper'
4
+
5
+ describe YumRepo do
6
+
7
+ FakeWeb.register_uri(:get, "http://centos.mirror.freedomvoice.com/6.0/os/SRPMS/repodata/repomd.xml", :body => File.read("spec/test_data/repomd.xml"))
8
+ FakeWeb.register_uri(:get, "http://centos.mirror.freedomvoice.com/6.0/os/SRPMS/repodata/primary.xml.gz", :body => File.read("spec/test_data/primary.xml.gz"))
9
+ FakeWeb.register_uri(:get, "http://centos.mirror.freedomvoice.com/6.0/os/SRPMS/repodata/other.xml.gz", :body => File.read("spec/test_data/other.xml.gz"))
10
+ YumRepo::Settings.instance.log_level = :error
11
+ YumRepo::Settings.instance.cache_enabled = false
12
+
13
+ describe "package list" do
14
+ it "for test_data should have 5 entries" do
15
+ pl = YumRepo::PackageList.new "http://centos.mirror.freedomvoice.com/6.0/os/SRPMS"
16
+ pl.all.length.should == 5
17
+ end
18
+ end
19
+
20
+ describe "package parsing" do
21
+ before :each do
22
+ YumRepo::Settings.instance.cache_enabled = false # not strictly neccessary, but for safety
23
+ @pl = YumRepo::PackageList.new "http://centos.mirror.freedomvoice.com/6.0/os/SRPMS"
24
+ end
25
+
26
+ it "first package should be readline" do
27
+ @pl.all.first.name.should == "readline"
28
+ end
29
+
30
+ it "readline should have a summary" do
31
+ @pl.all.first.summary.should == "A library for editing typed command lines"
32
+ end
33
+
34
+ it "readline should have a version" do
35
+ @pl.all.first.version.should == "6.0"
36
+ end
37
+
38
+ it "readline should have a release" do
39
+ @pl.all.first.release.should == "3.el6"
40
+ end
41
+
42
+ it "perl-Module-Info should not have a source rpm" do
43
+ p = @pl.all.last
44
+ p.name.should == "perl-Module-Info"
45
+ p.src_rpm.should == "xorg-x11-drv-savage-2.3.1-1.1.el6.src.rpm"
46
+ end
47
+
48
+ it "readline should have a source rpm of empty string" do
49
+ @pl.all.first.src_rpm.should == ""
50
+ end
51
+
52
+ it "readline should have a group" do
53
+ @pl.all.first.group.should == "System Environment/Libraries"
54
+ end
55
+
56
+ it "readline should have a vendor" do
57
+ @pl.all.first.vendor.should == "CentOS"
58
+ end
59
+
60
+ it "readline should have a license" do
61
+ @pl.all.first.license.should == "GPLv3+"
62
+ end
63
+
64
+ it "readline should have a description" do
65
+ @pl.all.first.description.should == "The Readline library provides a set of functions
66
+ that allow users to edit command lines. Both Emacs and vi
67
+ editing modes are available. The Readline library includes
68
+ additional functions for maintaining a list of
69
+ previously-entered command lines for recalling or editing those
70
+ lines, and for performing csh-like history expansion on
71
+ previous commands."
72
+ end
73
+
74
+ it "readline should have a url" do
75
+ @pl.all.first.url.should == "http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html"
76
+ end
77
+
78
+ it "readline should have a location" do
79
+ @pl.all.first.location.should == "Packages/readline-6.0-3.el6.src.rpm"
80
+ end
81
+
82
+ it "readline should provide nothing" do
83
+ @pl.all.last.provides.should == [{:name=>"config(pothana2000-fonts)"},
84
+ {:name=>"font(:lang=te)"},
85
+ {:name=>"font(pothana2000)"},
86
+ {:name=>"pothana2000-fonts"}]
87
+ end
88
+
89
+ it "perl-Module-Info should provide stuff" do
90
+ p = @pl.all.last
91
+ p.name.should == "perl-Module-Info"
92
+ @pl.all.first.provides.should == []
93
+ end
94
+
95
+ it "readline should require stuff" do
96
+ @pl.all.first.requires.should == [{:name=>"rpmlib(FileDigests)"},
97
+ {:name=>"ncurses-devel"},
98
+ {:name=>"rpmlib(CompressedFileNames)"}]
99
+ end
100
+ end
101
+
102
+ describe "cache" do
103
+ before :each do
104
+ @cache_dir = File.expand_path("~/.yumrepo/cache/09e41263dad74ad145d3ace79bbdaf21")
105
+ @cache_file = File.join(@cache_dir, "primary.xml.gz")
106
+ FileUtils.remove_entry_secure(@cache_dir) if File.exist?(@cache_dir)
107
+ end
108
+
109
+ it "enabled the cache file should be created" do
110
+ File.exist?(@cache_file).should == false
111
+ YumRepo::Settings.instance.cache_enabled = true
112
+ pl = YumRepo::PackageList.new "http://centos.mirror.freedomvoice.com/6.0/os/SRPMS"
113
+ pl.all.length.should == 5
114
+ File.exist?(@cache_file).should == true
115
+ end
116
+
117
+ it "enabled and cache file exists, we should use it if it's not too old" do
118
+ File.exist?(@cache_file).should == false
119
+ YumRepo::Settings.instance.cache_enabled = true
120
+ YumRepo::PackageList.new "http://centos.mirror.freedomvoice.com/6.0/os/SRPMS"
121
+ File.exist?(@cache_file).should == true
122
+
123
+ mtime = Time.at(((Time.now() - YumRepo::Settings.instance.cache_expire) + 10).to_i)
124
+ File.utime(0, mtime, @cache_file)
125
+ File.atime(@cache_file).should == Time.at(0)
126
+ File.mtime(@cache_file).should == mtime
127
+ YumRepo::PackageList.new "http://centos.mirror.freedomvoice.com/6.0/os/SRPMS"
128
+ File.mtime(@cache_file).should == mtime
129
+ (File.atime(@cache_file) > Time.at(0)).should == true
130
+ end
131
+
132
+ it "enabled and cache file exists, and is too old we should replace it" do
133
+ File.exist?(@cache_file).should == false
134
+ YumRepo::Settings.instance.cache_enabled = true
135
+ YumRepo::PackageList.new "http://centos.mirror.freedomvoice.com/6.0/os/SRPMS"
136
+ File.exist?(@cache_file).should == true
137
+
138
+ File.utime(0, 1, @cache_file)
139
+ File.atime(@cache_file).should == Time.at(0)
140
+ File.mtime(@cache_file).should == Time.at(1)
141
+ YumRepo::PackageList.new "http://centos.mirror.freedomvoice.com/6.0/os/SRPMS"
142
+ File.mtime(@cache_file).should_not == Time.at(1)
143
+ (File.atime(@cache_file) > Time.at(0)).should == true
144
+ end
145
+
146
+ it "disabled the cache file should not be created" do
147
+ File.exist?(@cache_file).should == false
148
+ YumRepo::Settings.instance.cache_enabled = false
149
+ pl = YumRepo::PackageList.new "http://centos.mirror.freedomvoice.com/6.0/os/SRPMS"
150
+ pl.all.length.should == 5
151
+ File.exist?(@cache_file).should == false
152
+ end
153
+
154
+ after :each do
155
+ YumRepo::Settings.instance.cache_enabled = false
156
+ FileUtils.remove_entry_secure(@cache_dir) if File.exist?(@cache_dir)
157
+ end
158
+ end
159
+
160
+ describe "package changelog list" do
161
+ it "for test_data should have 2 entries with 73 and 18 entries respectivly" do
162
+ pl = YumRepo::PackageChangelogList.new "http://centos.mirror.freedomvoice.com/6.0/os/SRPMS"
163
+ pl.all.length.should == 2
164
+ pl.all.first.all.length.should == 73
165
+ pl.all.last.all.length.should == 18
166
+ end
167
+ end
168
+
169
+ describe "parse package changelog" do
170
+ before :each do
171
+ @pl = YumRepo::PackageChangelogList.new "http://centos.mirror.freedomvoice.com/6.0/os/SRPMS"
172
+ @first = @pl.all.first
173
+ @last = @pl.all.last
174
+ end
175
+
176
+ it "first change log should have a name" do
177
+ @first.name.should == "readline"
178
+ end
179
+
180
+ it "first change log should have an arch" do
181
+ @first.arch.should == "src"
182
+ end
183
+
184
+ it "first change log should have a current version" do
185
+ @first.current_version.should == "6.0"
186
+ end
187
+
188
+ it "first change log should have a current release" do
189
+ @first.current_release.should == "3.el6"
190
+ end
191
+
192
+ it "first entry of first changelog should have an author" do
193
+ @first.all.first[:author].should == "Miroslav Lichvar <mlichvar@redhat.com> 6.0-3"
194
+ end
195
+
196
+ it "first entry of first changelog should have a version" do
197
+ @first.all.first[:version].should == "6.0-3"
198
+ end
199
+
200
+ it "first entry of first changelog should have a date" do
201
+ @first.all.first[:date].should == Time.at(1251201600)
202
+ end
203
+ end
204
+ end
@@ -0,0 +1,76 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "yumrepo"
8
+ s.version = "0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Sergio Rubio"]
12
+ s.date = "2011-11-09"
13
+ s.description = "YUM Repository Metadata handling library"
14
+ s.email = "rubiojr@frameos.org"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "Guardfile",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "examples/basic.rb",
29
+ "lib/yumrepo.rb",
30
+ "spec/spec_helper.rb",
31
+ "spec/test_data/other.xml.gz",
32
+ "spec/test_data/primary.xml.gz",
33
+ "spec/test_data/repomd.xml",
34
+ "spec/yumrepo_spec.rb",
35
+ "yumrepo.gemspec"
36
+ ]
37
+ s.homepage = "http://github.com/rubiojr/yumrepo"
38
+ s.licenses = ["MIT"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = "1.8.10"
41
+ s.summary = "YUM Repository Metadata handling library"
42
+
43
+ if s.respond_to? :specification_version then
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
+ s.add_development_dependency(%q<nokogiri>, ["~> 1.5.0"])
48
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
49
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
50
+ s.add_development_dependency(%q<guard>, [">= 0"])
51
+ s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
52
+ s.add_development_dependency(%q<rspec>, [">= 0"])
53
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
54
+ s.add_development_dependency(%q<fakeweb>, [">= 0"])
55
+ else
56
+ s.add_dependency(%q<nokogiri>, ["~> 1.5.0"])
57
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
59
+ s.add_dependency(%q<guard>, [">= 0"])
60
+ s.add_dependency(%q<nokogiri>, [">= 0"])
61
+ s.add_dependency(%q<rspec>, [">= 0"])
62
+ s.add_dependency(%q<simplecov>, [">= 0"])
63
+ s.add_dependency(%q<fakeweb>, [">= 0"])
64
+ end
65
+ else
66
+ s.add_dependency(%q<nokogiri>, ["~> 1.5.0"])
67
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
68
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
69
+ s.add_dependency(%q<guard>, [">= 0"])
70
+ s.add_dependency(%q<nokogiri>, [">= 0"])
71
+ s.add_dependency(%q<rspec>, [">= 0"])
72
+ s.add_dependency(%q<simplecov>, [">= 0"])
73
+ s.add_dependency(%q<fakeweb>, [">= 0"])
74
+ end
75
+ end
76
+
metadata CHANGED
@@ -1,144 +1,151 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: yumrepo
3
- version: !ruby/object:Gem::Version
4
- hash: 9
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.2'
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- version: "0.1"
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Sergio Rubio
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2011-08-11 00:00:00 Z
18
- dependencies:
19
- - !ruby/object:Gem::Dependency
20
- version_requirements: &id001 !ruby/object:Gem::Requirement
12
+ date: 2011-11-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: &12472800 !ruby/object:Gem::Requirement
21
17
  none: false
22
- requirements:
23
- - - ">="
24
- - !ruby/object:Gem::Version
25
- hash: 3
26
- segments:
27
- - 0
28
- version: "0"
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.5.0
29
22
  type: :development
30
- requirement: *id001
31
23
  prerelease: false
32
- name: shoulda
33
- - !ruby/object:Gem::Dependency
34
- version_requirements: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *12472800
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
27
+ requirement: &12506340 !ruby/object:Gem::Requirement
35
28
  none: false
36
- requirements:
29
+ requirements:
37
30
  - - ~>
38
- - !ruby/object:Gem::Version
39
- hash: 23
40
- segments:
41
- - 1
42
- - 0
43
- - 0
31
+ - !ruby/object:Gem::Version
44
32
  version: 1.0.0
45
33
  type: :development
46
- requirement: *id002
47
34
  prerelease: false
48
- name: bundler
49
- - !ruby/object:Gem::Dependency
50
- version_requirements: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *12506340
36
+ - !ruby/object:Gem::Dependency
37
+ name: jeweler
38
+ requirement: &12504180 !ruby/object:Gem::Requirement
51
39
  none: false
52
- requirements:
40
+ requirements:
53
41
  - - ~>
54
- - !ruby/object:Gem::Version
55
- hash: 7
56
- segments:
57
- - 1
58
- - 5
59
- - 2
42
+ - !ruby/object:Gem::Version
60
43
  version: 1.5.2
61
44
  type: :development
62
- requirement: *id003
63
45
  prerelease: false
64
- name: jeweler
65
- - !ruby/object:Gem::Dependency
66
- version_requirements: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *12504180
47
+ - !ruby/object:Gem::Dependency
48
+ name: guard
49
+ requirement: &12501300 !ruby/object:Gem::Requirement
67
50
  none: false
68
- requirements:
69
- - - ">="
70
- - !ruby/object:Gem::Version
71
- hash: 3
72
- segments:
73
- - 0
74
- version: "0"
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
75
55
  type: :development
76
- requirement: *id004
77
56
  prerelease: false
78
- name: rcov
79
- - !ruby/object:Gem::Dependency
80
- version_requirements: &id005 !ruby/object:Gem::Requirement
57
+ version_requirements: *12501300
58
+ - !ruby/object:Gem::Dependency
59
+ name: nokogiri
60
+ requirement: &12499020 !ruby/object:Gem::Requirement
81
61
  none: false
82
- requirements:
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- hash: 3
86
- segments:
87
- - 0
88
- version: "0"
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
89
66
  type: :runtime
90
- requirement: *id005
91
67
  prerelease: false
92
- name: nokogiri
68
+ version_requirements: *12499020
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: &12572780 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *12572780
80
+ - !ruby/object:Gem::Dependency
81
+ name: simplecov
82
+ requirement: &12647220 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *12647220
91
+ - !ruby/object:Gem::Dependency
92
+ name: fakeweb
93
+ requirement: &12723600 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *12723600
93
102
  description: YUM Repository Metadata handling library
94
103
  email: rubiojr@frameos.org
95
104
  executables: []
96
-
97
105
  extensions: []
98
-
99
- extra_rdoc_files:
106
+ extra_rdoc_files:
100
107
  - LICENSE.txt
101
- - README.rdoc
102
- files:
108
+ - README.md
109
+ files:
103
110
  - .document
111
+ - .rspec
104
112
  - Gemfile
113
+ - Gemfile.lock
114
+ - Guardfile
105
115
  - LICENSE.txt
106
- - README.rdoc
116
+ - README.md
107
117
  - Rakefile
108
118
  - examples/basic.rb
109
119
  - lib/yumrepo.rb
120
+ - spec/spec_helper.rb
121
+ - spec/test_data/other.xml.gz
122
+ - spec/test_data/primary.xml.gz
123
+ - spec/test_data/repomd.xml
124
+ - spec/yumrepo_spec.rb
125
+ - yumrepo.gemspec
110
126
  homepage: http://github.com/rubiojr/yumrepo
111
- licenses:
127
+ licenses:
112
128
  - MIT
113
129
  post_install_message:
114
130
  rdoc_options: []
115
-
116
- require_paths:
131
+ require_paths:
117
132
  - lib
118
- required_ruby_version: !ruby/object:Gem::Requirement
133
+ required_ruby_version: !ruby/object:Gem::Requirement
119
134
  none: false
120
- requirements:
121
- - - ">="
122
- - !ruby/object:Gem::Version
123
- hash: 3
124
- segments:
125
- - 0
126
- version: "0"
127
- required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
140
  none: false
129
- requirements:
130
- - - ">="
131
- - !ruby/object:Gem::Version
132
- hash: 3
133
- segments:
134
- - 0
135
- version: "0"
141
+ requirements:
142
+ - - ! '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
136
145
  requirements: []
137
-
138
146
  rubyforge_project:
139
- rubygems_version: 1.8.5
147
+ rubygems_version: 1.8.10
140
148
  signing_key:
141
149
  specification_version: 3
142
150
  summary: YUM Repository Metadata handling library
143
151
  test_files: []
144
-
@@ -1,19 +0,0 @@
1
- = yumrepo
2
-
3
- Description goes here.
4
-
5
- == Contributing to yumrepo
6
-
7
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
- * Fork the project
10
- * Start a feature/bugfix branch
11
- * Commit and push until you are happy with your contribution
12
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
-
15
- == Copyright
16
-
17
- Copyright (c) 2011 Sergio Rubio. See LICENSE.txt for
18
- further details.
19
-