Class: S3download::Cli
- Inherits:
-
Thor
- Object
- Thor
- S3download::Cli
- Defined in:
- lib/s3download/cli.rb
Instance Attribute Summary collapse
-
#bucket ⇒ Object
Returns the value of attribute bucket.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#files_found ⇒ Object
Returns the value of attribute files_found.
-
#from ⇒ Object
Returns the value of attribute from.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#range ⇒ Object
Returns the value of attribute range.
-
#s3 ⇒ Object
Returns the value of attribute s3.
-
#target ⇒ Object
Returns the value of attribute target.
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
Instance Attribute Details
#bucket ⇒ Object
Returns the value of attribute bucket.
13 14 15 |
# File 'lib/s3download/cli.rb', line 13 def bucket @bucket end |
#debug ⇒ Object
Returns the value of attribute debug.
13 14 15 |
# File 'lib/s3download/cli.rb', line 13 def debug @debug end |
#files_found ⇒ Object
Returns the value of attribute files_found.
13 14 15 |
# File 'lib/s3download/cli.rb', line 13 def files_found @files_found end |
#from ⇒ Object
Returns the value of attribute from.
13 14 15 |
# File 'lib/s3download/cli.rb', line 13 def from @from end |
#prefix ⇒ Object
Returns the value of attribute prefix.
13 14 15 |
# File 'lib/s3download/cli.rb', line 13 def prefix @prefix end |
#range ⇒ Object
Returns the value of attribute range.
13 14 15 |
# File 'lib/s3download/cli.rb', line 13 def range @range end |
#s3 ⇒ Object
Returns the value of attribute s3.
13 14 15 |
# File 'lib/s3download/cli.rb', line 13 def s3 @s3 end |
#target ⇒ Object
Returns the value of attribute target.
13 14 15 |
# File 'lib/s3download/cli.rb', line 13 def target @target end |
#to ⇒ Object
Returns the value of attribute to.
13 14 15 |
# File 'lib/s3download/cli.rb', line 13 def to @to end |
Instance Method Details
#fetch ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/s3download/cli.rb', line 24 def fetch raise Thor::RequiredArgumentMissingError, 'You must supply an S3 bucket name' if [:bucket].nil? raise Thor::RequiredArgumentMissingError, 'You must supply a location where to save the downloaded files to' if [:save_to].nil? if [:prefix].nil? say "You did not pass a --prefix option, this will scan the entire bucket and can be very slow if there too many files in that bucket\n", color = :yellow say "If you're trying to script this and bypass this question, use --prefix '' (empty string)\n", color = :yellow response = ask "Continue without a prefix? (y/n)", color = :white exit 0 if response == 'n' self.prefix = '' else self.prefix = [:prefix] end init ProgressBar.new("Looking for files: ", bucket.count) do || bucket.each do |object| if [:verbose] say "timezone: #{options[:timezone]}" say "object last modified: #{object.last_modified}" say "object last modified in timezone: #{object.last_modified.in_time_zone(options[:timezone])}" say "object falls in range: #{self.range}? => #{self.range.cover?(object.last_modified.in_time_zone(options[:timezone]))}" end if self.range.cover?(object.last_modified.in_time_zone([:timezone])) self.files_found += 1 say("Downloading #{object.key} #{object.last_modified.in_time_zone(options[:timezone])}\n", color = :white) if [:debug] FileUtils.mkdir_p "#{target}/#{object.key.match(/(.+)\//)[1]}" begin File.open("#{target}/#{object.key}", "w") do |f| f.write(object.read) end rescue Exception => e say "Unable to save file: #{e}", color = :red end end .inc end end say "Total files downloaded from S3: #{self.files_found}", color = :yellow end |
#list_timezones ⇒ Object
69 70 71 |
# File 'lib/s3download/cli.rb', line 69 def list_timezones say JSON.pretty_generate(ActiveSupport::TimeZone::MAPPING), color = :white end |
#version ⇒ Object
75 76 77 |
# File 'lib/s3download/cli.rb', line 75 def version say S3download::ABOUT end |