diff options
author | 2016-01-12 16:24:39 +0100 | |
---|---|---|
committer | 2016-01-12 20:08:53 +0100 | |
commit | b25e26fd9f0dc496f5a10eeaf7f921b84e2cd873 (patch) | |
tree | 2b00adad02e46151b97173474721408acb6157d4 | |
parent | !validpkg: Do queries using packages.gentoo.org (diff) | |
download | rbot-gentoo-b25e26fd9f0dc496f5a10eeaf7f921b84e2cd873.tar.gz rbot-gentoo-b25e26fd9f0dc496f5a10eeaf7f921b84e2cd873.tar.bz2 rbot-gentoo-b25e26fd9f0dc496f5a10eeaf7f921b84e2cd873.zip |
!meta: Do queries using packages.gentoo.org
-rw-r--r-- | gentoo-data.rb | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/gentoo-data.rb b/gentoo-data.rb index b1d9827..1a165c1 100644 --- a/gentoo-data.rb +++ b/gentoo-data.rb @@ -34,6 +34,7 @@ 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' +PGO_DATA_URI = 'https://packages.gentoo.org/packages/%s.json' class GentooPlugin < Plugin Config.register Config::StringValue.new('gentoo.scriptdir', @@ -73,18 +74,31 @@ class GentooPlugin < Plugin end end + def pgo_get(m, atom) + pkg = pgo_resolve_one(m, atom) + return if pkg.nil? + + uri = PGO_DATA_URI % [pkg['atom']] + res = @bot.httputil.get(uri) + return JSON.parse(res) + end + + def meta_print(m, pkg) + # TODO: handle description? + maints = pkg['maintainers'].map{|x| x['email'].chomp('@gentoo.org')}.join(', ') + maints = '(none)' if maints.empty? + herds = pkg['herds'].join(', ') + herds = '(none)' if herds.empty? + + m.reply "#{pkg['atom']}; herds: #{herds}; maintainers: #{maints}" + end + def meta(m, params) - cp = params[:pkg] - cp = validate_package(m, cp) - return if cp.nil? - f = IO.popen("#{python} #{scriptdir}/metadata.py '#{cp}'") - r = f.readlines - f.close - if r.length > 0 - m.reply "#{r}" - else - m.reply "Cannot find metadata for '#{cp}'" - end + atom = params[:pkg] + pkg = pgo_get(m, atom) + return if pkg.nil? + + meta_print(m, pkg) end def validpkg(m, params) @@ -95,18 +109,12 @@ class GentooPlugin < Plugin end def meta_verbose(m, params) - cp = params[:pkg] - cp = validate_package(m, cp) - return if cp.nil? - f = IO.popen("#{python} #{scriptdir}/metadata.py '#{cp}'") - output = f.readlines - f.close - m.reply "#{output}" - herds = [] - output[0].gsub!(/(Maintainer:|Description:).*/,'') - mre = /Herd: +([-[:alnum:], ]+) .*/.match(output[0]) - herds = mre[1].strip.split(/[, ]+/).map { |s| s.strip }.flatten if mre and mre[1] - herds.each { |h| + atom = params[:pkg] + pkg = pgo_get(m, atom) + return if pkg.nil? + + meta_print(m, pkg) + pkg['herds'].each { |h| debug("meta -v calling herd for #{h}") p = params.clone p[:herd] = h |