Module: Pkgwat
- Defined in:
- lib/pkgwat.rb,
lib/pkgwat/railtie.rb,
lib/pkgwat/version.rb
Defined Under Namespace
Classes: Railtie
Constant Summary collapse
- PACKAGE_NAME =
"rubygem-:gem"
- PACKAGES_URL =
"https://apps.fedoraproject.org/packages/fcomm_connector/bodhi/query/query_active_releases"
- PACKAGES_URL_LIST =
"https://apps.fedoraproject.org/packages/fcomm_connector/xapian/query/search_packages"
- BUGS_URL =
"https://apps.fedoraproject.org/packages/fcomm_connector/bugzilla/query/query_bugs"
- BUILDS_URL =
"https://apps.fedoraproject.org/packages/fcomm_connector/koji/query/query_builds"
- CHANGELOG_URL =
"https://apps.fedoraproject.org/packages/fcomm_connector/koji/query/query_changelogs"
- CONTENT_URL =
"https://apps.fedoraproject.org/packages/fcomm_connector/yum/get_file_tree"
- UPDATES_URL =
"https://apps.fedoraproject.org/packages/fcomm_connector/bodhi/query/query_updates"
- KOJI_BUILD_STATES =
["all" => "", "f19" =>"19", "f18" => "18", "f20" => "20", "e16" => "16", "e15" => "15"]
- BUGZILLA_RELEASE =
["all" => "", "building" =>"0", "success" => "1", "failed" => "2", "cancelled" => "3", "deleted" => "4"]
- BODHI_RELEASE =
["all", "f19", "f18", "f20", "e16", "e15"]
- BODHI_ARCH =
["x86_64", "i686"]
- VERSION =
"0.2.0"
Class Attribute Summary collapse
-
.debug ⇒ Object
Returns the value of attribute debug.
Class Method Summary collapse
- .check_gem(name, version, distros, throw_ex = false) ⇒ Object
- .compare_versions(version1, version2) ⇒ Object
-
.get_bugs(pattern, version = 'all', num = nil, start = 0) ⇒ Object
this function queries for and returns a list of then open BUGS.
-
.get_builds(pattern, state = 'all', num = nil, start = 0) ⇒ Object
this function queries for and returns a list of the BUILDS.
- .get_changelog(pattern, num = nil, start = 0) ⇒ Object
- .get_contents(pattern, arch = 'x86_64', release = 'Rawhide') ⇒ Object
-
.get_package(pattern) ⇒ Object
this function just queries for and returns a single package.
-
.get_packages(pattern, start = 0, num = nil) ⇒ Object
this function queries and returns the specified number of packages starting at the specified row.
- .get_releases(pattern, num = nil, start = 0) ⇒ Object
- .get_updates(pattern, status, release, num = nil, start = 0) ⇒ Object
- .get_versions(gem_name) ⇒ Object
- .package_name(gem) ⇒ Object
- .parse_results(results) ⇒ Object
- .search_params(gem) ⇒ Object
- .search_url(gem) ⇒ Object
- .submit_request(uri) ⇒ Object
Class Attribute Details
.debug ⇒ Object
Returns the value of attribute debug.
23 24 25 |
# File 'lib/pkgwat.rb', line 23 def debug @debug end |
Class Method Details
.check_gem(name, version, distros, throw_ex = false) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pkgwat.rb', line 26 def self.check_gem(name, version, distros, throw_ex = false) versions = get_versions(name) distros = Array(distros) # convert distros to an array if not already matches = distros.each_with_object([]) do |distro, results| distro_match = versions.detect { |v| v["release"] == distro } if distro_match distro_version = distro_match["stable_version"][/\A(\S+)-.*\z/, 1] # get the actual gem version match = compare_versions(version, distro_version) results << distro_match["release"] if match end end matches.any? ? matches : false end |
.compare_versions(version1, version2) ⇒ Object
42 43 44 45 |
# File 'lib/pkgwat.rb', line 42 def self.compare_versions(version1, version2) return false if version1.nil? || version1.to_s.length < 1 || version2.nil? || version2.to_s.length < 1 Gem::Version.new(version1) == Gem::Version.new(version2) end |
.get_bugs(pattern, version = 'all', num = nil, start = 0) ⇒ Object
this function queries for and returns a list of then open BUGS
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/pkgwat.rb', line 76 def self.get_bugs(pattern, version='all', num=nil, start =0) if BUGZILLA_RELEASE[0][version].nil? version = BUGZILLA_RELEASE[0]['all'] else version = BUGZILLA_RELEASE[0][version] end num ||= total_rows(pattern, "bugs", BUGS_URL) query = {"filters"=> {"package"=> pattern, "version"=> version}, "rows_per_page"=> num, "start_row"=> start} url = BUGS_URL + "/" + query.to_json uri = URI.parse(URI.escape(url)) response = submit_request(uri) parse_results(response.body) end |
.get_builds(pattern, state = 'all', num = nil, start = 0) ⇒ Object
this function queries for and returns a list of the BUILDS
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/pkgwat.rb', line 92 def self.get_builds(pattern, state='all', num=nil, start =0) if KOJI_BUILD_STATES[0][state].nil? state = KOJI_BUILD_STATES[0]['all'] else state = KOJI_BUILD_STATES[0][state] end num ||= total_rows(pattern, "builds", BUILDS_URL) query = {"rows_per_page"=> num, "start_row"=> start, "filters"=> {"state"=> state, "package"=> pattern}} url = BUILDS_URL + "/" + query.to_json uri = URI.parse(URI.escape(url)) response = submit_request(uri) parse_results(response.body) end |
.get_changelog(pattern, num = nil, start = 0) ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/pkgwat.rb', line 106 def self.get_changelog(pattern, num=nil, start=0) num ||= total_rows(pattern, "builds", BUILDS_URL) build_id = get_builds(pattern)[0]['build_id'] query = {"filters"=> {"build_id"=> build_id}, "rows_per_page"=> num, "start_row"=> start} url = CHANGELOG_URL + "/" + query.to_json uri = URI.parse(URI.escape(url)) response = submit_request(uri) parse_results(response.body) end |
.get_contents(pattern, arch = 'x86_64', release = 'Rawhide') ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/pkgwat.rb', line 116 def self.get_contents(pattern, arch='x86_64', release='Rawhide') if !BODHI_ARCH.include? arch return "Invalid yum arch." end if !BODHI_RELEASE.include? release return "Invalid bodhi release." end url = CONTENT_URL + "?package=#{pattern}&arch=#{arch}&repo=#{release}" uri = URI.parse(URI.escape(url)) response = submit_request(uri) JSON.parse(response.body) end |
.get_package(pattern) ⇒ Object
this function just queries for and returns a single package
71 72 73 |
# File 'lib/pkgwat.rb', line 71 def self.get_package(pattern) get_packages(pattern, 0, 1).first end |
.get_packages(pattern, start = 0, num = nil) ⇒ Object
this function queries and returns the specified number of packages starting at the specified row
60 61 62 63 64 65 66 67 68 |
# File 'lib/pkgwat.rb', line 60 def self.get_packages(pattern, start=0, num=nil) num ||= total_rows(pattern, "packages", PACKAGES_URL_LIST) query = {"filters"=>{"search"=>pattern}, "rows_per_page"=>num, "start_row"=>start} url = PACKAGES_URL_LIST + "/" + query.to_json uri = URI.parse(URI.escape(url)) response = submit_request(uri) clean_response = Sanitize.clean(response.body) parse_results(clean_response) end |
.get_releases(pattern, num = nil, start = 0) ⇒ Object
129 130 131 132 133 134 135 136 |
# File 'lib/pkgwat.rb', line 129 def self.get_releases(pattern, num=nil, start=0) num ||= total_rows(pattern, "releases", PACKAGES_URL) query = {"filters"=> {"package"=> pattern}, "rows_per_page"=> num, "start_row"=> start} url = PACKAGES_URL + "/" + query.to_json uri = URI.parse(URI.escape(url)) response = submit_request(uri) parse_results(response.body) end |
.get_updates(pattern, status, release, num = nil, start = 0) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/pkgwat.rb', line 138 def self.get_updates(pattern, status, release, num=nil, start=0) num ||= total_rows(pattern, "updates", UPDATES_URL) if !BODHI_RELEASE.include? status return "Invalid bodhi state." end if !BODHI_RELEASE.include? release return "Invalid bodhi release." end if status == "all" status = "" end if release == "all" release = "" end query = {"rows_per_page"=> num, "start_row"=> start, "filters"=> {"package"=> pattern, "release" => release, "state"=> status}} url = PACKAGES_URL + "/" + query.to_json uri = URI.parse(URI.escape(url)) response = submit_request(uri) parse_results(response.body) end |
.get_versions(gem_name) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/pkgwat.rb', line 47 def self.get_versions(gem_name) uri = search_url(gem_name) response = submit_request(uri) raise "Could not connect to packages API (#{response.inspect})" unless response.code == "200" parse_results(response.body) end |
.package_name(gem) ⇒ Object
54 55 56 |
# File 'lib/pkgwat.rb', line 54 def self.package_name(gem) PACKAGE_NAME.gsub(":gem", gem) end |
.parse_results(results) ⇒ Object
178 179 180 181 |
# File 'lib/pkgwat.rb', line 178 def self.parse_results(results) results = JSON.parse(results) results["rows"] end |
.search_params(gem) ⇒ Object
159 160 161 162 |
# File 'lib/pkgwat.rb', line 159 def self.search_params(gem) filters = { :package => package_name(gem) } { :filters => filters } end |
.search_url(gem) ⇒ Object
164 165 166 167 168 |
# File 'lib/pkgwat.rb', line 164 def self.search_url(gem) query = search_params(gem) url = PACKAGES_URL + "/" + query.to_json URI.parse(URI.escape(url)) end |
.submit_request(uri) ⇒ Object
170 171 172 173 174 175 176 |
# File 'lib/pkgwat.rb', line 170 def self.submit_request(uri) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE #TODO: verify request = Net::HTTP::Get.new(uri.request_uri) http.request(request) end |