diff options
author | 2016-01-12 15:57:04 +0100 | |
---|---|---|
committer | 2016-01-12 20:08:53 +0100 | |
commit | fbfaafce172be5fc7d9547ed200e6d22214792a8 (patch) | |
tree | 40605e5f0dbd9f5861f7dee615bc09b6af3056a7 | |
parent | !proj: Distinguish between non-existing and empty projects (diff) | |
download | rbot-gentoo-fbfaafce172be5fc7d9547ed200e6d22214792a8.tar.gz rbot-gentoo-fbfaafce172be5fc7d9547ed200e6d22214792a8.tar.bz2 rbot-gentoo-fbfaafce172be5fc7d9547ed200e6d22214792a8.zip |
!validpkg: Do queries using packages.gentoo.org
-rw-r--r-- | gentoo-data.rb | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/gentoo-data.rb b/gentoo-data.rb index 37b606f..b1d9827 100644 --- a/gentoo-data.rb +++ b/gentoo-data.rb @@ -33,6 +33,7 @@ VALID_PACKAGE_SRC = "/dev/shm/qsearch.txt" GLSA_SRC = "#{ENV['PORTDIR']}/metadata/glsa/glsa-@GLSA_ID@.xml" HERDS_SRC = 'https://api.gentoo.org/packages/herds.xml' PROJECTS_SRC = 'https://api.gentoo.org/metastructure/projects.xml' +PGO_RESOLVE_URI = 'https://packages.gentoo.org/packages/resolve.json?atom=%s' class GentooPlugin < Plugin Config.register Config::StringValue.new('gentoo.scriptdir', @@ -54,7 +55,24 @@ class GentooPlugin < Plugin py = '/usr/bin/python' unless py return py end - + + def pgo_resolve(atom) + uri = PGO_RESOLVE_URI % [URI.escape(atom, '\W+')] + res = @bot.httputil.get(uri) + return JSON.parse(res) + end + + def pgo_resolve_one(m, atom) + pkgs = pgo_resolve(atom)['packages'] + if pkgs.empty? + m.reply "No matching packages for '#{atom}'" + elsif pkgs.length > 1 + m.reply "Ambiguous name '#{atom}'. Possible options: #{pkgs.map{ |x| x['atom'] }.sort.join(' ')}" + else + return pkgs[0] + end + end + def meta(m, params) cp = params[:pkg] cp = validate_package(m, cp) @@ -68,12 +86,12 @@ class GentooPlugin < Plugin m.reply "Cannot find metadata for '#{cp}'" end end - + def validpkg(m, params) - icp = params[:pkg] - cp = validate_package(m, icp) - return if cp.nil? - m.reply "#{icp} => #{cp} is valid" + atom = params[:pkg] + pkg = pgo_resolve_one(m, atom) + return if pkg.nil? + m.reply "#{atom} => #{pkg['atom']} is valid" end def meta_verbose(m, params) |