s3_zipper 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock CHANGED
@@ -1,34 +1,42 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- s3_zipper (1.0.4)
4
+ s3_zipper (1.0.6)
5
5
  aws-sdk-s3 (~> 1)
6
+ concurrent-ruby (~> 1.1)
6
7
  ruby-progressbar (~> 1)
7
8
  rubyzip (>= 1.0.0)
8
9
 
9
10
  GEM
10
11
  remote: https://rubygems.org/
11
12
  specs:
13
+ ast (2.4.0)
12
14
  aws-eventstream (1.0.3)
13
- aws-partitions (1.159.0)
14
- aws-sdk-core (3.50.0)
15
+ aws-partitions (1.167.0)
16
+ aws-sdk-core (3.53.1)
15
17
  aws-eventstream (~> 1.0, >= 1.0.2)
16
18
  aws-partitions (~> 1.0)
17
19
  aws-sigv4 (~> 1.1)
18
20
  jmespath (~> 1.0)
19
- aws-sdk-kms (1.18.0)
20
- aws-sdk-core (~> 3, >= 3.48.2)
21
+ aws-sdk-kms (1.21.0)
22
+ aws-sdk-core (~> 3, >= 3.53.0)
21
23
  aws-sigv4 (~> 1.1)
22
- aws-sdk-s3 (1.36.1)
23
- aws-sdk-core (~> 3, >= 3.48.2)
24
+ aws-sdk-s3 (1.40.0)
25
+ aws-sdk-core (~> 3, >= 3.53.0)
24
26
  aws-sdk-kms (~> 1)
25
27
  aws-sigv4 (~> 1.0)
26
28
  aws-sigv4 (1.1.0)
27
29
  aws-eventstream (~> 1.0, >= 1.0.2)
30
+ concurrent-ruby (1.1.5)
28
31
  diff-lcs (1.3)
29
32
  docile (1.3.1)
33
+ jaro_winkler (1.5.2)
30
34
  jmespath (1.4.0)
31
35
  json (2.2.0)
36
+ parallel (1.17.0)
37
+ parser (2.6.3.0)
38
+ ast (~> 2.4.0)
39
+ rainbow (3.0.0)
32
40
  rake (10.5.0)
33
41
  rake-compiler (1.0.7)
34
42
  rake
@@ -45,14 +53,22 @@ GEM
45
53
  diff-lcs (>= 1.2.0, < 2.0)
46
54
  rspec-support (~> 3.8.0)
47
55
  rspec-support (3.8.0)
56
+ rubocop (0.70.0)
57
+ jaro_winkler (~> 1.5.1)
58
+ parallel (~> 1.10)
59
+ parser (>= 2.6)
60
+ rainbow (>= 2.2.2, < 4.0)
61
+ ruby-progressbar (~> 1.7)
62
+ unicode-display_width (>= 1.4.0, < 1.7)
48
63
  ruby-progressbar (1.10.0)
49
- rubyzip (1.2.2)
64
+ rubyzip (1.2.3)
50
65
  simplecov (0.16.1)
51
66
  docile (~> 1.1)
52
67
  json (>= 1.8, < 3)
53
68
  simplecov-html (~> 0.10.0)
54
69
  simplecov-html (0.10.2)
55
70
  thor (0.20.3)
71
+ unicode-display_width (1.6.0)
56
72
 
57
73
  PLATFORMS
58
74
  ruby
@@ -62,6 +78,7 @@ DEPENDENCIES
62
78
  rake (~> 10.0)
63
79
  rake-compiler
64
80
  rspec (~> 3.0)
81
+ rubocop (~> 0.70.0)
65
82
  s3_zipper!
66
83
  simplecov
67
84
  thor
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "bundler/setup"
4
5
  require "s3_zipper"
data/exe/s3_zipper CHANGED
@@ -1,24 +1,25 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "s3_zipper"
4
- require 'thor'
5
- require 'awesome_print'
5
+ require "thor"
6
+ require "awesome_print"
6
7
  class CLI < Thor
