takenoko-s3 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/takenoko/s3/attach_helper.rb +24 -3
- data/lib/takenoko/s3/takenoko.rb +14 -2
- data/lib/takenoko/s3/version.rb +1 -1
- data/takenoko-s3.gemspec +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6922c02010745f12516ecedde82d5d58b28528d
|
4
|
+
data.tar.gz: 0d21656bde5a035f48bc594f634179325d20020d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7682d01f2a68bb3f78292495dd552494df603c43afad03780514882bec670c168c6663fc08754922145e0d89df04c5c6622c5c975c81119438884174c74e29c
|
7
|
+
data.tar.gz: 826600fc19787eb2ab050b9bf3fbb833d2fcba077e95ea0112dc10abb9818b7c4a3f7760cb696c5043c9b042f064565deb5d7cfdf3d1adb0cffa7e9d2d30cd31
|
@@ -2,29 +2,50 @@ module Takenoko
|
|
2
2
|
module AttachHelper
|
3
3
|
extend self
|
4
4
|
def upload_to_s3(table_data)
|
5
|
+
errors = []
|
5
6
|
return false unless table_data[:to_s3].present?
|
6
7
|
raise 'bucket must be set' if table_data[:bucket].blank?
|
7
8
|
raise 'attach_files empty' if table_data[:attach_files].blank?
|
8
9
|
raise "Bucket not found:#{table_data[:bucket]}" unless bucket = Takenoko.s3.client.bucket(table_data[:bucket])
|
9
10
|
|
11
|
+
table_name = table_data[:table_name]
|
12
|
+
takelog = "#{Takenoko.log_folder}/#{table_name}_log.yml"
|
13
|
+
log_data = (File.exist?(takelog) && YAML.load_file(takelog)) || {}
|
14
|
+
|
10
15
|
table_data[:attach_files].each do |col|
|
11
16
|
next unless col[:to_s3].present?
|
12
17
|
table_data[:rows].each do |row|
|
13
18
|
next if row[col[:column_name]].blank?
|
14
19
|
file_path = col[:download_location] + '/' + File.basename(row[col[:column_name]])
|
15
20
|
unless File.file?(file_path)
|
16
|
-
|
21
|
+
errors << "Table[#{table_data[:table_name]}]File not found: #{file_path}"
|
22
|
+
next
|
17
23
|
end
|
24
|
+
|
18
25
|
file = File.open(file_path)
|
19
26
|
s3_path = col[:s3_folder]+ "/" + File.basename(row[col[:column_name]])
|
27
|
+
|
28
|
+
find_val = row[table_data[:find_column]]
|
29
|
+
|
30
|
+
if log_data[find_val].present? && (f = bucket.files.get(s3_path))
|
31
|
+
next if log_data[find_val][:s3_last_upload] && log_data[find_val][:s3_last_upload] >= file.mtime.to_i
|
32
|
+
end
|
33
|
+
|
20
34
|
Rails.logger.info "Uploading to s3: #{file_path} -> #{s3_path}"
|
21
|
-
bucket.files.create({
|
35
|
+
f = bucket.files.create({
|
22
36
|
key: s3_path,
|
23
37
|
body: file,
|
24
|
-
public: col[:s3_public]
|
38
|
+
public: col[:s3_public],
|
25
39
|
})
|
40
|
+
|
41
|
+
log_data[find_val] ||= {}
|
42
|
+
log_data[find_val][:s3_last_upload] = file.mtime.to_i
|
26
43
|
end
|
27
44
|
end
|
45
|
+
|
46
|
+
File.open(takelog, 'w') {|f| f.write log_data.to_yaml }
|
47
|
+
|
48
|
+
raise errors.join("\n") unless errors.empty?
|
28
49
|
return true
|
29
50
|
end
|
30
51
|
end
|
data/lib/takenoko/s3/takenoko.rb
CHANGED
@@ -11,10 +11,16 @@ module Takenoko
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def upload_all_to_s3
|
14
|
+
errors = []
|
14
15
|
mapping_config[:tables].each do |table,conf|
|
15
16
|
next if conf[:attach_files].blank?
|
16
|
-
|
17
|
+
begin
|
18
|
+
upload_table_to_s3 table
|
19
|
+
rescue Exception => e
|
20
|
+
errors << e.to_s
|
21
|
+
end
|
17
22
|
end
|
23
|
+
raise errors.join("\n") unless errors.empty?
|
18
24
|
return true
|
19
25
|
end
|
20
26
|
|
@@ -26,10 +32,16 @@ module Takenoko
|
|
26
32
|
end
|
27
33
|
|
28
34
|
def download_and_upload_all_to_s3
|
35
|
+
errors = []
|
29
36
|
mapping_config[:tables].each do |table,conf|
|
30
37
|
next if conf[:attach_files].blank?
|
31
|
-
|
38
|
+
begin
|
39
|
+
download_and_upload_table_to_s3 table
|
40
|
+
rescue Exception => e
|
41
|
+
errors << e.to_s
|
42
|
+
end
|
32
43
|
end
|
44
|
+
raise errors.join("\n") unless errors.empty?
|
33
45
|
return true
|
34
46
|
end
|
35
47
|
end
|
data/lib/takenoko/s3/version.rb
CHANGED
data/takenoko-s3.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
|
12
12
|
spec.summary = %q{S3 Uploader plugin for takenoko}
|
13
13
|
spec.description = %q{S3 Uploader plugin for takenoko}
|
14
|
-
spec.homepage = "https://github.com/khiemns54/takenoko-s3/tree/release/0.0.
|
14
|
+
spec.homepage = "https://github.com/khiemns54/takenoko-s3/tree/release/0.0.6"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.12"
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
24
|
spec.add_development_dependency "minitest", "~> 5.0"
|
25
|
-
spec.add_dependency "takenoko", "~> 0.2.
|
25
|
+
spec.add_dependency "takenoko", "~> 0.2.5"
|
26
26
|
spec.add_dependency "fog-aws"
|
27
27
|
|
28
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: takenoko-s3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- KhiemNS
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.2.
|
61
|
+
version: 0.2.5
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.2.
|
68
|
+
version: 0.2.5
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: fog-aws
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -104,7 +104,7 @@ files:
|
|
104
104
|
- lib/takenoko/s3/tasks/takenoko.rake
|
105
105
|
- lib/takenoko/s3/version.rb
|
106
106
|
- takenoko-s3.gemspec
|
107
|
-
homepage: https://github.com/khiemns54/takenoko-s3/tree/release/0.0.
|
107
|
+
homepage: https://github.com/khiemns54/takenoko-s3/tree/release/0.0.6
|
108
108
|
licenses:
|
109
109
|
- MIT
|
110
110
|
metadata: {}
|