Class: Gonzui::SRPMExtractor

Inherits:
AbstractExtractor show all
Defined in:
lib/gonzui/extractor.rb

Constant Summary collapse

RPMTemporaryDirectories =
["BUILD", "SOURCES", "SPECS"]

Instance Attribute Summary

Attributes included from TemporaryDirectoryUtil

#temporary_directory

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractExtractor

#clean, #extract, #initialize

Methods included from TemporaryDirectoryUtil

#clean_temporary_directory, #prepare_temporary_directory, #set_temporary_directory

Methods included from Util

assert, assert_equal, assert_equal_all, assert_non_nil, assert_not_reached, benchmark, command_exist?, commify, eprintf, format_bytes, program_name, protect_from_signals, require_command, set_verbosity, shell_escape, unix?, vprintf, windows?, wprintf

Constructor Details

This class inherits a constructor from Gonzui::AbstractExtractor

Class Method Details

.commandsObject



272
273
274
# File 'lib/gonzui/extractor.rb', line 272

def self.commands
  ["rpm", "rpmbuild"]
end

.extnamesObject



276
277
278
# File 'lib/gonzui/extractor.rb', line 276

def self.extnames
  [".src.rpm"]
end

Instance Method Details

#clean_rpm_directoriesObject



287
288
289
290
291
292
# File 'lib/gonzui/extractor.rb', line 287

def clean_rpm_directories
  RPMTemporaryDirectories.each {|dirname| 
    path = File.join(self.temporary_directory, dirname)
    FileUtils.rm_rff(path)
  }
end

#do_extractObject



336
337
338
339
340
341
342
343
# File 'lib/gonzui/extractor.rb', line 336

def do_extract
  prepare_rpm_directories
  begin
    do_extract_internal
  ensure
    clean_rpm_directories
  end
end

#do_extract_internalObject

Raises:



301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/gonzui/extractor.rb', line 301

def do_extract_internal
  options = "--nodeps --rmsource"
  common  = sprintf("rpmbuild --define '_topdir %s' %s",
                    self.temporary_directory, options)
  command_line = sprintf("rpm --define '_topdir %s' -i %s",
                         self.temporary_directory,
                         shell_escape(File.expand_path(@file_name)))
  status = system(command_line)
  raise ExtractorError.new("rpm command failed") if status == false
  spec_directory = File.join(self.temporary_directory, "SPECS")
  spec_file_name = find_spec_file(spec_directory)
  command_line =  sprintf("%s -bp %s", common, shell_escape(spec_file_name))
  # FIXME: --target=i686 is a kludge for ExclusiveArch
  command_line << sprintf("|| %s --target=i686 -bp %s",
                          common, shell_escape(spec_file_name))
  unless @config.verbose
    command_line = sprintf("(%s) >/dev/null 2>&1", command_line)
  end
  run_extract_command(command_line, @file_name)

  build_directory = File.join(self.temporary_directory, "BUILD")
  unless has_single_directory?(build_directory)
    raise ExtractorError.new("BUILD should contain a single directory")
  end
  base_name = Dir.entries_without_dots(build_directory).first
  package_name = File.basename(@file_name, ".src.rpm")
  src  = File.join(build_directory, base_name)
  dest = File.join(self.temporary_directory, package_name)
  File.rename(src, dest)

  unless FileTest.exist?(File.join(dest, File.basename(spec_file_name)))
    FileUtils.mv(spec_file_name, dest)
  end
end

#find_spec_file(spec_directory) ⇒ Object

Raises:



294
295
296
297
298
299
# File 'lib/gonzui/extractor.rb', line 294

def find_spec_file(spec_directory)
  base_name = Dir.entries_without_dots(spec_directory).first
  raise ExtractorError.new("spec file not found") unless 
    File.extname(base_name) == ".spec"
  return File.join(spec_directory, base_name)
end

#prepare_rpm_directoriesObject



281
282
283
284
285
# File 'lib/gonzui/extractor.rb', line 281

def prepare_rpm_directories
  RPMTemporaryDirectories.each {|dirname| 
    Dir.mkdir(File.join(self.temporary_directory, dirname))
  }
end