From 0f22d81f982e02523c852521a5b94db657fe6673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20R=C3=BCckert?= Date: Thu, 24 Jul 2014 17:17:33 +0200 Subject: [PATCH 6/8] Preserve the license header found in the output file --- bin/gem2rpm | 13 +++++++++++-- lib/gem2rpm.rb | 5 ++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/bin/gem2rpm b/bin/gem2rpm index 7f28603..8a6db05 100755 --- a/bin/gem2rpm +++ b/bin/gem2rpm @@ -145,12 +145,21 @@ if config_file end # Produce a specfile +oldlicense = nil if output_file.nil? - Gem2Rpm::convert(gemfile, template, $stdout, nongem, local, doc_subpackage, config) unless deps + Gem2Rpm::convert(gemfile, template, $stdout, nongem, local, doc_subpackage, oldlicense, config) unless deps else begin + if File.exists?(output_file) + File.open(output_file, 'r') do |oldfile| + oldfile.each_line do |line| + m = line.match(%r{^License:\s*(\w.*)$}) + oldlicense = m[1] if m + end + end + end out = open(output_file, "w") - Gem2Rpm::convert(gemfile, template, out, nongem, local, doc_subpackage, config) + Gem2Rpm::convert(gemfile, template, out, nongem, local, doc_subpackage, oldlicense, config) ensure out.close() end diff --git a/lib/gem2rpm.rb b/lib/gem2rpm.rb index 5261ae1..d30e0f6 100644 --- a/lib/gem2rpm.rb +++ b/lib/gem2rpm.rb @@ -31,11 +31,14 @@ module Gem2Rpm end def Gem2Rpm.convert(fname, template=TEMPLATE, out=$stdout, - nongem=true, local=false, doc_subpackage = true, config={}) + nongem=true, local=false, doc_subpackage = true, oldlicense=nil, config={}) package = Gem2Rpm::Package.new(fname) # Deprecate, kept just for backward compatibility. format = Gem2Rpm::Format.new(package) spec = Gem2Rpm::Specification.new(package.spec) + if spec.licenses.empty? && oldlicense + spec.licenses = oldlicense.split(' and ') + end config ||= {} download_path = "" unless local -- 1.8.4.5