metric_tools 0.0.2 → 0.0.3
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/README.md +2 -2
- data/lib/metric_tools/s3.rb +11 -5
- metadata +1 -1
data/README.md
CHANGED
@@ -25,10 +25,10 @@
|
|
25
25
|
### S3
|
26
26
|
|
27
27
|
S3.login('Access_Key', 'secret_key~~', 'bucket-name!')
|
28
|
-
S3.fetch_all('logs/retention_rate', 'User/masaori/Desktop/') #fetch all files in specified s3 directory
|
28
|
+
S3.fetch_all('logs/retention_rate', '/User/masaori/Desktop/') #fetch all files in specified s3 directory
|
29
29
|
|
30
30
|
# You can give a condition.
|
31
|
-
S3.fetch_all('logs/retention_rate, 'User/masaori/Desktop/') {|f| f.name.include? ".rb" } #Download all ".rb" files
|
31
|
+
S3.fetch_all('logs/retention_rate, '/User/masaori/Desktop/') {|f| f.name.include? ".rb" } #Download all ".rb" files
|
32
32
|
|
33
33
|
### Skype
|
34
34
|
|
data/lib/metric_tools/s3.rb
CHANGED
@@ -19,6 +19,8 @@ module MetricTools
|
|
19
19
|
@secret = secret
|
20
20
|
@bucket_name = bucket_name
|
21
21
|
|
22
|
+
puts "Login to #{bucket_name} .."
|
23
|
+
|
22
24
|
AWS::S3::Base.establish_connection!(
|
23
25
|
:access_key_id => key,
|
24
26
|
:secret_access_key => secret,
|
@@ -56,18 +58,22 @@ module MetricTools
|
|
56
58
|
# force_all=falseにすると、既にローカルにファイルが有る場合はDLしません。
|
57
59
|
#
|
58
60
|
def fetch_all(dir_key, target_dir, force_all=false, &condition)
|
59
|
-
|
61
|
+
objects_in_dir = @bucket.objects(prefix: dir_key)
|
62
|
+
remote_files = objects_in_dir
|
60
63
|
.select{|obj|
|
64
|
+
puts obj.key
|
61
65
|
key = obj.key
|
62
66
|
is_dir = (key[key.length-1] == '/')
|
63
|
-
name = key.include? dir_key
|
64
67
|
cond = condition.nil? ? true : condition.call(obj)
|
65
|
-
!is_dir &&
|
68
|
+
!is_dir && cond }
|
66
69
|
.collect{|obj| obj.key }
|
67
|
-
|
70
|
+
Dir.chdir(target_dir)
|
71
|
+
local_files = Dir["**/*"]
|
72
|
+
|
73
|
+
puts "remote directory is empty => #{@bucket.name}/#{dir_key}" if @remote_files.empty?
|
68
74
|
|
69
75
|
remote_files.each {|key|
|
70
|
-
if force_all || !local_files.
|
76
|
+
if force_all || !local_files.any?{|f| File.basename(f) == File.basename(key)}
|
71
77
|
download(key, target_dir, true)
|
72
78
|
end
|
73
79
|
}
|