7
- desc 'local_file FILES', 'zip files from s3 to a local file'
8
- method_option :filename, type: :string, aliases: 'f', desc: 'Name of the created zip archive'
9
- method_option :bucket, type: :string, default: ENV['AWS_BUCKET'], required: !ENV['AWS_BUCKET'].nil?, aliases: 'b', desc: 'Name of the bucket the files are in'
8
+ desc "local_file FILES", "zip files from s3 to a local file"
9
+ method_option :filename, type: :string, aliases: "f", desc: "Name of the created zip archive"
10
+ method_option :bucket, type: :string, default: ENV["AWS_BUCKET"], required: !ENV["AWS_BUCKET"].nil?, aliases: "b", desc: "Name of the bucket the files are in"
10
11
 
11
- def local_file(*files)
12
+ def local_file *files
12
13
  S3Zipper.new(options[:bucket]).zip_to_local_file(files, file: options[:filename] || SecureRandom.hex)
13
14
  end
14
15
 
15
- desc 's3 FILES', 'zip files from s3 to s3'
16
- method_option :filename, type: :string, aliases: 'f', desc: 'Name of the created zip archive'
17
- method_option :path, type: :string, aliases: 'p', desc: 'Path to the file in s3'
18
- method_option :bucket, type: :string, default: ENV['AWS_BUCKET'], required: !ENV['AWS_BUCKET'].nil?, aliases: 'b', desc: 'Name of the bucket the files are in'
16
+ desc "s3 FILES", "zip files from s3 to s3"
17
+ method_option :filename, type: :string, aliases: "f", desc: "Name of the created zip archive"
18
+ method_option :path, type: :string, aliases: "p", desc: "Path to the file in s3"
19
+ method_option :bucket, type: :string, default: ENV["AWS_BUCKET"], required: !ENV["AWS_BUCKET"].nil?, aliases: "b", desc: "Name of the bucket the files are in"
19
20
 
20
- def s3(*files)
21
+ def s3 *files
21
22
  S3Zipper.new(options[:bucket]).zip_to_s3(files, filename: options[:filename] || SecureRandom.hex, path: options[:path])
22
23
  end
23
24
  end
24
- CLI.start(ARGV)
25
+ CLI.start(ARGV)
@@ -1,5 +1,6 @@
1
- require 'aws-sdk-s3'
1
+ # frozen_string_literal: true
2
2
 
3
+ require "aws-sdk-s3"
3
4
  class S3Zipper
4
5
  class Client
5
6
  attr_accessor :bucket_name, :client, :options, :resource, :pb
@@ -42,18 +43,26 @@ class S3Zipper
42
43
  temp.binmode
43
44
  temp = download_to_file key, temp
44
45
  return if temp.nil?
46
+
45
47
  yield(temp) if block_given?
46
48
  temp
47
49
  ensure
48
50
  temp&.unlink if cleanup
49
51
  end
50
52
 
51
- def get_url(key)
53
+ def get_url key
52
54
  resource.bucket(bucket_name).object(key).public_url
53
55
  end
54
56
 
55
57
  def upload local_path, repo_path, options: {}
56
- client.put_object(options.merge!(bucket: bucket_name, key: repo_path, body: File.open(local_path).read))
58
+ spinner = Spinner.new(
59
+ enabled: options[:progress],
60
+ title: "Uploading zip to #{bucket_name}/#{repo_path}",
61
+ )
62
+ spinner.start
63
+ object = client.put_object(options.merge!(bucket: bucket_name, key: repo_path, body: File.open(local_path).read))
64
+ spinner.finish title: "Uploaded zip to #{bucket_name}/#{repo_path}"
65
+ object
57
66
  end
58
67
  end
59
68
  end
@@ -1,38 +1,61 @@
1
- require 'ruby-progressbar'
1
+ # frozen_string_literal: true
2
+
3
+ require "ruby-progressbar"
2
4
  class Progress
5
+
3
6
  def initialize options = {}
4
7
  return unless options[:enabled] || true
8
+
5
9
  @options = options
6
10
  @format = options[:format]
7
11
  @progress_bar = ProgressBar.create(@options)
8
12
  end
9
13
 
10
- def reset(title: nil, total: nil, format: nil)
14
+ def reset title: nil, total: nil, format: nil
15
+ return unless @progress_bar
16
+
11
17
  @progress_bar.progress = 0
12
- @progress_bar.title = title
13
- @progress_bar.total = total
14
- @progress_bar.format = format
18
+ @progress_bar.title = title if title
19
+ @progress_bar.total = total if total
20
+ @progress_bar.format = format if format
15
21
  refresh
