bucket_list 0.3.1 → 0.4.0
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/bin/bucket_list +11 -1
- data/config/config.yml +1 -1
- data/lib/bucket_list/app.rb +16 -0
- data/lib/bucket_list/aws_helper.rb +12 -5
- metadata +4 -4
data/bin/bucket_list
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
begin
|
4
4
|
require 'bucket_list'
|
5
5
|
rescue LoadError
|
6
|
-
# Cucumber seems to need this
|
7
6
|
$:.unshift "#{File.dirname(__FILE__)}/../lib/"
|
8
7
|
$:.unshift "#{File.dirname(__FILE__)}/../lib/bucket_list/"
|
9
8
|
require 'bucket_list'
|
@@ -40,6 +39,10 @@ option_parser = OptionParser.new do |opts|
|
|
40
39
|
options[:upload] = hash
|
41
40
|
end
|
42
41
|
|
42
|
+
opts.on('-t', '--download BUCKET_NAME:FILE', Hash, 'Download FILE from BUCKET_NAME') do |hash|
|
43
|
+
options[:download] = hash
|
44
|
+
end
|
45
|
+
|
43
46
|
opts.on("-o ", "--objects BUCKET_NAME", "Show contents of BUCKET_NAME") do |bucket_name|
|
44
47
|
options[:show_contents] = bucket_name.to_s
|
45
48
|
end
|
@@ -107,6 +110,13 @@ if options[:upload]
|
|
107
110
|
end
|
108
111
|
end
|
109
112
|
|
113
|
+
if options[:download]
|
114
|
+
options[:download].each_pair do |bucket_name, file|
|
115
|
+
puts "[INFO] Downloading '#{file}' from the '#{bucket_name}' bucket"
|
116
|
+
bucket_list.download(bucket_name, file)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
110
120
|
if options[:version]
|
111
121
|
puts "[INFO] bucket_list version: #{bucket_list.settings['version']}"
|
112
122
|
end
|
data/config/config.yml
CHANGED
data/lib/bucket_list/app.rb
CHANGED
@@ -69,6 +69,22 @@ class BucketList
|
|
69
69
|
}
|
70
70
|
end
|
71
71
|
|
72
|
+
def download(bucket_name, file, local_path="./")
|
73
|
+
bucket = @s3.buckets[bucket_name]
|
74
|
+
|
75
|
+
if bucket_contains_object?(bucket_name, file)
|
76
|
+
File.open("#{local_path}#{file}", 'w') do |f|
|
77
|
+
make_request {
|
78
|
+
bucket.objects[file].read do |chunk|
|
79
|
+
f.write(chunk)
|
80
|
+
end
|
81
|
+
}
|
82
|
+
end
|
83
|
+
else
|
84
|
+
puts "[ERROR] Sorry, a file named '#{file}' does not exist"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
72
88
|
def get_bucket_contents(bucket_name)
|
73
89
|
bucket_contents = Array.new
|
74
90
|
if bucket_exists?(bucket_name)
|
@@ -1,4 +1,9 @@
|
|
1
1
|
module AwsHelper
|
2
|
+
|
3
|
+
def log(level="INFO", message)
|
4
|
+
puts "[#{level}] #{message}"
|
5
|
+
end
|
6
|
+
|
2
7
|
def make_request
|
3
8
|
done = false
|
4
9
|
attempts = 0
|
@@ -8,26 +13,28 @@ module AwsHelper
|
|
8
13
|
begin
|
9
14
|
yield
|
10
15
|
done = true
|
11
|
-
|
16
|
+
log("Done")
|
12
17
|
rescue AWS::S3::Errors::NoSuchBucket => error
|
13
18
|
if attempts == 0
|
14
|
-
|
19
|
+
log("ERROR", "#{error}")
|
15
20
|
end
|
16
21
|
puts "[INFO] Trying again... (#{attempts.to_i + 1}/#{max_attempts})"
|
17
22
|
attempts = attempts + 1
|
18
23
|
sleep 1
|
19
24
|
next
|
20
25
|
rescue AWS::S3::Errors::BucketAlreadyExists => error
|
21
|
-
|
26
|
+
log("ERROR", "#{error}")
|
22
27
|
exit 1
|
23
28
|
rescue AWS::S3::Errors::AccessDenied => error
|
24
|
-
|
29
|
+
log("ERROR", "#{error}")
|
25
30
|
exit 1
|
31
|
+
rescue => msg
|
32
|
+
log("ERROR", msg)
|
26
33
|
end
|
27
34
|
end
|
28
35
|
|
29
36
|
if attempts >= max_attempts
|
30
|
-
|
37
|
+
log("ERROR", "Max no. of attempts reached")
|
31
38
|
exit 1
|
32
39
|
end
|
33
40
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bucket_list
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-sdk
|
@@ -60,7 +60,7 @@ dependencies:
|
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 0.4.11
|
62
62
|
description: bucket_list is a simple command line tool that can be used to manage
|
63
|
-
and
|
63
|
+
and transfer files to/from AWS S3 buckets.
|
64
64
|
email: ed@victavision.co.uk
|
65
65
|
executables:
|
66
66
|
- bucket_list
|
@@ -73,7 +73,7 @@ files:
|
|
73
73
|
- config/config.yml
|
74
74
|
- config/aws_config.yml
|
75
75
|
- bin/bucket_list
|
76
|
-
homepage: http://
|
76
|
+
homepage: http://ted.victavision.co.uk/article/3
|
77
77
|
licenses: []
|
78
78
|
post_install_message:
|
79
79
|
rdoc_options: []
|