pkg-query 0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c01830d857930ee7bff7cae573d0d6dd3722fec50c79e3366a8b70590a48298d
4
+ data.tar.gz: fb1cb586648e7c4f50271656f613db94ff484f7873186b0d6b074fe9b9dbdce2
5
+ SHA512:
6
+ metadata.gz: e9a5716dfd1e1aaeaaa43d813792415b6dcacef0221c02d3f20fc8fd4e7db57842da44b5cc600eb3c76f4a82c99ca1829bdd997e295e1057e6d5a1363c257e3f
7
+ data.tar.gz: ed1ec394ebc145f1535d595bac503ffb078bd50f967613b220563a96de8f5a635d8d5b4516efab6b7c47278d5d34309493c976a6c039b596f6a49d6b989c4469
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'nokogiri'
4
+ gem 'watir'
5
+
6
+ group :development do
7
+ gem 'rubocop'
8
+ gem 'ruby-debug-ide'
9
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,46 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ ast (2.4.0)
5
+ childprocess (1.0.1)
6
+ rake (< 13.0)
7
+ jaro_winkler (1.5.3)
8
+ mini_portile2 (2.4.0)
9
+ nokogiri (1.10.3)
10
+ mini_portile2 (~> 2.4.0)
11
+ parallel (1.17.0)
12
+ parser (2.6.3.0)
13
+ ast (~> 2.4.0)
14
+ rainbow (3.0.0)
15
+ rake (12.3.2)
16
+ regexp_parser (1.5.1)
17
+ rubocop (0.73.0)
18
+ jaro_winkler (~> 1.5.1)
19
+ parallel (~> 1.10)
20
+ parser (>= 2.6)
21
+ rainbow (>= 2.2.2, < 4.0)
22
+ ruby-progressbar (~> 1.7)
23
+ unicode-display_width (>= 1.4.0, < 1.7)
24
+ ruby-debug-ide (0.7.0)
25
+ rake (>= 0.8.1)
26
+ ruby-progressbar (1.10.1)
27
+ rubyzip (1.2.3)
28
+ selenium-webdriver (3.142.3)
29
+ childprocess (>= 0.5, < 2.0)
30
+ rubyzip (~> 1.2, >= 1.2.2)
31
+ unicode-display_width (1.6.0)
32
+ watir (6.16.5)
33
+ regexp_parser (~> 1.2)
34
+ selenium-webdriver (~> 3.6)
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ nokogiri
41
+ rubocop
42
+ ruby-debug-ide
43
+ watir
44
+
45
+ BUNDLED WITH
46
+ 2.0.2
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2019 Alejandro Blanco López
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # pkg-query
2
+
3
+ pkg-query is a simple web scraping tool that allows you to compare the version of a package across some Linux distributions.
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ $ pkg-query package
9
+ ```
data/bin/pkg-query ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pkg-query'
4
+
5
+ package = ARGV[0]
6
+ raise 'Specify a package' unless package
7
+
8
+ distros = ['arch', 'debian', 'ubuntu']
9
+ debian_releases = ['stable', 'testing', 'sid']
10
+ fedora_releases = ['Fedora 29', 'Fedora 30', 'Rawhide']
11
+ ubuntu_releases = ['bionic', 'cosmic', 'disco', 'eoan']
12
+
13
+ include PkgQuery
14
+ puts package
15
+ puts "Arch: #{arch(package)}"
16
+ debian_releases.each { |release| puts "Debian #{release}: #{debian(release, package)}" }
17
+ fedora_releases.each { |release| puts "Fedora #{release}: #{fedora(release, package)}" }
18
+ ubuntu_releases.each { |release| puts "Ubuntu #{release}: #{ubuntu(release, package)}" }
data/lib/pkg-query.rb ADDED
@@ -0,0 +1,56 @@
1
+
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+ require 'watir' # requires chrome-driver
5
+
6
+ module PkgQuery
7
+ VERSION = '0.3'
8
+
9
+ def arch(package)
10
+ base_url = 'https://www.archlinux.org/packages'
11
+ repos = ['core', 'community', 'extra']
12
+ archs = ['x86_64', 'any']
13
+ repos.product(archs).each do |repo|
14
+ url = [base_url, repo, package].join('/')
15
+ begin
16
+ doc = Nokogiri::HTML(open(url))
17
+ return doc.xpath('/html/body/div[2]/div[2]/h2').inner_text.split[1]
18
+ rescue OpenURI::HTTPError
19
+ next # pkg is not in this repo, next
20
+ end
21
+ end.empty?
22
+ nil
23
+ end
24
+
25
+ def debian(release, package)
26
+ base_url = 'https://packages.debian.org'
27
+ url = [base_url, release, package].join('/')
28
+ doc = Nokogiri::HTML(open(url))
29
+ doc.xpath('/html/body/div[2]/h1').inner_text[/\((.*)\)/, 1]
30
+ end
31
+
32
+ def fedora(release, package, timeout=1)
33
+ base_url = 'https://apps.fedoraproject.org/packages'
34
+ url = [base_url, package].join('/')
35
+ browser = Watir::Browser.new :chrome, headless: true
36
+ browser.goto url
37
+ begin
38
+ Watir::Wait.until(timeout: timeout) {browser.execute_script('return jQuery.active') == 0}
39
+ rescue; end
40
+ doc = Nokogiri::HTML(browser.html)
41
+ doc.xpath('/html/body/div/div/div[2]/div/div[2]/div/div[2]/div[1]/div/div[2]/div/div/table/tbody/tr').each do |tbody|
42
+ return tbody.xpath('td[2]/a[1]').inner_text if tbody.xpath('td[1]/div').inner_text.chop == release
43
+ end
44
+ end
45
+
46
+ def ubuntu(release, package)
47
+ base_url = 'https://packages.ubuntu.com'
48
+ url = [base_url, release, package].join('/')
49
+ begin
50
+ doc = Nokogiri::HTML(open(url))
51
+ rescue
52
+ retry
53
+ end
54
+ doc.xpath('/html/body/div[1]/div[3]/h1').inner_text[/\((.*)\)/, 1]
55
+ end
56
+ end
data/pkg-query.gemspec ADDED
@@ -0,0 +1,21 @@
1
+
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'pkg-query'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'pkg-query'
9
+ spec.version = PkgQuery::VERSION
10
+ spec.authors = ['Alejandro Blanco López']
11
+ spec.email = ['alexbl1996@gmail.com']
12
+ spec.summary = 'A gem to compare packages versions.'
13
+ spec.description = 'A gem to query packages versions in several GNU/Linux distributions.'
14
+ spec.homepage = "https://github.com/blalop/pkg-query"
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ['lib']
21
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pkg-query
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.3'
5
+ platform: ruby
6
+ authors:
7
+ - Alejandro Blanco López
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A gem to query packages versions in several GNU/Linux distributions.
14
+ email:
15
+ - alexbl1996@gmail.com
16
+ executables:
17
+ - pkg-query
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - Gemfile
22
+ - Gemfile.lock
23
+ - LICENSE
24
+ - README.md
25
+ - bin/pkg-query
26
+ - lib/pkg-query.rb
27
+ - pkg-query.gemspec
28
+ homepage: https://github.com/blalop/pkg-query
29
+ licenses:
30
+ - MIT
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project:
48
+ rubygems_version: 2.7.6.2
49
+ signing_key:
50
+ specification_version: 4
51
+ summary: A gem to compare packages versions.
52
+ test_files: []