pkgwat 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -29,7 +29,7 @@ Inside your code, simply require rubygems and pkgwat. Then you use it like so:
29
29
  Pkgwat.get_versions("rails")
30
30
 
31
31
  # this will return true or false if the package exists
32
- Pkgwat.check_gem("pry", "0.9.10", [Pkgwat::F16])
32
+ Pkgwat.check_gem("pry", "0.9.10", ["Fedora EPEL 6", "Fedora 19", "Rawhide"])
33
33
  ```
34
34
 
35
35
  ### Rake Tasks
@@ -64,8 +64,8 @@ Then just fire up irb:
64
64
 
65
65
  ```
66
66
  irb -Ilib -rpkgwat
67
- >> Pkgwat::F16
68
- => "Fedora 16"
67
+ >> Pkgwat.get_versions("runcible")
68
+ => [{"release"=>"Rawhide", ...
69
69
  ```
70
70
 
71
71
  ### Testing
@@ -6,12 +6,6 @@ require 'sanitize'
6
6
  module Pkgwat
7
7
  require 'pkgwat/railtie' if defined?(Rails)
8
8
 
9
- F17 = "Fedora 17"
10
- F16 = "Fedora 16"
11
- F18 = "Fedora 18"
12
- EPEL6 = "Fedora EPEL 6"
13
- EPEL5 = "Fedora EPEL 5"
14
- DEFAULT_DISTROS = [F17, F16, EPEL6]
15
9
  PACKAGE_NAME = "rubygem-:gem"
16
10
  PACKAGES_URL = "https://apps.fedoraproject.org/packages/fcomm_connector/bodhi/query/query_active_releases"
17
11
  PACKAGES_URL_LIST = "https://apps.fedoraproject.org/packages/fcomm_connector/xapian/query/search_packages"
@@ -20,31 +14,34 @@ module Pkgwat
20
14
  CHANGELOG_URL = "https://apps.fedoraproject.org/packages/fcomm_connector/koji/query/query_changelogs"
21
15
  CONTENT_URL = "https://apps.fedoraproject.org/packages/fcomm_connector/yum/get_file_tree"
22
16
  UPDATES_URL = "https://apps.fedoraproject.org/packages/fcomm_connector/bodhi/query/query_updates"
23
- KOJI_BUILD_STATES = ["all" => "", "f17" =>"17", "f16" => "16", "f15" => "15", "e16" => "16", "e15" => "15"]
17
+ KOJI_BUILD_STATES = ["all" => "", "f19" =>"19", "f18" => "18", "f20" => "20", "e16" => "16", "e15" => "15"]
24
18
  BUGZILLA_RELEASEA = ["all" => "", "building" =>"0", "success" => "1", "failed" => "2", "cancelled" => "3", "deleted" => "4"]
25
- BODHI_REALEASE = ["all", "f17", "f16", "f15", "e16", "e15"]
19
+ BODHI_REALEASE = ["all", "f19", "f18", "f20", "e16", "e15"]
26
20
  BODHI_ARCH = ["x86_64", "i686"]
27
21
 
28
22
  class << self
29
23
  attr_accessor :debug
30
24
  end
31
25
 
32
- def self.check_gem(name, version, distros = DEFAULT_DISTROS, throw_ex = false)
33
- puts "Checking #{name} #{version}...\n" if self.debug
26
+ def self.check_gem(name, version, distros, throw_ex = false)
34
27
  versions = get_versions(name)
35
- matches = []
36
- distros.each do |distro|
37
- dv = versions.detect { |v| v["release"] == distro }
38
- match = compare_versions(version, dv["stable_version"])
39
- matches << dv["release"] if match
28
+ distros = Array(distros) # convert distros to an array if not already
29
+
30
+ matches = distros.each_with_object([]) do |distro, results|
31
+ distro_match = versions.detect { |v| v["release"] == distro }
32
+ if distro_match
33
+ distro_version = distro_match["stable_version"][/\A(\S+)-.*\z/, 1] # get the actual gem version
34
+ match = compare_versions(version, distro_version)
35
+ results << distro_match["release"] if match
36
+ end
40
37
  end
41
- puts "#{name} is available in the following distros: #{matches.join(",")}" if self.debug
42
38
 
43
- matches.any?
39
+ matches.any? ? matches : false
44
40
  end
45
41
 
46
- def self.compare_versions(version, distro)
47
- distro.to_s.split("-").first == version.to_s
42
+ def self.compare_versions(version1, version2)
43
+ return false if version1.nil? || version1.to_s.length < 1 || version2.nil? || version2.to_s.length < 1
44
+ Gem::Version.new(version1) == Gem::Version.new(version2)
48
45
  end
49
46
 
50
47
  def self.get_versions(gem_name)
@@ -1,12 +1,29 @@
1
1
  require 'rake'
2
2
  require 'pkgwat'
3
3
 
4
+ DISTRO_ERROR_MESSAGE = <<-EOS
5
+ ERROR: Distros not supplied. Please call this task with distros (e.g. rake pkgwat:check DISTROS="Fedora 19, Fedora EPEL 6, Rawhide")
6
+ EOS
7
+
8
+ def gem_output(gem)
9
+ "#{gem.name} #{gem.version}"
10
+ end
11
+
4
12
  namespace :pkgwat do
5
13
  desc "Check the Gemfile.lock for packages"
6
14
  task :check do
15
+ distros = ENV['DISTROS']
16
+ raise DISTRO_ERROR_MESSAGE if distros.nil? || distros.length < 1
17
+ distros = distros.split(",")
18
+
7
19
  lockfile = Bundler::LockfileParser.new(Bundler.read_file("Gemfile.lock"))
8
20
  lockfile.specs.each do |gem|
9
- Pkgwat.check_gem(gem.name, gem.version)
21
+ puts "Checking gem (#{gem_output(gem)})"
22
+ if rel = Pkgwat.check_gem(gem.name, gem.version, distros)
23
+ puts " OK: #{gem_output(gem)} available in #{rel.join(", ")}"
24
+ else
25
+ puts " FAIL: #{gem_output(gem)} not in #{distros.join(", ")}"
26
+ end
10
27
  end
11
28
  end
12
29
  end
@@ -1,3 +1,3 @@
1
1
  module Pkgwat
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -17,36 +17,36 @@ http_interactions:
17
17
  message: OK
18
18
  headers:
19
19
  Date:
20
- - Sun, 20 Jan 2013 17:10:05 GMT
20
+ - Sat, 27 Jul 2013 16:16:41 GMT
21
21
  Server:
22
22
  - Apache/2.2.15 (Red Hat)
23
23
  Content-Length:
24
- - '577'
24
+ - '561'
25
25
  Apptime:
26
- - D=5932
26
+ - D=4908
27
27
  Appserver:
28
- - packages02.phx2.fedoraproject.org
28
+ - packages01.phx2.fedoraproject.org
29
29
  Vary:
30
30
  - Accept-Encoding
31
31
  Content-Type:
32
32
  - text/html; charset=UTF-8
33
33
  Proxytime:
34
- - D=35750
34
+ - D=146264
35
35
  Proxyserver:
36
- - proxy08.fedoraproject.org
36
+ - proxy04.fedoraproject.org
37
37
  body:
38
38
  encoding: US-ASCII
39
- string: ! '{"start_row":0,"total_rows":6,"rows":[{"stable_version":"3.2.8-1.fc18","release":"Rawhide","testing_version":"<i>Not
40
- Applicable</i>"},{"stable_version":"3.2.8-1.fc18","release":"Fedora 18","testing_version":"None"},{"stable_version":"3.0.11-1.fc17","release":"Fedora
41
- 17","testing_version":"None"},{"stable_version":"3.0.10-1.fc16","release":"Fedora
42
- 16","testing_version":"None"},{"stable_version":"None","release":"Fedora EPEL
43
- 6","testing_version":"None"},{"stable_version":"2.1.1-2.el5","release":"Fedora
44
- EPEL 5","testing_version":"None"}],"rows_per_page":10,"visible_rows":6}'
39
+ string: ! '{"rows":[{"release":"Rawhide","testing_version":"None","stable_version":"3.2.13-1.fc20"},{"release":"Fedora
40
+ 19","testing_version":"None","stable_version":"3.2.13-1.fc19"},{"release":"Fedora
41
+ 18","testing_version":"None","stable_version":"3.2.8-1.fc18"},{"release":"Fedora
42
+ 17","testing_version":"None","stable_version":"3.0.11-1.fc17"},{"release":"Fedora
43
+ EPEL 6","testing_version":"None","stable_version":"None"},{"release":"Fedora
44
+ EPEL 5","testing_version":"None","stable_version":"2.1.1-2.el5"}],"rows_per_page":10,"start_row":0,"visible_rows":6,"total_rows":6}'
45
45
  http_version:
46
- recorded_at: Sun, 20 Jan 2013 17:10:03 GMT
46
+ recorded_at: Sat, 27 Jul 2013 16:16:42 GMT
47
47
  - request:
48
48
  method: get
49
- uri: https://apps.fedoraproject.org/packages/fcomm_connector/bodhi/query/query_active_releases/%7B%22filters%22:%7B%22package%22:%22rubygem-rails%22%7D%7D
49
+ uri: https://apps.fedoraproject.org/packages/fcomm_connector/bodhi/query/query_active_releases/%7B%22filters%22:%7B%22package%22:%22rubygem-this-gem-doesnt-exist%22%7D%7D
50
50
  body:
51
51
  encoding: US-ASCII
52
52
  string: ''
@@ -61,13 +61,13 @@ http_interactions:
61
61
  message: OK
62
62
  headers:
63
63
  Date:
64
- - Sun, 20 Jan 2013 17:10:05 GMT
64
+ - Sat, 27 Jul 2013 16:16:41 GMT
65
65
  Server:
66
66
  - Apache/2.2.15 (Red Hat)
67
67
  Content-Length:
68
- - '577'
68
+ - '519'
69
69
  Apptime:
70
- - D=6254
70
+ - D=3366
71
71
  Appserver:
72
72
  - packages02.phx2.fedoraproject.org
73
73
  Vary:
@@ -75,23 +75,21 @@ http_interactions:
75
75
  Content-Type:
76
76
  - text/html; charset=UTF-8
77
77
  Proxytime:
78
- - D=142563
78
+ - D=144030
79
79
  Proxyserver:
80
80
  - proxy04.fedoraproject.org
81
81
  body:
82
82
  encoding: US-ASCII
83
- string: ! '{"visible_rows":6,"total_rows":6,"start_row":0,"rows":[{"stable_version":"3.2.8-1.fc18","testing_version":"<i>Not
84
- Applicable</i>","release":"Rawhide"},{"stable_version":"3.2.8-1.fc18","testing_version":"None","release":"Fedora
85
- 18"},{"stable_version":"3.0.11-1.fc17","testing_version":"None","release":"Fedora
86
- 17"},{"stable_version":"3.0.10-1.fc16","testing_version":"None","release":"Fedora
87
- 16"},{"stable_version":"None","testing_version":"None","release":"Fedora EPEL
88
- 6"},{"stable_version":"2.1.1-2.el5","testing_version":"None","release":"Fedora
89
- EPEL 5"}],"rows_per_page":10}'
83
+ string: ! '{"rows_per_page":10,"total_rows":6,"start_row":0,"rows":[{"release":"Rawhide","testing_version":"None","stable_version":"None"},{"release":"Fedora
84
+ 19","testing_version":"None","stable_version":"None"},{"release":"Fedora 18","testing_version":"None","stable_version":"None"},{"release":"Fedora
85
+ 17","testing_version":"None","stable_version":"None"},{"release":"Fedora EPEL
86
+ 6","testing_version":"None","stable_version":"None"},{"release":"Fedora EPEL
87
+ 5","testing_version":"None","stable_version":"None"}],"visible_rows":6}'
90
88
  http_version:
91
- recorded_at: Sun, 20 Jan 2013 17:10:04 GMT
89
+ recorded_at: Sat, 27 Jul 2013 16:16:42 GMT
92
90
  - request:
93
91
  method: get
94
- uri: https://apps.fedoraproject.org/packages/fcomm_connector/bodhi/query/query_active_releases/%7B%22filters%22:%7B%22package%22:%22rubygem-this-gem-doesnt-exist%22%7D%7D
92
+ uri: https://apps.fedoraproject.org/packages/fcomm_connector/bodhi/query/query_active_releases/%7B%22filters%22:%7B%22package%22:%22rubygem-rails%22%7D%7D
95
93
  body:
96
94
  encoding: US-ASCII
97
95
  string: ''
@@ -106,13 +104,13 @@ http_interactions:
106
104
  message: OK
107
105
  headers:
108
106
  Date:
109
- - Sun, 20 Jan 2013 17:10:03 GMT
107
+ - Sat, 27 Jul 2013 16:16:42 GMT
110
108
  Server:
111
109
  - Apache/2.2.15 (Red Hat)
112
110
  Content-Length:
113
- - '566'
111
+ - '561'
114
112
  Apptime:
115
- - D=6904
113
+ - D=7796
116
114
  Appserver:
117
115
  - packages01.phx2.fedoraproject.org
118
116
  Vary:
@@ -120,17 +118,17 @@ http_interactions:
120
118
  Content-Type:
121
119
  - text/html; charset=UTF-8
122
120
  Proxytime:
123
- - D=137898
121
+ - D=148018
124
122
  Proxyserver:
125
123
  - proxy04.fedoraproject.org
126
124
  body:
127
125
  encoding: US-ASCII
128
- string: ! '{"total_rows":6,"rows_per_page":10,"start_row":0,"visible_rows":6,"rows":[{"testing_version":"<i>Not
129
- Applicable</i>","stable_version":"No builds tagged with dist-5E-epel","release":"Rawhide"},{"testing_version":"None","stable_version":"None","release":"Fedora
130
- 18"},{"testing_version":"None","stable_version":"None","release":"Fedora 17"},{"testing_version":"None","stable_version":"None","release":"Fedora
131
- 16"},{"testing_version":"None","stable_version":"None","release":"Fedora EPEL
132
- 6"},{"testing_version":"None","stable_version":"None","release":"Fedora EPEL
133
- 5"}]}'
126
+ string: ! '{"rows":[{"release":"Rawhide","testing_version":"None","stable_version":"3.2.13-1.fc20"},{"release":"Fedora
127
+ 19","testing_version":"None","stable_version":"3.2.13-1.fc19"},{"release":"Fedora
128
+ 18","testing_version":"None","stable_version":"3.2.8-1.fc18"},{"release":"Fedora
129
+ 17","testing_version":"None","stable_version":"3.0.11-1.fc17"},{"release":"Fedora
130
+ EPEL 6","testing_version":"None","stable_version":"None"},{"release":"Fedora
131
+ EPEL 5","testing_version":"None","stable_version":"2.1.1-2.el5"}],"start_row":0,"rows_per_page":10,"visible_rows":6,"total_rows":6}'
134
132
  http_version:
135
- recorded_at: Sun, 20 Jan 2013 17:10:04 GMT
133
+ recorded_at: Sat, 27 Jul 2013 16:16:42 GMT
136
134
  recorded_with: VCR 2.4.0
@@ -2,10 +2,6 @@ require 'test_helper'
2
2
 
3
3
  describe "Pkgwat" do
4
4
 
5
- it "has a Fedora 17 constant" do
6
- Pkgwat::F17.must_equal "Fedora 17"
7
- end
8
-
9
5
  describe "#check_gem" do
10
6
  before do
11
7
  VCR.insert_cassette('pkgwat_check_gem')
@@ -16,21 +12,24 @@ describe "Pkgwat" do
16
12
  end
17
13
 
18
14
  it "returns false for a non-existing gem" do
19
- Pkgwat.check_gem("this-gem-doesnt-exist", "0.0.1").must_equal false
15
+ Pkgwat.check_gem("this-gem-doesnt-exist", "0.0.1", ["Rawhide"]).must_equal false
20
16
  end
21
17
 
22
18
  it "returns true for existing gem" do
23
- Pkgwat.check_gem("rails", "3.2.8", [Pkgwat::F18]).must_equal true
19
+ (!!Pkgwat.check_gem("rails", "3.2.13", "Fedora 19")).must_equal true
24
20
  end
25
21
 
26
22
  it "returns false for non-existing version" do
27
- Pkgwat.check_gem("rails", "3.2.8", [Pkgwat::F17]).must_equal false
28
- Pkgwat.check_gem("rails", "3.2.7", [Pkgwat::F18]).must_equal false
23
+ Pkgwat.check_gem("rails", "3.1.1", ["Rawhide"]).must_equal false
24
+ Pkgwat.check_gem("rails", "3.0.7", "Fedora 16").must_equal false
25
+ end
26
+
27
+ it "returns distros that have the gem" do
28
+ Pkgwat.check_gem("rails", "3.2.8", ["Fedora 18", "Rawhide"]).must_equal ["Fedora 18"]
29
29
  end
30
30
 
31
- it "returns false for an incomplete match" do
32
- skip "Need to fix this" # TODO: remove this line
33
- Pkgwat.check_gem("rails", "3.2.8", [Pkgwat::F17, Pkgwat::F18]).must_equal false
31
+ it "returns false if the distro doesn't exist" do
32
+ Pkgwat.check_gem("rails", "3.2.8", ["Ubuntu"]).must_equal false
34
33
  end
35
34
  end
36
35
  end
@@ -2,6 +2,7 @@ ENV['RACK_ENV'] = 'test'
2
2
  require 'minitest/autorun'
3
3
  require 'pkgwat'
4
4
  require 'vcr'
5
+ require 'debugger'
5
6
 
6
7
  mode = ENV['mode'] ? ENV['mode'] : :none
7
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pkgwat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: