Permalink
Browse files

wip upload progress

  • Loading branch information...
Alex Suraci and Dmitriy Kalinin
Alex Suraci and Dmitriy Kalinin committed Mar 12, 2013
1 parent 2b9f014 commit ff2bb1fcc755b3b7eff91a42b84ea058e12cd28c
Showing with 113 additions and 32 deletions.
  1. +2 −8 Gemfile
  2. +30 −18 Gemfile.lock
  3. +79 −2 lib/vmc/cli/app/push.rb
  4. +2 −4 vmc.gemspec
View
10 Gemfile
@@ -1,15 +1,9 @@
source "http://rubygems.org"
-#############
-# WARNING: Separate from the Gemspec. Please update both files
-#############
-
-gem "json_pure", "~> 1.6"
-gem "multi_json", "~> 1.3"
-gem "rake"
+gemspec
gem "interact", :git => "git://github.com/vito/interact.git"
-gem "cfoundry", :git => "git://github.com/cloudfoundry/vmc-lib.git", :submodules => true
+gem "cfoundry", :path => "../vmc-lib" #:git => "git://github.com/cloudfoundry/vmc-lib.git", :submodules => true
gem "clouseau", :git => "git://github.com/vito/clouseau.git"
gem "mothership", :git => "git://github.com/vito/mothership.git"
View
@@ -27,26 +27,15 @@ GIT
GIT
remote: git://github.com/cloudfoundry/tunnel-vmc-plugin.git
- revision: 55fbed47313871640cc9e1b481d3019c4a5ee5ba
+ revision: 2f3ea2523d8c8817b009246a8d8c268bbf8f4301
specs:
- tunnel-vmc-plugin (0.2.0)
+ tunnel-vmc-plugin (0.2.2)
addressable (~> 2.2)
caldecott-client (~> 0.0.2)
- cfoundry (~> 0.5.0)
+ cfoundry (>= 0.5.3.rc3, < 0.6)
rest-client (~> 1.6)
uuidtools (~> 2.1)
-GIT
- remote: git://github.com/cloudfoundry/vmc-lib.git
- revision: 759dd7fd042b50ea8e51cd52f5fd541462a17548
- submodules: true
- specs:
- cfoundry (0.5.3.rc3)
- cf-uaa-lib (~> 1.3.8)
- multi_json (~> 1.3)
- multipart-post (~> 1.1)
- rubyzip (~> 0.9)
-
GIT
remote: git://github.com/vito/clouseau.git
revision: af05617556504c436901d43edc76f6578f363b83
@@ -66,6 +55,29 @@ GIT
specs:
mothership (0.5.1)
+PATH
+ remote: .
+ specs:
+ vmc (0.5.1.rc3)
+ cfoundry (>= 0.5.3.rc3, < 0.6)
+ clouseau (~> 0.0)
+ interact (~> 0.5)
+ json_pure (~> 1.6)
+ manifests-vmc-plugin (~> 0.6.2)
+ mothership (>= 0.5.1, < 1.0)
+ multi_json (~> 1.3)
+ progressbar (= 0.20.0)
+ tunnel-vmc-plugin (~> 0.2.2)
+
+PATH
+ remote: ../vmc-lib
+ specs:
+ cfoundry (0.5.3.rc3)
+ cf-uaa-lib (~> 1.3.8)
+ multi_json (~> 1.3)
+ multipart-post (~> 1.1)
+ rubyzip (~> 0.9)
+
GEM
remote: http://rubygems.org/
specs:
@@ -86,7 +98,8 @@ GEM
parallel (0.6.2)
parallel_tests (0.10.0)
parallel
- rake (10.0.3)
+ progressbar (0.20.0)
+ rake (0.9.6)
rest-client (1.6.7)
mime-types (>= 1.16)
rr (1.0.4)
@@ -116,14 +129,13 @@ DEPENDENCIES
ffaker
gem-release
interact!
- json_pure (~> 1.6)
manifests-vmc-plugin!
mcf-vmc-plugin!
mothership!
- multi_json (~> 1.3)
parallel_tests
- rake
+ rake (~> 0.9)
rr (~> 1.0)
rspec (~> 2.11)
tunnel-vmc-plugin!
+ vmc!
webmock (~> 1.9)
View
@@ -1,3 +1,6 @@
+# coding: UTF-8
+require "progressbar"
+
require "vmc/cli/app/base"
require "vmc/cli/app/push/sync"
require "vmc/cli/app/push/create"
@@ -79,12 +82,86 @@ def url_choices(name)
end
end
+ class FancyProgressBar < ProgressBar
+ def initialize(title)
+ super(title, 1)
+ @configured = true
+ @title_width = @title.gsub(/\e\[\d+m/, "").size + 1
+ @format = "%-#{@title_width}s %3d%% %s %s"
+ end
+
+ # Colorizes the string with raindow colors of the rainbow
+ #
+ # @params string [String]
+ # @return [String]
+ def rainbowify(string)
+ c = colors[@current % colors.size]
+ "\e[38;5;#{c}m#{string}#{ESC}0m"
+ end
+
+ # Calculates the colors of the rainbow
+ #
+ # @return [Array]
+ def colors
+ @colors ||= (0...(6 * 7)).map do |n|
+ pi_3 = Math::PI / 3
+ n *= 1.0 / 6
+ r = (3 * Math.sin(n ) + 3).to_i
+ g = (3 * Math.sin(n + 2 * pi_3) + 3).to_i
+ b = (3 * Math.sin(n + 4 * pi_3) + 3).to_i
+ 36 * r + 6 * g + b + 16
+ end
+ end
+
+ def fmt_bar
+ bar_width = do_percentage * @terminal_width / 100
+ sprintf("%s%s",
+ # rainbowify(@bar_mark * bar_width),
+ @bar_mark * bar_width,
+ " " * (@terminal_width - bar_width))
+ end
+
+ def fmt_title
+ @title
+ end
+
+ def clear
+ super if @configured
+ end
+
+ def show
+ super if @configured
+ end
+
+ def set(count, total)
+ @total = total
+ super(count)
+ end
+
+ # @44 it shows a single `o'
+ def get_term_width
+ [super, 44].max
+ end
+ end
+
def upload_app(app, path)
app = filter(:push_app, app)
+ pbar = nil
- with_progress("Uploading #{c(app.name, :name)}") do
- app.upload(path)
+ line "Uploading #{c(app.name, :name)}..."
+ pbar = FancyProgressBar.new("")
+ pbar.file_transfer_mode
+ pbar.bar_mark = "#"
+ pbar.show
+
+ app.upload(path) do |current, total|
+ pbar.set(current, total)
end
+
+ pbar.finish
+ line c("OK", :good)
+ line
+
rescue
err "Upload failed. Try again with 'vmc push'."
raise
View
@@ -1,9 +1,5 @@
# -*- encoding: utf-8 -*-
-#############
-# WARNING: Separate from the Gemfile. Please update both files
-#############
-
$:.push File.expand_path("../lib", __FILE__)
require "vmc/version"
@@ -27,6 +23,8 @@ Gem::Specification.new do |s|
s.add_runtime_dependency "json_pure", "~> 1.6"
s.add_runtime_dependency "multi_json", "~> 1.3"
+ s.add_runtime_dependency "progressbar", "0.20.0"
+
s.add_runtime_dependency "interact", "~> 0.5"
s.add_runtime_dependency "cfoundry", ">= 0.5.3.rc3", "< 0.6"
s.add_runtime_dependency "clouseau", "~> 0.0"

0 comments on commit ff2bb1f

Please sign in to comment.