swa 0.8.5 → 0.8.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 731347c42ce0823ababd94ff7eeb58ea42e9d42cfbf152cea6d103356f8ea9d2
4
- data.tar.gz: fe2feaa04f3fd3df8f2664160b70d362050b587e22772018a6221ebe13482ff5
3
+ metadata.gz: 5c07723e018108852c4b08553e806bdd53e80e88988e2fa1dbdef99b8aebbab3
4
+ data.tar.gz: 2835192e6d525d1bdb79ae94b698f8435f3311bba1deb145d20a5ab9257e373e
5
5
  SHA512:
6
- metadata.gz: a2e6b01eb2be3d32536688c14db2b5511281f735b989716a26be37a8feb773ee153497de1a9ac1816112cedf8b5387ab656db38e14da1f8bbe6f6245e37965a1
7
- data.tar.gz: 9a6939b4984e7a5eb0e2a66e795312e91e634a173310607b2bcf3f2ba4f885a4fc98bb8ee51b6ca201465922c14a60d813f5ac0e54e0321ae8a1e1b4935fc7d9
6
+ metadata.gz: 0cc932811e45b02d1d1b254ca52ba54e188281f59764e4b0efaae4164bdc2695f7c7cfcbab3f0ab92c6cbcfd417b3ef17e05e5a76ce2b29820c7c936cfb65a47
7
+ data.tar.gz: fc6105d43f360c2db2be74a594bd855a4567618143edbefb6343f46c5dd137af87971468a1d85c9cad5ef2a0b7d2c952f8b9b10c02b60f29f90c910f615e8587
@@ -68,7 +68,28 @@ module Swa
68
68
  parameter "FILE", "file name", :attribute_name => :file_name
69
69
 
70
70
  def execute
71
- object.upload(file_name)
71
+ object.upload_from(file_name)
72
+ end
73
+
74
+ end
75
+
76
+ subcommand "download", "download object to local file" do
77
+
78
+ option %w(-T --to), "TARGET", "file or directory to download into", default: ".", attribute_name: :target
79
+
80
+ def execute
81
+ object.download_into(target_file_path, &method(:log_download_progress))
82
+ logger.info "Downloaded to #{target_file_path}"
83
+ end
84
+
85
+ private
86
+
87
+ def target_file_path
88
+ if File.directory?(target)
89
+ File.join(target, File.basename(object_key))
90
+ else
91
+ target
92
+ end
72
93
  end
73
94
 
74
95
  end
@@ -96,6 +117,27 @@ module Swa
96
117
 
97
118
  end
98
119
 
120
+ subcommand "download", "download version to local file" do
121
+
122
+ option %w(-T --to), "TARGET", "file or directory to download into", default: ".", attribute_name: :target
123
+
124
+ def execute
125
+ version.download_into(target_file_path)
126
+ logger.info "Downloaded to #{target_file_path}"
127
+ end
128
+
129
+ private
130
+
131
+ def target_file_path
132
+ if File.directory?(target)
133
+ File.join(target, File.basename(object_key))
134
+ else
135
+ target
136
+ end
137
+ end
138
+
139
+ end
140
+
99
141
  protected
100
142
 
101
143
  def version
@@ -263,6 +305,12 @@ module Swa
263
305
  resource_model.list(aws_resources)
264
306
  end
265
307
 
308
+ def log_download_progress(bytes, part_sizes, file_size)
309
+ # total_bytes = bytes.sum
310
+ # percent_done = "%.1f" % [100.0 * total_bytes / file_size]
311
+ # logger.debug "Downloaded #{total_bytes} of #{file_size}; #{percent_done}% done"
312
+ end
313
+
266
314
  end
267
315
 
268
316
  end
data/lib/swa/s3/object.rb CHANGED
@@ -30,11 +30,15 @@ module Swa
30
30
  object.get.body
31
31
  end
32
32
 
33
+ def download_into(file_name, &progress_callback)
34
+ object.download_file(file_name, progress_callback: progress_callback)
35
+ end
36
+
33
37
  def put(io, options = {})
34
38
  object.put(options.merge(:body => io))
35
39
  end
36
40
 
37
- def upload(file_name)
41
+ def upload_from(file_name)
38
42
  object.upload_file(file_name)
39
43
  end
40
44
 
@@ -34,6 +34,17 @@ module Swa
34
34
  version.get.body
35
35
  end
36
36
 
37
+ def download_into(file_name, &progress_callback)
38
+ downloader = Aws::S3::FileDownloader.new(client: aws_resource.client)
39
+ options = {
40
+ bucket: version.bucket_name,
41
+ key: version.object_key,
42
+ version_id: version.id,
43
+ progress_callback: progress_callback,
44
+ }
45
+ downloader.download(file_name, options)
46
+ end
47
+
37
48
  def delete
38
49
  version.delete
39
50
  end
data/lib/swa/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Swa
2
- VERSION = "0.8.5"
2
+ VERSION = "0.8.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.5
4
+ version: 0.8.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Williams
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-12 00:00:00.000000000 Z
11
+ date: 2024-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -360,7 +360,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
360
360
  - !ruby/object:Gem::Version
361
361
  version: '0'
362
362
  requirements: []
363
- rubygems_version: 3.5.3
363
+ rubygems_version: 3.5.10
364
364
  signing_key:
365
365
  specification_version: 4
366
366
  summary: AWS, backwards