Module: PkgQuery
- Defined in:
- lib/pkg-query.rb
Constant Summary collapse
- VERSION =
'0.3'
Instance Method Summary collapse
- #arch(package) ⇒ Object
- #debian(release, package) ⇒ Object
- #fedora(release, package, timeout = 1) ⇒ Object
- #ubuntu(release, package) ⇒ Object
Instance Method Details
#arch(package) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/pkg-query.rb', line 9 def arch(package) base_url = 'https://www.archlinux.org/packages' repos = ['core', 'community', 'extra'] archs = ['x86_64', 'any'] repos.product(archs).each do |repo| url = [base_url, repo, package].join('/') begin doc = Nokogiri::HTML(open(url)) return doc.xpath('/html/body/div[2]/div[2]/h2').inner_text.split[1] rescue OpenURI::HTTPError next # pkg is not in this repo, next end end.empty? nil end |
#debian(release, package) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/pkg-query.rb', line 25 def debian(release, package) base_url = 'https://packages.debian.org' url = [base_url, release, package].join('/') doc = Nokogiri::HTML(open(url)) doc.xpath('/html/body/div[2]/h1').inner_text[/\((.*)\)/, 1] end |
#fedora(release, package, timeout = 1) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/pkg-query.rb', line 32 def fedora(release, package, timeout=1) base_url = 'https://apps.fedoraproject.org/packages' url = [base_url, package].join('/') browser = Watir::Browser.new :chrome, headless: true browser.goto url begin Watir::Wait.until(timeout: timeout) {browser.execute_script('return jQuery.active') == 0} rescue; end doc = Nokogiri::HTML(browser.html) 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| return tbody.xpath('td[2]/a[1]').inner_text if tbody.xpath('td[1]/div').inner_text.chop == release end end |
#ubuntu(release, package) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/pkg-query.rb', line 46 def ubuntu(release, package) base_url = 'https://packages.ubuntu.com' url = [base_url, release, package].join('/') begin doc = Nokogiri::HTML(open(url)) rescue retry end doc.xpath('/html/body/div[1]/div[3]/h1').inner_text[/\((.*)\)/, 1] end |