diff --git a/bin/gem2rpm b/bin/gem2rpm index 3b07dbd..c63532c 100755 --- a/bin/gem2rpm +++ b/bin/gem2rpm @@ -27,14 +27,9 @@ end rest = options[:args] template = nil -if template_file.nil? - f = open('/etc/os-release', 'r') if File.exists?('/etc/os-release') - if f - f.read.split('\n').each do |line| - line.match(%r{^ID=(.*)$}) { |m| template_file=m[1] } - end - f.close - f = nil +if template_file.nil? && File.exist?('/etc/os-release') + File.read('/etc/os-release').each_line(chomp: true) do |line| + line.match(%r{^ID=(.*)$}) { |m| template_file=m[1] } end if template_file.match? '^"opensuse' $stderr.puts 'Using template opensuse on openSUSE variant' @@ -44,15 +39,13 @@ end if template_file.nil? template = Gem2Rpm::TEMPLATE else + template_file = File.join(Gem2Rpm.template_dir, template_file + '.spec.erb') unless File.exist?(template_file) begin - f = open(template_file, 'r') if File.exists?(template_file) - f = open(File.join(Gem2Rpm.template_dir, template_file + '.spec.erb'), 'r') unless f + template = File.read(template_file) rescue Errno::ENOENT $stderr.puts "Could not open template #{template_file}. Aborting" exit(1) end - template = f.read - f.close end if options[:print_template_file]