Skip to content
This repository has been archived by the owner on Jun 23, 2020. It is now read-only.

Commit

Permalink
Relax polisher deps, gracefully fail if missing (rev 4)
Browse files Browse the repository at this point in the history
Now polisher gem contains minimal runtime deps w/ mechanism
to catch runtime load errors. Components missing reqs will
not be accessible / calling methods on them will indicate
to install optional dependencies

Rebased against latest master
  • Loading branch information
movitto committed May 5, 2014
1 parent 50bcb3d commit accf071
Show file tree
Hide file tree
Showing 13 changed files with 1,435 additions and 1,410 deletions.
3 changes: 0 additions & 3 deletions bin/git_gem_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
# Copyright (C) 2013-2014 Red Hat, Inc.

require 'colored'
require 'curb'
require 'json'
require 'optparse'
require 'nokogiri'

require 'polisher/git'
require 'polisher/gem'
Expand Down
30 changes: 30 additions & 0 deletions lib/polisher/component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Polisher Components & Component Helpers
#
# Licensed under the MIT license
# Copyright (C) 2014 Red Hat, Inc.

require 'active_support/core_ext'

module Polisher
module Component
class Missing
def initialize(*args)
raise "polisher is missing a dependency - cannot instantiate"
end

def method_missing(method_id, *args, &bl)
raise "polisher is missing a dependency - cannot invoke #{method_id} on #{self}"
end
end # class MissingComponent

def self.verify(polisher_klass, *dependencies)
dependencies.each { |dep| require dep }
rescue LoadError
klass = polisher_klass.demodulize
polisher_module = "Polisher::#{polisher_klass.deconstantize}"
polisher_module.constantize.const_set(klass, Missing)
else
yield
end
end # module Component
end # module Polisher
112 changes: 56 additions & 56 deletions lib/polisher/errata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,73 +3,73 @@
# Licensed under the MIT license
# Copyright (C) 2013-2014 Red Hat, Inc.

require 'json'
require 'curb'

require 'polisher/core'
require 'polisher/component'

module Polisher
class Errata
extend ConfHelpers
Component.verify("Errata", 'json', 'curb') do
class Errata
extend ConfHelpers

conf_attr :advisory_url, ''
conf_attr :package_prefix, 'rubygem-'

conf_attr :advisory_url, ''
conf_attr :package_prefix, 'rubygem-'
# Initialize/return singleton curl handle to query errata
def self.client
@curl ||= begin
curl = Curl::Easy.new
curl.ssl_verify_peer = false
curl.ssl_verify_host = false
curl.http_auth_types = :negotiate
curl.userpwd = ':'
curl
end
end

# Initialize/return singleton curl handle to query errata
def self.client
@curl ||= begin
curl = Curl::Easy.new
curl.ssl_verify_peer = false
curl.ssl_verify_host = false
curl.http_auth_types = :negotiate
curl.userpwd = ':'
curl
def self.clear!
@cached_url = nil
@cached_builds = nil
self
end
end

def self.clear!
@cached_url = nil
@cached_builds = nil
self
end
def self.builds
@cached_url ||= advisory_url
@cached_builds ||= nil

def self.builds
@cached_url ||= advisory_url
@cached_builds ||= nil
if @cached_url != advisory_url || @cached_builds.nil?
client.url = "#{advisory_url}/builds"
@cached_builds = client.get
@cached_builds = JSON.parse(client.body_str)
end

if @cached_url != advisory_url || @cached_builds.nil?
client.url = "#{advisory_url}/builds"
@cached_builds = client.get
@cached_builds = JSON.parse(client.body_str)
@cached_builds
end

@cached_builds
end

def self.versions_for(name, &bl)
versions = builds.collect do |tag, builds|
ErrataBuild.builds_matching(builds, name)
end.flatten
bl.call(:errata, name, versions) unless(bl.nil?)
versions
end
end
def self.versions_for(name, &bl)
versions = builds.collect do |tag, builds|
ErrataBuild.builds_matching(builds, name)
end.flatten
bl.call(:errata, name, versions) unless(bl.nil?)
versions
end
end # class Errata

