Class: PKGWizard::RemoteBuild

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

Class Method Summary collapse

Methods inherited from Command

registry, #run

Class Method Details

.download_from_url(url, tmpdir = '/tmp') ⇒ Object



149
150
151
152
153
154
155
156
157
158
# File 'lib/pkg-wizard/commands/remote_build.rb', line 149

def self.download_from_url(url, tmpdir = '/tmp')
  uri = URI.parse(url)
  remote_pkg = uri.path.split('/').last
  d = StreamingDownloader.new
  f = "#{tmpdir}/#{remote_pkg}"
  tmpfile = File.new(f, 'w')
  d.download!(url, tmpfile)
  tmpfile.close
  f
end

.performObject



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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/pkg-wizard/commands/remote_build.rb', line 55

def self.perform
  cli = RemoteBuild.new
  cli.banner = "\nUsage: pkgwiz remote-build (options)\n\n"
  pkgs = cli.parse_options
  bbot_host = cli.config[:buildbot]
  bbot_port = cli.config[:buildbot_port]
  bbot_url = "http://#{bbot_host}:#{bbot_port}"
  if bbot_host.nil?
    $stderr.puts "\n--buildbot is required.\n"
    puts cli.opt_parser.help
    exit 1
  end
  downloaded_pkgs = []
  pkgs.reject! do |p|
    if p =~ /http:\/\//
      pkg = URI.parse(p).path.split("/").last
      $stdout.puts "Downloading: #{pkg}"
      downloaded_pkgs << download_from_url(p,cli.config[:tmpdir]) 
      true
    elsif p =~ /git:\/\//
      require 'tmpdir'
      d = Dir.mktmpdir

      # Fetch the package sources using Git
      $stdout.puts "Fetching package sources from Git..."
      PKGWizard::GitRPM.fetch p, d
      spec = Dir["#{d}/*.spec"].first
      pwd = Dir.pwd
      Dir.chdir d

      # Download sources
      source = cli.config[:source]
      if source and source =~ /http:\/\//
        url = URI.parse(source)
        $stdout.puts "Downloading source #{File.basename(url.path)}..."
        download_from_url(source,d) 
        puts
      end

      # Create the SRPM
      $stdout.puts "Creating SRPM for #{spec}..."
      srpm = SRPM.create
      downloaded_pkgs << srpm
      Dir.chdir pwd
      FileUtils.rm_rf d
      true
    else
      false
    end
  end
  pkgs += downloaded_pkgs

  #
  # If no packages are specified, we assume we need to create
  # and SRPM from current dir
  #
  created_srpms = []
  if pkgs.empty? and Dir["*.spec"].size > 0
    spec = Dir["*.spec"].first
    $stdout.puts "Creating SRPM for #{spec}..."
    srpm = SRPM.create
    created_srpms << srpm
  end
  pkgs += created_srpms

  # We need this to show the progress percentage 
  if pkgs.empty?
    $stderr.puts "\nNo packages found.\n\n"
    puts cli.opt_parser.help
    exit 1
  end
  pkgs.each do |pkg|
    fo = File.new(pkg)
    fsize = File.size(pkg)
    count = 0
    $stdout.sync = true
    line_reset = "\r\e[0K" 
    params = {}
    params[:mock_profile] = cli.config[:mock_profile] if cli.config[:mock_profile]
    params[:pkg] = fo
    res = StreamingUploader.post(
      bbot_url + '/build/',
      params
    ) do |size|
      count += size
      per = (100*count)/fsize 
      if per %10 == 0
        print "#{line_reset}Uploading:".ljust(40) + "[#{count}/#{fsize}]" 
      end
    end
    puts "#{line_reset}Uploading: #{File.basename(pkg)} ".ljust(40) + "[#{fsize}] [COMPLETE]"
  end
end