anvil-cli 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/anvil/cli.rb CHANGED
@@ -2,6 +2,7 @@ require "anvil"
2
2
  require "anvil/builder"
3
3
  require "anvil/manifest"
4
4
  require "anvil/version"
5
+ require "progress"
5
6
  require "thor"
6
7
  require "uri"
7
8
 
@@ -30,9 +31,18 @@ class Anvil::CLI < Thor
30
31
  Anvil::Builder.new(source)
31
32
  else
32
33
  manifest = Anvil::Manifest.new(File.expand_path(source))
33
- print "Uploading app... "
34
- count = manifest.upload
35
- puts "done, #{count} files uploaded"
34
+ print "Checking for files to sync... "
35
+ missing = manifest.missing
36
+ puts "done, #{missing.length} files needed"
37
+
38
+ if missing.length > 0
39
+ Progress.start("Uploading", missing.map { |hash, file| file["size"].to_i }.inject(&:+))
40
+ manifest.upload(missing.keys) do |file|
41
+ Progress.step file["size"].to_i
42
+ end
43
+ puts "Uploading, done "
44
+ end
45
+
36
46
  manifest
37
47
  end
38
48
 
@@ -41,6 +51,8 @@ class Anvil::CLI < Thor
41
51
  end
42
52
 
43
53
  old_stdout.puts slug_url if options[:pipeline]
54
+ rescue Anvil::Builder::BuildError => ex
55
+ error "Build Error: #{ex.message}"
44
56
  end
45
57
 
46
58
  desc "version", "Display Anvil version"
@@ -74,9 +74,21 @@ class Anvil::Manifest
74
74
  res.headers[:location]
75
75
  end
76
76
 
77
- def upload
78
- missing = json_decode(anvil["/manifest/diff"].post(:manifest => self.to_json).to_s)
79
- upload_hashes missing
77
+ def manifest_by_hash(manifest)
78
+ manifest.inject({}) do |ax, (name, file)|
79
+ ax.update file["hash"] => file.merge("name" => name)
80
+ end
81
+ end
82
+
83
+ def missing
84
+ mbh = manifest_by_hash(@manifest)
85
+ json_decode(anvil["/manifest/diff"].post(:manifest => self.to_json).to_s).inject({}) do |ax, hash|
86
+ ax.update hash => mbh[hash]
87
+ end
88
+ end
89
+
90
+ def upload(missing, &blk)
91
+ upload_hashes missing, &blk
80
92
  missing.length
81
93
  end
82
94
 
@@ -107,6 +119,7 @@ private
107
119
  next(hash) if File.pipe?(file)
108
120
  next(hash) if file =~ /\.git/
109
121
  next(hash) if file =~ /\.swp$/
122
+ next(hash) unless file =~ /^[A-Za-z0-9\-\_\.\/]*$/
110
123
  hash[Pathname.new(file).relative_path_from(root).to_s] = file_manifest(file)
111
124
  hash
112
125
  end
@@ -117,6 +130,7 @@ private
117
130
  manifest = {
118
131
  "mtime" => stat.mtime.to_i,
119
132
  "mode" => "%o" % stat.mode,
133
+ "size" => stat.size.to_s
120
134
  }
121
135
  if File.symlink?(file)
122
136
  manifest["link"] = File.readlink(file)
@@ -138,7 +152,8 @@ private
138
152
  error "error uploading #{filename}: #{ex.http_body}"
139
153
  end
140
154
 
141
- def upload_hashes(hashes)
155
+ def upload_hashes(hashes, &blk)
156
+ mbh = manifest_by_hash(@manifest)
142
157
  filenames_by_hash = @manifest.inject({}) do |ax, (name, file_manifest)|
143
158
  ax.update file_manifest["hash"] => File.join(@dir.to_s, name)
144
159
  end
@@ -152,6 +167,7 @@ private
152
167
  Thread.new do
153
168
  hashes.each do |hash|
154
169
  upload_file filenames_by_hash[hash], hash
170
+ blk.call mbh[hash]
155
171
  end
156
172
  end
157
173
  end
data/lib/anvil/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Anvil
2
- VERSION = "0.0.6"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anvil-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-16 00:00:00.000000000 Z
12
+ date: 2012-08-21 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: progress
16
+ requirement: &70322453636400 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.4.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70322453636400
14
25
  - !ruby/object:Gem::Dependency
15
26
  name: rest-client
16
- requirement: &70359909240180 !ruby/object:Gem::Requirement
27
+ requirement: &70322453635920 !ruby/object:Gem::Requirement
17
28
  none: false
18
29
  requirements:
19
30
  - - ~>
@@ -21,10 +32,10 @@ dependencies:
21
32
  version: 1.6.7
22
33
  type: :runtime
23
34
  prerelease: false
24
- version_requirements: *70359909240180
35
+ version_requirements: *70322453635920
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: thor
27
- requirement: &70359909256060 !ruby/object:Gem::Requirement
38
+ requirement: &70322453635460 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ~>
@@ -32,7 +43,7 @@ dependencies:
32
43
  version: 0.15.2
33
44
  type: :runtime
34
45
  prerelease: false
35
- version_requirements: *70359909256060
46
+ version_requirements: *70322453635460
36
47
  description: Alternate Heroku build workflow
37
48
  email: david@dollar.io
38
49
  executables: