tumugi-plugin-google_drive 0.2.0 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 813453c81708108b539ff741428030f1d4c431b0
4
- data.tar.gz: eab95dcf2f132a73ce6af6318a74df13f4d3afc1
3
+ metadata.gz: 6299d3432c8ea64f32980e96034eedd84ba7ccd9
4
+ data.tar.gz: 24be0abafa651a00fb408bb5efcd791ddedc4028
5
5
  SHA512:
6
- metadata.gz: d1e9252df8992ed4ec76150d8a3e1a6c3bf4ba59ca0bca17579daa2bab84e61b9e5bd81fa01e22455318f07b8b830710f1434f95c1c70be578ad5f60a7273fe6
7
- data.tar.gz: ce205a1b015a4852280cde6feb9600f9e11383c8340e7d70da12740afcc54e4a832efee61942fa0936e0f54bd40bbf638d4ea5680240fa8894adc7e147d960c3
6
+ metadata.gz: 4efc5aa4b66a9c81fb01b200290dacb44165e8a2b4390881678f10c8263b846de3733f82af1171cc39420c7a517cd3edfdd69c17ea3eb995784131176cdb517a
7
+ data.tar.gz: 02d61db00ff93d161899a39f5e53bf99fcc85561289b6e538976aa73d4b16f1ba8bedb68a81bd3c7a79723b1310fb9269fc41d96a9391dcf967f3cdf5e5c0eeb
@@ -1,10 +1,18 @@
1
1
  # Change Log
2
2
 
