lib/pkg-wizard/commands/remote_build.rb in pkg-wizard-0.1.3 vs lib/pkg-wizard/commands/remote_build.rb in pkg-wizard-0.1.5

- old
+ new

@@ -28,10 +28,16 @@ option :buildbot, :short => '-b URL', :description => 'rpmwiz build-bot URL', :long => '--buildbot URL' + + option :buildbot_port, + :short => '-p PORT', + :description => 'rpmwiz build-bot PORT (default 4567)', + :long => '--buildbot-port PORT', + :default => 4567 option :tmpdir, :short => '-t TEMP', :long => '--tmpdir TEMP', :description => 'Directory for downloaded files to be put', @@ -39,21 +45,23 @@ def self.perform cli = RemoteBuild.new cli.banner = "\nUsage: rpmwiz remote-build (options)\n\n" pkgs = cli.parse_options - bbot_url = cli.config[:buildbot] + bbot_host = cli.config[:buildbot] + bbot_port = cli.config[:buildbot_port] + bbot_url = "http://#{bbot_host}:#{bbot_port}" if bbot_url.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}..." + $stdout.puts "Downloading: #{pkg}" downloaded_pkgs << download_from_url(p,cli.config[:tmpdir]) true else false end @@ -81,32 +89,35 @@ end pkgs.each do |pkg| fo = File.new(pkg) fsize = File.size(pkg) count = 0 + pcount = 0 $stdout.sync = true line_reset = "\r\e[0K" res = StreamingUploader.post( bbot_url + '/build/', { 'pkg' => fo } ) do |size| count += size per = (100*count)/fsize if per %10 == 0 - print "#{line_reset}Uploading:".ljust(40) + "#{(100*count)/fsize}% " + pcount += 10 + print "#{line_reset}Uploading:".ljust(40) + "#{pcount}%" end end - #puts "#{line_reset}Uploading: #{File.basename(pkg).gsub(/-((\d|\.)*)-(.*)\.src\.rpm/,'')} ".ljust(40) + "#{(100*count)/fsize}% [COMPLETE]" - puts "#{line_reset}Uploading: #{File.basename(pkg)} ".ljust(40) + "#{(100*count)/fsize}% [COMPLETE]" + puts "#{line_reset}Uploading: #{File.basename(pkg)} ".ljust(40) + "[#{fsize}] [COMPLETE]" end end 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}" - d.download!(url, File.new(f, 'w')) + tmpfile = File.new(f, 'w') + d.download!(url, tmpfile) + tmpfile.close f end end end