mobilize-base 1.25 → 1.26
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 +4 -4
- data/lib/mobilize-base/extensions/google_drive/worksheet.rb +7 -2
- data/lib/mobilize-base/handlers/gfile.rb +1 -1
- data/lib/mobilize-base/handlers/gsheet.rb +3 -9
- data/lib/mobilize-base/models/runner.rb +2 -1
- data/lib/mobilize-base/models/stage.rb +4 -3
- data/lib/mobilize-base/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 589b56572a43097c84f63317ef02d681f7add21d
|
4
|
+
data.tar.gz: 660181a7039188861db41215c185fc1ec76244ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eafc31651c0737c1b9788f109a6a34f7afdc3af235028892d98173b03d6279e6e867a85498b08b0f4700d24320ebc3ebe43d561f1809bf94a901ae8942c53b8d
|
7
|
+
data.tar.gz: 19508e09afba3af8aea6091a26c8481a9382b905ef07ba9af8288bdcb8829e296fb684b0800206ff89d7a99b25766b76ecd827a9325ec4c75b0d156a8119a925
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module GoogleDrive
|
2
2
|
class Worksheet
|
3
|
-
def to_tsv
|
3
|
+
def to_tsv(gsub_line_breaks="\n")
|
4
4
|
sheet = self
|
5
5
|
rows = sheet.rows
|
6
6
|
header = rows.first
|
@@ -8,7 +8,12 @@ module GoogleDrive
|
|
8
8
|
#look for blank cols to indicate end of row
|
9
9
|
col_last_i = (header.index("") || header.length)-1
|
10
10
|
#ignore user-entered line breaks for purposes of tsv reads
|
11
|
-
out_tsv = rows.map
|
11
|
+
out_tsv = rows.map do |r|
|
12
|
+
row = r[0..col_last_i].join("\t")
|
13
|
+
row.gsub!("\n",gsub_line_breaks)
|
14
|
+
row = row + "\n"
|
15
|
+
row
|
16
|
+
end.join + "\n"
|
12
17
|
out_tsv.tsv_convert_dates(Mobilize::Gsheet.config['sheet_date_format'],
|
13
18
|
Mobilize::Gsheet.config['read_date_format'])
|
14
19
|
end
|
@@ -10,12 +10,10 @@ module Mobilize
|
|
10
10
|
end
|
11
11
|
|
12
12
|
# converts a source path or target path to a dst in the context of handler and stage
|
13
|
-
def Gsheet.path_to_dst(path,stage_path)
|
13
|
+
def Gsheet.path_to_dst(path,stage_path,gdrive_slot)
|
14
14
|
s = Stage.where(:path=>stage_path).first
|
15
15
|
params = s.params
|
16
16
|
target_path = params['target']
|
17
|
-
#take random slot if one is not available
|
18
|
-
gdrive_slot = Gdrive.slot_worker_by_path(stage_path) || Gdrive.worker_emails.sort_by{rand}.first
|
19
17
|
#if this is the target, it doesn't have to exist already
|
20
18
|
is_target = true if path == target_path
|
21
19
|
#don't need the ://
|
@@ -46,9 +44,7 @@ module Mobilize
|
|
46
44
|
|
47
45
|
def Gsheet.read_by_dataset_path(dst_path,user_name,*args)
|
48
46
|
#expects gdrive slot as first arg, otherwise chooses random
|
49
|
-
gdrive_slot = args
|
50
|
-
worker_emails = Gdrive.worker_emails.sort_by{rand}
|
51
|
-
gdrive_slot = worker_emails.first unless worker_emails.include?(gdrive_slot)
|
47
|
+
gdrive_slot = args.to_a.first
|
52
48
|
sheet = Gsheet.find_by_path(dst_path,gdrive_slot)
|
53
49
|
sheet.read(user_name) if sheet
|
54
50
|
end
|
@@ -56,8 +52,6 @@ module Mobilize
|
|
56
52
|
def Gsheet.write_by_dataset_path(dst_path,tsv,user_name,*args)
|
57
53
|
#expects gdrive slot as first arg, otherwise chooses random
|
58
54
|
gdrive_slot,crop = args
|
59
|
-
worker_emails = Gdrive.worker_emails.sort_by{rand}
|
60
|
-
gdrive_slot = worker_emails.first unless worker_emails.include?(gdrive_slot)
|
61
55
|
crop ||= true
|
62
56
|
Gsheet.write_target(dst_path,tsv,user_name,gdrive_slot,crop)
|
63
57
|
end
|
@@ -134,7 +128,7 @@ module Mobilize
|
|
134
128
|
crop = s.params['crop'] || true
|
135
129
|
begin
|
136
130
|
#get tsv to write from stage
|
137
|
-
source = s.sources.first
|
131
|
+
source = s.sources(gdrive_slot).first
|
138
132
|
raise "Need source for gsheet write" unless source
|
139
133
|
tsv = source.read(u.name,gdrive_slot)
|
140
134
|
raise "No data source found for #{source.url}" unless tsv
|
@@ -101,7 +101,8 @@ module Mobilize
|
|
101
101
|
|
102
102
|
def read_gsheet(gdrive_slot)
|
103
103
|
r = self
|
104
|
-
|
104
|
+
#argument converts line breaks in cells to spaces
|
105
|
+
gsheet_tsv = r.gsheet(gdrive_slot).to_tsv(" ")
|
105
106
|
#turn it into a hash array
|
106
107
|
gsheet_jobs = gsheet_tsv.tsv_to_hash_array
|
107
108
|
#go through each job, update relevant job with its params
|
@@ -212,14 +212,15 @@ module Mobilize
|
|
212
212
|
raise "incompatible target handler #{handler} for #{s.handler} stage"
|
213
213
|
else
|
214
214
|
begin
|
215
|
-
|
215
|
+
#nil gdrive_slot for targets since there is no verification
|
216
|
+
return "Mobilize::#{s.handler.downcase.capitalize}".constantize.path_to_dst(target_path,s.path,nil)
|
216
217
|
rescue => exc
|
217
218
|
raise "Could not get #{target_path} with error: #{exc.to_s}"
|
218
219
|
end
|
219
220
|
end
|
220
221
|
end
|
221
222
|
|
222
|
-
def sources
|
223
|
+
def sources(gdrive_slot)
|
223
224
|
#returns an array of Datasets corresponding to
|
224
225
|
#items listed as sources in the stage params
|
225
226
|
s = self
|
@@ -248,7 +249,7 @@ module Mobilize
|
|
248
249
|
end
|
249
250
|
begin
|
250
251
|
stage_path = s.path
|
251
|
-
dsts << "Mobilize::#{handler.downcase.capitalize}".constantize.path_to_dst(source_path,stage_path)
|
252
|
+
dsts << "Mobilize::#{handler.downcase.capitalize}".constantize.path_to_dst(source_path,stage_path,gdrive_slot)
|
252
253
|
rescue => exc
|
253
254
|
raise "Could not get #{source_path} with error: #{exc.to_s}"
|
254
255
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mobilize-base
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.26'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cassio Paes-Leme
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-03-
|
11
|
+
date: 2013-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|