16
22
  end
17
23
 
24
+ def spin
25
+ until @progress_bar.finished?
26
+ increment
27
+ end
28
+ end
29
+
18
30
  def total
19
- @progress_bar&.total
31
+ return unless @progress_bar
32
+
33
+ @progress_bar.total
20
34
  end
21
35
 
22
36
  def percentage
23
- @progress_bar&.to_h['percentage']
37
+ return unless @progress_bar
38
+
39
+ @progress_bar.to_h["percentage"]
24
40
  end
25
41
 
26
42
  def refresh
27
- @progress_bar&.refresh
43
+ return unless @progress_bar
44
+
45
+ @progress_bar.refresh
28
46
  end
29
47
 
30
48
  def progress
31
- @progress_bar&.progress
49
+ return unless @progress_bar
50
+
51
+ @progress_bar.progress
32
52
  end
33
53
 
34
- def increment
35
- @progress_bar&.increment
54
+ def increment attrs = {}
55
+ return unless @progress_bar
56
+
57
+ @progress_bar.increment
58
+ update_attrs(attrs) unless attrs.empty?
36
59
  end
37
60
 
38
61
  def update_attrs attrs
@@ -41,11 +64,13 @@ class Progress
41
64
 
42
65
  def update attr, value
43
66
  return unless @progress_bar
67
+
44
68
  @progress_bar.send("#{attr}=", value)
45
69
  end
46
70
 
47
71
  def finish title: nil, format: nil
48
72
  return unless @progress_bar
73
+
49
74
  @progress_bar.title = title if title
50
75
  @progress_bar.format = format if format
51
76
  @progress_bar.finish
@@ -57,6 +82,7 @@ class Progress
57
82
 
58
83
  def get_attr attr
59
84
  return unless @progress_bar
85
+
60
86
  @progress_bar.send(attr)
61
87
  end
62
- end
88
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ruby-progressbar"
4
+ require "concurrent-ruby"
5
+ class S3Zipper
6
+ class Spinner
7
+ include Concurrent::Async
8
+
9
+ def initialize title: "", enabled: true, steps: %w[⎺ ⎻ ⎼ ⎽ ⎼ ⎻]
10
+ return unless enabled || true
11
+
12
+ @progress_bar = ProgressBar.create(
13
+ format: "[%i] %t",
14
+ total: nil,
15
+ length: 97,
16
+ title: title,
17
+ autofinish: false,
18
+ unknown_progress_animation_steps: steps,
19
+ )
20
+ end
21
+
22
+ def reset title: nil, total: nil, format: nil
23
+ return unless @progress_bar
24
+
25
+ @progress_bar.progress = 0
26
+ @progress_bar.title = title if title
27
+ @progress_bar.total = total if total
28
+ @progress_bar.format = format if format
29
+ refresh
30
+ end
31
+
32
+ def start
33
+ async.spin
34
+ end
35
+
36
+ def spin
37
+ return unless @progress_bar
38
+ until @progress_bar.finished?
39
+ increment
40
+ end
41
+ end
42
+
43
+ def increment
44
+ return unless @progress_bar
45
+
46
+ @progress_bar.increment
47
+ end
48
+
49
+ def finish title: nil
50
+ return unless @progress_bar
51
+
52
+ @progress_bar.title = title if title
53
+ @progress_bar.format = "[✔] %t"
54
+ @progress_bar.finish
55
+ end
56
+ end
57
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class S3Zipper
2
- VERSION = "1.0.5"
4
+ VERSION = "1.0.6"
3
5
  end
data/lib/s3_zipper.rb CHANGED
@@ -1,27 +1,32 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "s3_zipper/version"
2
- require 's3_zipper/progress'
4
+ require "s3_zipper/progress"
5
+ require "s3_zipper/spinner"
3
6
  require "s3_zipper/client"
4
7
  require "zip"
5
8
 
6
9
  class S3Zipper
7
- attr_accessor :client, :options, :progress
10
+ attr_accessor :client, :options, :progress, :zip_client
8
11
 
9
12
  # @param [String] bucket - bucket that files exist in
10
13
  # @param [Hash] options - options for zipper
11
14
  # @option options [Boolean] :progress - toggles progress tracking
12
15
  # @return [S3Zipper]
13
16
  def initialize bucket, options = {}