class ErrataBuild
def self.builds_matching(builds, name)
builds.collect { |build|
self.build_matches?(build, name) ? self.build_version(build, name) : nil
}.compact
end
class ErrataBuild
def self.builds_matching(builds, name)
builds.collect { |build|
self.build_matches?(build, name) ? self.build_version(build, name) : nil
}.compact
end

def self.build_matches?(build, name)
pkg,meta = *build.flatten
pkg =~ /^#{Errata.package_prefix}#{name}-([^-]*)-.*$/
end
def self.build_matches?(build, name)
pkg,meta = *build.flatten
pkg =~ /^#{Errata.package_prefix}#{name}-([^-]*)-.*$/
end

def self.build_version(build, name)
pkg,meta = *build.flatten
pkg.gsub(Errata.package_prefix, '').split('-')[1]
end
end
end
def self.build_version(build, name)
pkg,meta = *build.flatten
pkg.gsub(Errata.package_prefix, '').split('-')[1]
end
end # class ErrataBuild
end # Component.verify(Errata)
end # module Polisher
66 changes: 33 additions & 33 deletions lib/polisher/fedora.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,44 @@
# Licensed under the MIT license
# Copyright (C) 2013-2014 Red Hat, Inc.

require 'curb'
require 'pkgwat'

require 'polisher/bodhi'
require 'polisher/component'

module Polisher
class Fedora
PACKAGE_LIST = 'https://admin.fedoraproject.org/pkgdb/users/packages/'
Component.verify("Fedora", "curb", "pkgwat", "nokogiri") do
class Fedora
PACKAGE_LIST = 'https://admin.fedoraproject.org/pkgdb/users/packages/'

def self.client
@client ||= Curl::Easy.new
end
def self.client
@client ||= Curl::Easy.new
end

# Retrieve list of gems owned by the specified user
#
# @param [String] user Fedora username to lookup
# @return [Array<String>] list of gems which the user owns/has access to
def self.gems_owned_by(user)
client.url = "#{PACKAGE_LIST}#{user}"
client.http_get
packages = client.body_str
# TODO instantiate Polisher::Gem instances & return
Nokogiri::HTML(packages).xpath("//a[@class='PackageName']").
select { |i| i.text =~ /rubygem-.*/ }.
collect { |i| i.text.gsub(/rubygem-/, '') }
end
# Retrieve list of gems owned by the specified user
#
# @param [String] user Fedora username to lookup
# @return [Array<String>] list of gems which the user owns/has access to
def self.gems_owned_by(user)
client.url = "#{PACKAGE_LIST}#{user}"
client.http_get
packages = client.body_str
# TODO instantiate Polisher::Gem instances & return
Nokogiri::HTML(packages).xpath("//a[@class='PackageName']").
select { |i| i.text =~ /rubygem-.*/ }.
collect { |i| i.text.gsub(/rubygem-/, '') }
end

# Retrieve list of the versions of the specified package in the various
# Fedora releases.
#
# @param [String] name name of the package to lookup
# @param [Callable] bl optional callback to invoke with versions retrieved
# @return [Array<String>] list of versions in Fedora
def self.versions_for(name, &bl)
# simply dispatch to bodhi to get latest updates
Polisher::Bodhi.versions_for name do |target,name,versions|
bl.call(:fedora, name, versions) unless(bl.nil?)
# Retrieve list of the versions of the specified package in the various
# Fedora releases.
#
# @param [String] name name of the package to lookup
# @param [Callable] bl optional callback to invoke with versions retrieved
# @return [Array<String>] list of versions in Fedora
def self.versions_for(name, &bl)
# simply dispatch to bodhi to get latest updates
Polisher::Bodhi.versions_for name do |target,name,versions|
bl.call(:fedora, name, versions) unless(bl.nil?)
end
end
end
end # class Fedora
end # class Fedora
end # Component.verify("Fedora")
end # module Polisher

0 comments on commit accf071

Please sign in to comment.