Class: PKGWizard::CreateSrpm

Inherits:
Command
  • Object
show all
Defined in:
lib/pkg-wizard/commands/create_srpm.rb

Class Method Summary collapse

Methods inherited from Command

registry, #run

Class Method Details

.performObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/pkg-wizard/commands/create_srpm.rb', line 37

def self.perform
  cmd = CreateSrpm.new
  cmd.banner = "\nUsage: pkgwiz create-srpm (options)\n\n"
  cmd.parse_options
  repo = cmd.config[:gitrepo]
  workspace = cmd.config[:workspace] || "/tmp/pkgwiz-#{Time.now.to_i}"
  FileUtils.mkdir_p(workspace) if not File.exist?(workspace)
  source_dir = workspace + '/SOURCES'

  resultdir = cmd.config[:resultdir] || workspace + '/SRPMS'
  if not File.exist?(resultdir)
    Dir.mkdir(resultdir)
  end

  if not File.exist?(resultdir)
    raise Exception.new("resultdir #{resultdir} does not exist.")
  end
  if repo
    begin
      repo_name = URI.parse(repo).path.split('/').last.gsub(/\.git$/,'')
    rescue Exception => e
      raise Exception.new('Invalid Git repo URL')
    end
    repo_dir = File.join(source_dir, repo_name)
    if not File.exist?(repo_dir)
      FileUtils.mkdir_p repo_dir
    end
    GitRPM.fetch(repo, repo_dir)
    pwd = Dir.pwd
    Dir.chdir repo_dir
    output = SRPM.create
    # FIXME
    # This is dangerous but SRPM.create does not return
    # the full filename
    pkg = output
    basename = File.basename(pkg)
    Dir.chdir pwd
    FileUtils.cp pkg, resultdir
    $stdout.puts "SRPM created: #{resultdir}/#{basename}"
  else
    output = SRPM.create
    # FIXME
    # This is dangerous but SRPM.create does not return
    # the full filename
    pkg = output
    basename = File.basename(pkg)
    FileUtils.cp pkg, resultdir
    $stdout.puts "SRPM created: #{resultdir}/#{basename}"
  end
end