14
- @options = options
15
- @client = Client.new(bucket, options)
16
- @progress = Progress.new(enabled: options[:progress], format: "%e %c/%C %t", total: nil, length: 80, autofinish: false)
17
+ @options = options
18
+ @progress = Progress.new(enabled: options[:progress], format: "%e %c/%C %t", total: nil, length: 80, autofinish: false)
19
+ @client = Client.new(bucket, options)
20
+ @zip_client = Client.new(options[:zip_bucket], options) if options[:zip_bucket]
21
+ @zip_client ||= @client
17
22
  end
18
23
 
19
24
  # Zips files from s3 to a local zip
20
25
  # @param [Array] keys - Array of s3 keys to zip
21
26
  # @param [String, File] file - Filename or file object for the zip, defaults to a random string
22
27
  # @return [Hash]
23
- def zip_to_local_file(keys, file: SecureRandom.hex, &block)
24
- file = file.is_a?(File) ? file : File.open("#{file}.zip", 'w')
28
+ def zip_to_local_file keys, file: SecureRandom.hex, &block
29
+ file = file.is_a?(File) ? file : File.open("#{file}.zip", "w")
25
30
  zip(keys, file.path, &block)
26
31
  end
27
32
 
@@ -29,8 +34,8 @@ class S3Zipper
29
34
  # @param [Array] keys - Array of s3 keys to zip
30
35
  # @param [String, File] filename - Name of file, defaults to a random string
31
36
  # @return [Hash]
32
- def zip_to_tempfile(keys, filename: SecureRandom.hex, cleanup: false, &block)
33
- zipfile = Tempfile.new([filename, '.zip'])
37
+ def zip_to_tempfile keys, filename: SecureRandom.hex, cleanup: false, &block
38
+ zipfile = Tempfile.new([filename, ".zip"])
34
39
  result = zip(keys, zipfile.path, &block)
35
40
  zipfile.unlink if cleanup
36
41
  result
@@ -42,12 +47,9 @@ class S3Zipper
42
47
  # @param [String] path - path for file in s3
43
48
  # @return [Hash]
44
49
  def zip_to_s3 keys, filename: SecureRandom.hex, path: nil, s3_options: {}, &block
45
- progress.update :total, 1
46
50
  filename = "#{path ? "#{path}/" : ''}#{filename}.zip"
47
51
  result = zip_to_tempfile(keys, filename: filename, cleanup: false, &block)
48
- progress.update_attrs title: "Uploading zip to s3", total: nil
49
- client.upload(result.delete(:filename), filename, options: s3_options)
50
- progress.finish(title: "Uploaded zip to #{filename}")
52
+ zip_client.upload(result.delete(:filename), filename, options: s3_options)
51
53
  result[:key] = filename
52
54
  result[:url] = client.get_url(result[:key])
53
55
  result
@@ -59,19 +61,18 @@ class S3Zipper
59
61
  # @param [String] path - path to zip
60
62
  # @yield [progress]
61
63
  # @return [Hash]
62
- def zip(keys, path)
63
- total = progress.total || 0
64
- total += keys.size
65
- progress.update_attrs total: total, title: "Zipping Keys to #{path}"
64
+ def zip keys, path
65
+ progress.reset total: keys.size, title: "Zipping Keys to #{path}"
66
66
  Zip::File.open(path, Zip::File::CREATE) do |zipfile|
67
67
  @failed, @successful = client.download_keys keys do |file, key|
68
- progress.increment
69
- progress.update :title, "Zipping #{key} to #{path}"
68
+ progress.increment title: "Zipping #{key} to #{path}"
70
69
  yield(zipfile, progress) if block_given?
71
70
  next if file.nil?
71
+
72
72
  zipfile.add(File.basename(key), file.path)
73
73
  end
74
74
  end
75
+ progress.finish(title: "Zipped keys to #{path}")
75
76
  @successful.each { |_, temp| temp.unlink }