3
- ## [v0.2.0](https://github.com/tumugi/tumugi-plugin-google_drive/tree/v0.2.0) (2016-07-19)
3
+ ## [v0.3.0](https://github.com/tumugi/tumugi-plugin-google_drive/tree/v0.3.0) (2016-08-02)
4
+ [Full Changelog](https://github.com/tumugi/tumugi-plugin-google_drive/compare/v0.2.0...v0.3.0)
5
+
6
+ **Implemented enhancements:**
7
+
8
+ - \[Breaking Change\] Support match by name [\#12](https://github.com/tumugi/tumugi-plugin-google_drive/pull/12) ([hakobera](https://github.com/hakobera))
9
+
10
+ ## [v0.2.0](https://github.com/tumugi/tumugi-plugin-google_drive/tree/v0.2.0) (2016-07-18)
4
11
  [Full Changelog](https://github.com/tumugi/tumugi-plugin-google_drive/compare/v0.1.0...v0.2.0)
5
12
 
6
13
  **Merged pull requests:**
7
14
 
15
+ - Prepare release for 0.2.0 [\#11](https://github.com/tumugi/tumugi-plugin-google_drive/pull/11) ([hakobera](https://github.com/hakobera))
8
16
  - Update README [\#10](https://github.com/tumugi/tumugi-plugin-google_drive/pull/10) ([hakobera](https://github.com/hakobera))
9
17
  - Update tumugi to 0.6 [\#9](https://github.com/tumugi/tumugi-plugin-google_drive/pull/9) ([hakobera](https://github.com/hakobera))
10
18
 
@@ -1,19 +1,22 @@
1
1
  task :task1 do
2
2
  param :day, type: :time, auto_bind: true, required: true
3
+ param :seed, type: :string, auto_bind: true, required: true
4
+
3
5
  requires :folder
4
6
 
5
7
  output do
6
8
  target(:google_drive_file,
7
- name: "test_#{day.strftime('%Y%m%d')}.txt",
9
+ name: "test_#{day.strftime('%Y%m%d%H%M')}_#{seed}.txt",
8
10
  parents: input.folder_id)
9
11
  end
10
12
 
11
13
  run do
12
- log 'task1#run'
13
- output.open('w') {|f| f.puts('done') }
14
+ log "task1#run"
15
+ output.open("w") {|f| f.puts("done") }
14
16
  end
15
17
  end
16
18
 
17
19
  task :folder, type: :google_drive_folder do
18
- name 'xyz'
20
+ param :day, type: :time, auto_bind: true, required: true
21
+ name { "folder_#{day.strftime('%Y%m%d%H%M')}" }
19
22
  end
@@ -113,6 +113,14 @@ module Tumugi
113
113
  process_error($!)
114
114
  end
115
115
 
116
+ def list_files(query:, order_by: "name", spaces: "drive", fields: "next_page_token, files(id, name, parents, mime_type)", page_size: 100, page_token: nil)
117
+ # https://developers.google.com/drive/v3/reference/files/list
118
+ # https://developers.google.com/drive/v3/web/search-parameters
119
+ client.list_files(q: query, order_by: order_by, spaces: spaces, fields: fields, page_size: page_size, page_token: page_token)
120
+ rescue
121
+ process_error($!)
122
+ end
123
+
116
124
  private
117
125
 
118
126
  def save_config(config)
@@ -11,12 +11,12 @@ module Tumugi
11
11
 
12
12
  attr_reader :file_id, :name, :parents
13
13
 
14
- def initialize(file_id: nil, name: nil, parents: nil, fs: nil)
14
+ def initialize(file_id: nil, name:, parents: nil, fs: nil)
15
15
  @fs = fs unless fs.nil?
16
- @file_id = file_id || self.fs.generate_file_id
16
+ @file_id = file_id
17
17
  @name = name
18
18
  @parents = parents
19
- super(@file_id)
19
+ super(file_id)
20
20
  end
21
21
 
22
22
  def fs
@@ -25,18 +25,26 @@ module Tumugi
25
25
 
26
26
  def open(mode="r", &block)
27
27
  if mode.include? 'r'
28
+ if file_id.nil?
29
+ file = find_by_name(name)
30
+ @file_id = file.id unless file.nil?
31
+ end
28
32
  fs.download(file_id, mode: mode, &block)
29
33
  elsif mode.include? 'w'
30
- file = Tumugi::Plugin::GoogleDrive::AtomicFile.new(name, fs, file_id: @file_id, parents: @parents)
34
+ file = Tumugi::Plugin::GoogleDrive::AtomicFile.new(name, fs, file_id: file_id, parents: @parents)
31
35
  file.open(&block)
32
36
  @file_id = file.id
33
37
  else
34
- raise Tumugi::TumugiError.new('Invalid mode: #{mode}')
38
+ raise Tumugi::TumugiError.new("Invalid mode: #{mode}")
35
39
  end
36
40
  end
37
41
 
38
42
  def exist?
39
- fs.exist?(file_id)
43
+ if file_id
44
+ fs.exist?(file_id)
45
+ else
46
+ !!find_by_name(name)
47
+ end
40
48
  end
41
49
 
42
50
  def to_s
@@ -44,6 +52,29 @@ module Tumugi
44
52
  s += ", parents: #{parents}" if parents
45
53
  s
46
54
  end
55
+
56
+ private
57
+
58
+ def find_by_name(n)
59
+ query = "name='#{n}'"
60
+ ps = parents
61
+ if parents.is_a?(String)
62
+ ps = [parents]
63
+ end
64
+ if parents
65
+ query += " and ("
66
+ query += "#{ps.map{|p| "'#{p}' in parents"}.join(" or ")}"
67
+ query += ")"
68
+ end
69
+ files = fs.list_files(query: query, page_size: 2).files
70
+ if files.size == 0
71
+ nil
72
+ elsif files.size == 1
73
+ files.first
74
+ else
75
+ raise Tumugi::TumugiError.new("Multiple files find for query: #{query}")
76
+ end
77
+ end
47
78
  end
48
79
  end
49
80
  end
@@ -9,9 +9,9 @@ module Tumugi
9
9
 
10
10
  attr_reader :folder_id, :name, :parents
11
11
 
12
- def initialize(folder_id: nil, name: nil, parents: nil, fs: nil)
12
+ def initialize(folder_id: nil, name:, parents: nil, fs: nil)
13
13
  @fs = fs unless fs.nil?
14
- @folder_id = folder_id || self.fs.generate_file_id
14
+ @folder_id = folder_id
15
15
  @name = name
16
16
  @parents = parents
17
17
  end
@@ -21,7 +21,17 @@ module Tumugi
21
21
  end
22
22
 
23
23
  def exist?
24
- fs.exist?(folder_id)
24
+ if folder_id
25
+ fs.exist?(folder_id)
26
+ else
27
+ !!find_by_name(name)
28
+ end
29
+ end
30
+
31
+ def mkdir
32
+ fid = folder_id || fs.generate_file_id
33
+ fs.mkdir(name, folder_id: fid, parents: parents)
34
+ @folder_id = fid
25
35
  end
26
36
 
27
37
  def to_s
@@ -29,6 +39,29 @@ module Tumugi
29
39
  s += ", parents: #{parents}" if parents
30
40
  s
31
41
  end
42
+
43
+ private
44
+
45
+ def find_by_name(n)
46
+ query = "name='#{n}'"
47
+ ps = parents
48
+ if parents.is_a?(String)
49
+ ps = [parents]
50
+ end
51
+ if parents
52
+ query += " and ("
53
+ query += "#{ps.map{|p| "'#{p}' in parents"}.join(" or ")}"
54
+ query += ") and mime_type = '#{Tumugi::Plugin::GoogleDrive::FileSystem::MIME_TYPE_FOLDER}'"
55
+ end
56
+ files = fs.list_files(query: query, page_size: 2).files
57
+ if files.size == 0
58
+ nil
59
+ elsif files.size == 1
60
+ files.first
61
+ else
62
+ raise Tumugi::TumugiError.new("Multiple files find for query: #{query}")
63
+ end
64
+ end
32
65
  end
33
66
  end
34
67
  end
@@ -19,7 +19,7 @@ module Tumugi
19
19
  log "skip: #{output} is already exists"
20
20
  else
21
21
  log "create folder: #{output}"
22
- output.fs.mkdir(name, folder_id: output.folder_id, parents: output.parents)
22
+ output.mkdir
23
23
  end
24
24
  end
25
25
  end
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "tumugi-plugin-google_drive"
7
- spec.version = "0.2.0"
7
+ spec.version = "0.3.0"
8
8
  spec.authors = ["Kazuyuki Honda"]
9
9
  spec.email = ["hakobera@gmail.com"]
10
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tumugi-plugin-google_drive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuyuki Honda
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-18 00:00:00.000000000 Z
11
+ date: 2016-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tumugi