metric_tools 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +2 -2
  2. data/lib/metric_tools/s3.rb +11 -5
  3. 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
 
@@ -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
- remote_files = @bucket
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 && name && cond }
68
+ !is_dir && cond }
66
69
  .collect{|obj| obj.key }
67
- local_files = Dir.glob(File.join(target_dir, "**/*"))
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.include?(File.basename(key))
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
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metric_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: