bin/gem2rpm in gem2rpm-0.11.2 vs bin/gem2rpm in gem2rpm-0.11.3

- old
+ new

@@ -1,153 +1,74 @@ #!/usr/bin/env ruby # -*- ruby -*- -$:.push(File.expand_path(File.dirname(__FILE__) + "/../lib")) +$LOAD_PATH.push(File.expand_path(File.dirname(__FILE__) + "/../lib")) require 'gem2rpm' require 'optparse' require 'fileutils' require 'open-uri' require 'uri' -opts = OptionParser.new("Usage: #{$0} [OPTIONS] GEM") -opts.separator(" Convert Ruby gems to source RPMs and specfiles.") -opts.separator(" Uses a template to generate the RPM specfile") -opts.separator(" from the gem specification.") +options = Gem2Rpm::Configuration.instance.options +rest = options[:args] -print_template_file = nil -template_file = nil -output_file = nil -local = false -srpm = false -deps = false -nongem = false -doc_subpackage = true -fetch = false - -opts.separator("") -opts.separator(" Options:") -opts.on("-T", "--current-template", "Print the current template") do |val| - print_template_file = true -end -opts.on("-t", "--template TEMPLATE", "Use TEMPLATE for the specfile") do |val| - template_file = val -end -opts.on("--templates", "List all available templates") do - puts "Available templates in #{Gem2Rpm::Template.default_location}:\n\n" - puts Gem2Rpm::Template.list.map{ - |t| t.gsub(/(.*)\.spec.erb/, '\\1') - }.join("\n") - exit 0 -end -opts.on("-v", "--version", "Print gem2rpm's version and exit") do - puts Gem2Rpm::VERSION - exit 0 -end -opts.on("-o", "--output FILE", "Send the specfile to FILE") do |val| - output_file = val -end -opts.on("-s", "--srpm", "Create a source RPM") do |val| - srpm = true -end -opts.on("-l", "--local", "Do not retrieve Gem information over -#{' '*36} the network. Use on disconnected machines") do |val| - local = true -end -opts.on("-d", "--dependencies", "Print the dependencies of the gem") do |val| - deps = true -end -opts.on("-n", "--nongem", "Generate a subpackage for non-gem use") do |val| - nongem = true -end -opts.on("--no-doc", "Disable document subpackage") do |val| - doc_subpackage = false -end -opts.on("--fetch", "Fetch the gem from rubygems.org") do |val| - fetch = true -end -opts.separator("") -opts.separator(" Arguments:") -opts.separator(" GEM The path to the locally stored gem package file or the name") -opts.separator(" of the gem when using --fetch.") -opts.separator("") - -begin - rest = opts.permute(ARGV) -rescue OptionParser::InvalidOption => e - $stderr.puts "#{e}\n\n" - $stderr.puts opts - exit(1) -end - template = begin - Gem2Rpm::Template.find template_file, :gem_file => rest[0] + Gem2Rpm::Template.find options[:template_file], :gem_file => rest[0] rescue Gem2Rpm::Template::TemplateError => e $stderr.puts e exit(1) end -if print_template_file +if options[:print_template_file] puts template.read exit 0 end if rest.size != 1 - $stderr.puts "Missing GEMFILE\n\n" - $stderr.puts opts - exit(1) + $stderr.puts "Missing GEMFILE\n\n" + $stderr.puts opts + exit(1) end gemfile = rest[0] -if fetch +if options[:fetch] gem_uri = '' - open("http://rubygems.org/api/v1/gems/#{gemfile}.json") do |f| + open("https://rubygems.org/api/v1/gems/#{gemfile}.json") do |f| gem_uri = f.read.match(/"gem_uri":\s*"(.*?)",/m)[1] gemfile = URI.parse(gem_uri).path.split('/').last open(gemfile, 'w') do |gf| gf.write(open(gem_uri).read) end end end srpmdir = nil -gemname = nil -srpmdir = nil specfile = nil -if srpm - gemname = Gem2Rpm::Package.new(gemfile).spec.name - srpmdir = `/bin/mktemp -t -d gem2rpm-#{gemname}.XXXXXX`.chomp - specfile = File::join(srpmdir, "rubygem-#{gemname}.spec") - if output_file.nil? - output_file = specfile - end +if options[:srpm] + gemname = Gem2Rpm::Package.new(gemfile).spec.name + srpmdir = `/bin/mktemp -t -d gem2rpm-#{gemname}.XXXXXX`.chomp + specfile = File.join(srpmdir, "rubygem-#{gemname}.spec") + options[:output_file] ||= specfile end # Produce a specfile -if output_file.nil? - Gem2Rpm::convert(gemfile, template, $stdout, nongem, local, doc_subpackage) unless deps +if options[:output_file].nil? + Gem2Rpm.convert(gemfile, template, $stdout, options[:nongem], options[:local], options[:doc_subpackage]) unless options[:deps] else - begin - out = open(output_file, "w") - Gem2Rpm::convert(gemfile, template, out, nongem, local, doc_subpackage) - ensure - out.close() - end + begin + out = open(options[:output_file], "w") + Gem2Rpm.convert(gemfile, template, out, options[:nongem], options[:local], options[:doc_subpackage]) + ensure + out.close + end end # Create a source RPM -if srpm - unless File::exist?(specfile) - FileUtils::copy(output_file, specfile) - end - FileUtils::copy(gemfile, srpmdir) +if options[:srpm] + FileUtils.copy(options[:output_file], specfile) unless File.exist?(specfile) + FileUtils.copy(gemfile, srpmdir) - system("rpmbuild -bs --nodeps --define '_sourcedir #{srpmdir}' --define '_srcrpmdir #{Dir::pwd}' #{specfile}") + system("rpmbuild -bs --nodeps --define '_sourcedir #{srpmdir}' --define '_srcrpmdir #{Dir.pwd}' #{specfile}") end -if deps - Gem2Rpm::Package.new(gemfile).spec.dependencies.each do |dep| - Gem2Rpm::Dependency.new(dep).requirement.each do |r| - puts "rubygem(#{dep.name}) #{r}" - end - end -end +Gem2Rpm.print_dependencies(gemfile) if options[:deps]