76
77
  {
77
78
  filename: path,
data/s3_zipper.gemspec CHANGED
@@ -1,15 +1,17 @@
1
- lib = File.expand_path("../lib", __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require "s3_zipper/version"
4
6
 
5
7
  Gem::Specification.new do |spec|
6
8
  spec.name = "s3_zipper"
7
9
  spec.version = S3Zipper::VERSION
8
- spec.authors = ["Capshare", 'Nickolas Komarnitsky']
10
+ spec.authors = ["Capshare", "Nickolas Komarnitsky"]
9
11
  spec.email = [""]
10
12
 
11
- spec.summary = %q{Gem for zipping files in s3}
12
- spec.description = %q{}
13
+ spec.summary = "Gem for zipping files in s3"
14
+ spec.description = ""
13
15
  spec.homepage = "https://github.com/capshareinc/s3zipper"
14
16
  spec.license = "MIT"
15
17
 
@@ -27,7 +29,7 @@ Gem::Specification.new do |spec|
27
29
 
28
30
  # Specify which files should be added to the gem when it is released.
29
31
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
31
33
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
34
  end
33
35
  spec.bindir = "exe"
@@ -38,9 +40,11 @@ Gem::Specification.new do |spec|
38
40
  spec.add_development_dependency "rake", "~> 10.0"
39
41
  spec.add_development_dependency "rake-compiler"
40
42
  spec.add_development_dependency "rspec", "~> 3.0"
43
+ spec.add_development_dependency "rubocop", "~> 0.70.0"
41
44
  spec.add_development_dependency "simplecov"
42
45
  spec.add_development_dependency "thor"
43
- spec.add_dependency 'aws-sdk-s3', '~> 1'
44
- spec.add_dependency 'rubyzip', '>= 1.0.0'
45
- spec.add_dependency 'ruby-progressbar', '~> 1'
46
+ spec.add_dependency "aws-sdk-s3", "~> 1"
47
+ spec.add_dependency "concurrent-ruby", "~> 1.1"
48
+ spec.add_dependency "ruby-progressbar", "~> 1"
49
+ spec.add_dependency "rubyzip", ">= 1.0.0"
46
50
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s3_zipper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Capshare
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-05-08 00:00:00.000000000 Z
12
+ date: 2019-05-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -67,6 +67,20 @@ dependencies:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
69
  version: '3.0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rubocop
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: 0.70.0
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: 0.70.0
70
84
  - !ruby/object:Gem::Dependency
71
85
  name: simplecov
72
86
  requirement: !ruby/object:Gem::Requirement
@@ -110,19 +124,19 @@ dependencies:
110
124
  - !ruby/object:Gem::Version
111
125
  version: '1'
112
126
  - !ruby/object:Gem::Dependency
113
- name: rubyzip
127
+ name: concurrent-ruby
114
128
  requirement: !ruby/object:Gem::Requirement
115
129
  requirements:
116
- - - ">="
130
+ - - "~>"
117
131
  - !ruby/object:Gem::Version
118
- version: 1.0.0
132
+ version: '1.1'
119
133
  type: :runtime
120
134
  prerelease: false
121
135
  version_requirements: !ruby/object:Gem::Requirement
122
136
  requirements:
123
- - - ">="
137
+ - - "~>"
124
138
  - !ruby/object:Gem::Version
125
- version: 1.0.0
139
+ version: '1.1'
126
140
  - !ruby/object:Gem::Dependency
127
141
  name: ruby-progressbar
128
142
  requirement: !ruby/object:Gem::Requirement
@@ -137,6 +151,20 @@ dependencies:
137
151
  - - "~>"
138
152
  - !ruby/object:Gem::Version
139
153
  version: '1'
154
+ - !ruby/object:Gem::Dependency
155
+ name: rubyzip
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: 1.0.0
161
+ type: :runtime
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: 1.0.0
140
168
  description: ''
141
169
  email:
142
170
  - ''
@@ -148,6 +176,8 @@ files:
148
176
  - ".env.test"
149
177
  - ".gitignore"
150
178
  - ".rspec"
179
+ - ".rubocop.yml"
180
+ - ".rubocop_todo.yml"
151
181
  - ".ruby-version"
152
182
  - ".travis.yml"
153
183
  - CODE_OF_CONDUCT.md
@@ -162,6 +192,7 @@ files:
162
192
  - lib/s3_zipper.rb
163
193
  - lib/s3_zipper/client.rb
164
194
  - lib/s3_zipper/progress.rb
195
+ - lib/s3_zipper/spinner.rb
165
196
  - lib/s3_zipper/version.rb
166
197
  - s3_zipper.gemspec
167
198
  homepage: https://github.com/capshareinc/s3zipper