Skip to content

Instantly share code, notes, and snippets.

@movitto movitto/fgc.rb
Created Jun 5, 2013

Embed
What would you like to do?
Fedora Gemfile Checker - Compare a Bundler Gemfile to the Fedora Ruby Stack
#!/usr/bin/ruby
# Fedora Gemfile Checker
# Print out Gemfile dependencies, highlighting
# missing dependencies and those that are remotely
# available in Fedora.
#
# Licensed under the MIT license
# Copyright (C) 2013 Red Hat, Inc.
# Written By Mo Morsi <mmorsi@redhat.com>
###########################################################
require 'optparse'
require 'colored'
require 'pkgwat'
require 'gemnasium/parser'
##########################################################
conf = { :gemfile => './Gemfile',
:command => nil,
:highlight_missing => false,
:highlight_available => false }
optparse = OptionParser.new do |opts|
opts.on('-h', '--help', 'Display this help screen') do
puts opts
exit
end
opts.on('-g', '--gemfile file', 'Location of the gemfile to parse') do |g|
conf[:gemfile] = g
end
opts.on('-c', '--command command', 'Command to run') do |c|
conf[:command] = c
end
opts.on('-m', '--[no-]missing', 'Highlight missing packages') do |m|
conf[:highlight_missing] = m
end
opts.on('-a', '--[no-]available', 'Highlight missing but avaiable packages') do |a|
conf[:highlight_available] = a
end
end
optparse.parse!
conf[:gemfile] = './Gemfile' if conf[:gemfile].nil? && File.exists?('./Gemfile')
##########################################################
local = Gem::Specification.all
parser = Gemnasium::Parser.gemfile(File.read(conf[:gemfile]))
parser.dependencies.each { |d|
name = d.name
req = d.requirement
version = req.to_s.split.last # TODO match version better
if conf[:command]
cmd = conf[:command].gsub(/NAME/, name).gsub(/VERSION/, version)
puts cmd
else
out = "#{name} #{req}"
has = !local.find { |s| s.name == name && s.version.to_s == version }.nil? if conf[:highlight_missing]
avail = Pkgwat.get_package("rubygem-#{name}") if !has && conf[:highlight_available] # TODO set timeout
if has
puts out.green
elsif avail
puts out.yellow
elsif conf[:highlight_missing]
puts out.red
else
puts out
end
end
}
##########################################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.