s3_download_by_date 0.2.5 → 0.2.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
  SHA1:
3
- metadata.gz: 68310667f45c318e02c4c93ab60c894782d81db9
4
- data.tar.gz: ed42d5bbb1b26a3f0bdc439111c7882c74025334
3
+ metadata.gz: d0cb9fe9de33e920a98d32abff4b1619b20b2634
4
+ data.tar.gz: e5c27d16c8924369f1d6085ba7306e79858736fa
5
5
  SHA512:
6
- metadata.gz: 0f7c905d178f11b8eb1dce2d711dcc2a9a4e6c1a1321cb8d83cbf74ec36f87a370758c078b11fe5aad07e76292ce4673c1f859c02ba18110aa4b42dd3d400db0
7
- data.tar.gz: dc201134e2a781ae61144e75eb693ffd89f5f6141cb62762966b04c4164cafe84663a430bd33c9d28361f8e80c37b4f3a04ffba62bafebbd158a6ebd4c244cfb
6
+ metadata.gz: b5e1dee76df19e6da56da6aa26294fc0849d455f31a61baf183ab8358b135008d9204c083d6ae6efd62b81d9976ffb4ce2fa61a881067999a475c1ff8d1e68d7
7
+ data.tar.gz: f5c46c57cf2d81c2bfaa3c988442994ea4045fac7a85f671476fbd426b55d1c6dad022fe00c913cee0b030e93ad04c79df453e36c23e046418fed2d1fff80f18
@@ -10,7 +10,7 @@ require 'json'
10
10
 
11
11
  class S3download::Cli < Thor
12
12
  default_task :fetch
13
- attr_accessor :s3, :debug, :files_found, :range, :target, :bucket, :from, :to
13
+ attr_accessor :s3, :debug, :files_found, :range, :target, :bucket, :from, :to, :prefix
14
14
 
15
15
  desc 'fetch', 'Download S3 files by range (date)'
16
16
  class_option :bucket, :alias => 'b', :banner => 'S3 Bucket Name'
@@ -23,12 +23,21 @@ class S3download::Cli < Thor
23
23
  class_option :verbose, :default => false, :type => :boolean
24
24
  def fetch
25
25
  raise Thor::RequiredArgumentMissingError, 'You must supply an S3 bucket name' if options[:bucket].nil?
26
- raise Thor::RequiredArgumentMissingError, 'You must supply a prefix (folder within the s3 bucket to filter by' if options[:prefix].nil?
27
26
  raise Thor::RequiredArgumentMissingError, 'You must supply a location where to save the downloaded files to' if options[:save_to].nil?
27
+
28
+ if options[:prefix].nil?
29
+ 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
30
+ say "If you're trying to script this and bypass this question, use --prefix '' (empty string)\n", color = :yellow
31
+ response = ask "Continue without a prefix? (y/n)", color = :white
32
+ exit 0 if response == 'n'
33
+ self.prefix = ''
34
+ else
35
+ self.prefix = options[:prefix]
36
+ end
37
+
28
38
  init
29
39
 
30
- ProgressBar.new("Filter Files", bucket.count) do |pbar|
31
-
40
+ ProgressBar.new("Looking for files: ", bucket.count) do |pbar|
32
41
  bucket.each do |object|
33
42
  if options[:verbose]
34
43
  say "timezone: #{options[:timezone]}"
@@ -71,7 +80,7 @@ class S3download::Cli < Thor
71
80
  def init
72
81
  aws_init
73
82
  self.debug = true if options[:verbose]
74
- self.bucket = self.s3.buckets[options[:bucket]].objects.with_prefix(options[:prefix])
83
+ self.bucket = self.s3.buckets[options[:bucket]].objects.with_prefix(self.prefix)
75
84
  self.from = Chronic.parse("#{options[:from]}").in_time_zone(options[:timezone])
76
85
  self.to = Chronic.parse("#{options[:to]}").in_time_zone(options[:timezone])
77
86
  self.range = self.from..self.to
@@ -81,26 +90,33 @@ class S3download::Cli < Thor
81
90
  FileUtils.mkdir_p "#{self.target}"
82
91
 
83
92
  File.open("#{self.target}/download_info.txt", "w") {|f|
84
- f.write("#{Time.now} - Downloaded bucket #{options[:bucket]}/#{options[:prefix]} from: #{from} - to #{to}")
93
+ f.write("#{Time.now} - Downloaded bucket #{options[:bucket]}/#{self.prefix} from: #{from} - to #{to}")
85
94
  }
86
95
 
87
96
  say "S3 Search & Download", color = :white
88
97
  say "--------------------\n", color = :white
89
- say "Bucket: #{self.bucket}", color = :cyan
98
+ say "Bucket: #{options[:bucket]}", color = :cyan
99
+ say "Prefix: #{self.prefix}", color = :cyan
90
100
  say "TimeZone: #{options[:timezone]}", color = :cyan
91
101
  say "From: #{from}", color = :cyan
92
102
  say "To: #{to}", color = :cyan
93
- say("Download target: #{options[:save_to]}/#{options[:prefix]}", color = :cyan) if options[:debug]
103
+ say("Download target: #{options[:save_to]}/#{self.prefix}", color = :cyan) if options[:debug]
94
104
  say("Range: #{self.range}", color = :green) if options[:debug]
95
105
  end
96
106
 
97
107
  def aws_init
98
- AWS.config({
108
+ config = {
99
109
  :access_key_id => ENV['AWS_ACCESS_KEY'],
100
110
  :secret_access_key => ENV['AWS_SECRET_KEY'],
101
111
  :region => ENV['REGION'] || 'us-east-1'
102
- })
112
+ }
113
+
114
+ if config[:access_key_id].nil? || config[:secret_access_key].nil?
115
+ say "You must set your AWS Secret Key and AWS Access Key Id in your environment variables", color = :red
116
+ say "export REGION='eu-west-1' (default to us-east-1)\nexport AWS_ACCESS_KEY=\"YOUR AWS KEY ID\"\nexport AWS_SECRET_KEY=\"YOUR AWS SECRET KEY\"", color = :green
117
+ exit 1
118
+ end
103
119
 
104
- self.s3 = AWS::S3.new
120
+ self.s3 = AWS::S3.new(config)
105
121
  end
106
122
  end
data/lib/s3download.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module S3download
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  ABOUT = "S3download by date v#{VERSION} (c) #{Time.now.strftime("2014-%Y")} @innovia\nFind files & folders between dates on S3 given bucket and download them"
4
4
 
5
5
  autoload :Cli, 's3download/cli'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s3_download_by_date
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ami Mahloof