etna 0.1.26 → 0.1.27

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7075c5bf9637903a5aae31e83dbec99fc903945b362b5b454a3d31f95c03c6eb
4
- data.tar.gz: 48e957e8286a613f7a1cafab2512976e625211782ae09a402053161af0f69b87
3
+ metadata.gz: 99facdcccd4282d230f93f3ccd779af9f5f58878c5a33e2be0209e95b715a88e
4
+ data.tar.gz: b56796ac6f84ec988a07275bdaf78d14d12409cf7c3b0a4d2b8b30c0009d8130
5
5
  SHA512:
6
- metadata.gz: 850effed7485f90957cb3ee53ebb97abaa3fe9c32d9de9ff16c5d30585b61f34ccf00bb88c702ee9f1271c8a883526cebc36218904c311c276d6de51aca0d1ba
7
- data.tar.gz: 1c90072a96341cf75b869d08f9e1cd1e36c2a616873048d83c6c1cd2ffe57850c618745c80ee1e16e63c2c8c4c090cbb8c99ab19ed1541ec06d8b43d29824d0a
6
+ metadata.gz: c4a505a48d40c6ed15a97810002809260d43f9420c9339d5a00c6c78957430751cfa609312e99d6c50346cb0ebad300cc7bb6fbba12fde602e43005981556eab
7
+ data.tar.gz: 3edfd8838451970ed00a470c6b843a0e4b166c31ed7bb67eb2a8a1ce42c217414e6c92776aa4d4db2e0fa0cc2c27f50e2b05b339a28f4893c9137ec71ff8e2ff
@@ -499,10 +499,10 @@ COMPREPLY=($(compgen -W "$all_completion_names" -- "$1"))
499
499
  return
500
500
  fi
501
501
  shift
502
- all_flag_completion_names="$all_flag_completion_names --commit --models --record_names "
503
- string_flag_completion_names="$string_flag_completion_names --models --record_names "
502
+ all_flag_completion_names="$all_flag_completion_names --commit --models --mode "
503
+ string_flag_completion_names="$string_flag_completion_names --models --mode "
504
504
  declare _completions_for_models="__models__"
505
- declare _completions_for_record_names="__record_names__"
505
+ declare _completions_for_mode="__mode__"
506
506
  while [[ "$#" != "0" ]]; do
507
507
  if [[ "$#" == "1" ]]; then
508
508
  all_completion_names=""
@@ -351,16 +351,16 @@ class EtnaApp
351
351
 
352
352
  boolean_flags << '--commit'
353
353
  string_flags << '--models'
354
- string_flags << '--record_names'
354
+ string_flags << '--mode'
355
355
 
356
- def execute(project_name, redcap_tokens, models: "all", record_names: nil, commit: false)
356
+ def execute(project_name, redcap_tokens, models: "all", mode: nil, commit: false)
357
357
  raise "Must provide at least one REDCap token (comma-separated)." unless redcap_tokens.split(',').length > 0
358
358
 
359
359
  puts "NOTE: This is a **preview** of what the data loading will look like. Use the --commit flag to load records into Magma." unless commit
360
360
 
361
361
  polyphemus_client.job(Etna::Clients::Polyphemus::RedcapJobRequest.new(
362
362
  model_names: "all" == models ? "all" : models.split(','),
363
- record_names: nil == record_names || "existing" == record_names ? record_names : record_names.split(','),
363
+ mode: mode,
364
364
  redcap_tokens: redcap_tokens.split(','),
365
365
  project_name: project_name,
366
366
  commit: commit
@@ -10,7 +10,7 @@ module Etna
10
10
  :metis_client, :magma_client, :project_name,
11
11
  :model_name, :model_filters, :model_attributes_mask,
12
12
  :filesystem, :logger, :stub_files,
13
- keyword_init: true)
13
+ :skip_tmpdir, keyword_init: true)
14
14
 
15
15
  def initialize(**kwds)
16
16
  super(**({filesystem: Etna::Filesystem.new}.update(kwds)))
@@ -24,8 +24,8 @@ module Etna
24
24
  @model_walker ||= WalkModelTreeWorkflow.new(magma_crud: magma_crud, logger: logger)
25
25
  end
26
26
 
27
- def materialize_all(dest = filesystem.tmpdir)
28
- tmpdir = filesystem.tmpdir
27
+ def materialize_all(dest)
28
+ tmpdir = skip_tmpdir ? nil : filesystem.tmpdir
29
29
 
30
30
  begin
31
31
  model_walker.walk_from(
@@ -37,7 +37,7 @@ module Etna
37
37
  materialize_record(dest, tmpdir, template, document)
38
38
  end
39
39
  ensure
40
- filesystem.rm_rf(tmpdir)
40
+ filesystem.rm_rf(tmpdir) unless skip_tmpdir
41
41
  end
42
42
  end
43
43
 
@@ -78,6 +78,7 @@ module Etna
78
78
  @sync_metis_data_workflow ||= Etna::Clients::Metis::SyncMetisDataWorkflow.new(
79
79
  metis_client: metis_client,
80
80
  logger: logger,
81
+ skip_tmpdir: skip_tmpdir,
81
82
  filesystem: filesystem)
82
83
  end
83
84
 
@@ -6,9 +6,10 @@ require 'tempfile'
6
6
  module Etna
7
7
  module Clients
8
8
  class Metis
9
- class SyncMetisDataWorkflow < Struct.new(:metis_client, :filesystem, :project_name, :bucket_name, :logger, keyword_init: true)
9
+ class SyncMetisDataWorkflow < Struct.new(:metis_client, :filesystem, :project_name, :bucket_name,
10
+ :logger, :skip_tmpdir, keyword_init: true)
10
11
  def copy_directory(src, dest, root = dest, tmpdir = nil)
11
- own_tmpdir = tmpdir.nil?
12
+ own_tmpdir = tmpdir.nil? && !skip_tmpdir
12
13
  if own_tmpdir
13
14
  tmpdir = filesystem.tmpdir
14
15
  end
@@ -33,6 +34,17 @@ module Etna
33
34
  "bin/#{etag}"
34
35
  end
35
36
 
37
+ def with_maybe_intermediate_tmp_dest(bin_file_name:, tmpdir:, dest_file_name:, &block)
38
+ filesystem.mkdir_p(::File.dirname(dest_file_name))
39
+ if tmpdir.nil?
40
+ yield dest_file_name
41
+ else
42
+ tmp_file = ::File.join(tmpdir, ::File.basename(bin_file_name))
43
+ yield tmp_file
44
+ filesystem.mv(tmp_file, dest_file_name)
45
+ end
46
+ end
47
+
36
48
  def copy_file(bin_root_dir:, tmpdir:, dest:, url:, stub: false)
37
49
  metadata = metis_client.file_metadata(url)
38
50
  etag = metadata[:etag]
@@ -44,56 +56,52 @@ module Etna
44
56
  return
45
57
  end
46
58
 
47
- tmp_file = ::File.join(tmpdir, etag)
48
-
49
-
50
- upload_timings = []
51
- upload_amount = 0
52
- last_rate = 0.00001
59
+ with_maybe_intermediate_tmp_dest(bin_file_name: dest_bin_file, tmpdir: tmpdir, dest_file_name: dest) do |tmp_file|
60
+ upload_timings = []
61
+ upload_amount = 0
62
+ last_rate = 0.00001
53
63
 
54
- filesystem.with_writeable(tmp_file, "w", size_hint: size) do |io|
55
- if stub
56
- io.write("(stub) #{size} bytes")
57
- else
58
- metis_client.download_file(url) do |chunk|
59
- io.write(chunk)
64
+ filesystem.with_writeable(tmp_file, "w", size_hint: size) do |io|
65
+ if stub
66
+ io.write("(stub) #{size} bytes")
67
+ else
68
+ metis_client.download_file(url) do |chunk|
69
+ io.write(chunk)
60
70
 
61
- upload_timings << [chunk.length, Time.now.to_f]
62
- upload_amount += chunk.length
71
+ upload_timings << [chunk.length, Time.now.to_f]
72
+ upload_amount += chunk.length
63
73
 
64
- if upload_timings.length > 150
65
- s, _ = upload_timings.shift
66
- upload_amount -= s
67
- end
74
+ if upload_timings.length > 150
75
+ s, _ = upload_timings.shift
76
+ upload_amount -= s
77
+ end
68
78
 
69
- _, start_time = upload_timings.first
70
- _, end_time = upload_timings.last
79
+ _, start_time = upload_timings.first
80
+ _, end_time = upload_timings.last
71
81
 
72
- if start_time == end_time
73
- next
74
- end
82
+ if start_time == end_time
83
+ next
84
+ end
75
85
 
76
- rate = upload_amount / (end_time - start_time)
86
+ rate = upload_amount / (end_time - start_time)
77
87
 
78
- if rate / last_rate > 1.3 || rate / last_rate < 0.7
79
- logger&.info("Uploading #{Etna::Formatting.as_size(rate)} per second")
88
+ if rate / last_rate > 1.3 || rate / last_rate < 0.7
89
+ logger&.info("Uploading #{Etna::Formatting.as_size(rate)} per second")
80
90
 
81
- if rate == 0
82
- last_rate = 0.0001
83
- else
84
- last_rate = rate
91
+ if rate == 0
92
+ last_rate = 0.0001
93
+ else
94
+ last_rate = rate
95
+ end
85
96
  end
86
97
  end
87
98
  end
88
99
  end
89
100
  end
90
101
 
91
- filesystem.mkdir_p(::File.dirname(dest))
92
- filesystem.mv(tmp_file, dest)
93
-
94
102
  filesystem.mkdir_p(::File.dirname(dest_bin_file))
95
103
  filesystem.with_writeable(dest_bin_file, 'w', size_hint: 0) do |io|
96
- # empty file
104
+ # empty file marking that this etag has been moved, to save a future write.
97
105
  end
98
106
  end
99
107
  end
@@ -13,11 +13,11 @@ module Etna
13
13
  end
14
14
  end
15
15
 
16
- class RedcapJobRequest < Struct.new(:model_names, :redcap_tokens, :commit, :project_name, :record_names, keyword_init: true)
16
+ class RedcapJobRequest < Struct.new(:model_names, :redcap_tokens, :commit, :project_name, :mode, keyword_init: true)
17
17
  include JsonSerializableStruct
18
18
 
19
19
  def initialize(**params)
20
- super({model_names: 'all', record_names: nil, commit: false}.update(params))
20
+ super({model_names: 'all', mode: nil, commit: false}.update(params))
21
21
  end
22
22
 
23
23
  def to_json
@@ -27,7 +27,7 @@ module Etna
27
27
  commit: commit,
28
28
  model_names: model_names,
29
29
  redcap_tokens: redcap_tokens,
30
- record_names: record_names
30
+ mode: mode
31
31
  }
32
32
  }.to_json
33
33
  end
@@ -194,6 +194,51 @@ module Etna
194
194
  end
195
195
  end
196
196
 
197
+ # Genentech's aspera deployment doesn't support modern commands, unfortunately...
198
+ class GeneAsperaCliFilesystem < AsperaCliFilesystem
199
+ def tmpdir
200
+ raise "tmpdir is not supported"
201
+ end
202
+
203
+ def rm_rf
204
+ raise "rm_rf is not supported"
205
+ end
206
+
207
+ def mkdir_p(dest)
208
+ # Pass through -- this file system creates containing directories by default, womp womp.
209
+ end
210
+
211
+ def mv
212
+ raise "mv is not supported"
213
+ end
214
+
215
+
216
+ def mkcommand(rd, wd, file, opts, size_hint: nil)
217
+ if opts.include?('w')
218
+ super.map do |e|
219
+ if e.instance_of?(String) && e.start_with?("stdio://")
220
+ "stdio-tar://"
221
+ elsif e == file
222
+ ::File.dirname(file)
223
+ else
224
+ e
225
+ end
226
+ end.insert(2, "-d")
227
+ else
228
+ super
229
+ end
230
+ end
231
+
232
+ def with_writeable(dest, opts = 'w', size_hint: nil, &block)
233
+ super do |io|
234
+ io.write("File: #{::File.basename(dest)}\n")
235
+ io.write("Size: #{size_hint}\n")
236
+ io.write("\n")
237
+ yield io
238
+ end
239
+ end
240
+ end
241
+
197
242
  class Mock < Filesystem
198
243
  def initialize(&new_io)
199
244
  @files = {}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etna
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.26
4
+ version: 0.1.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saurabh Asthana
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-12 00:00:00.000000000 Z
11
+ date: 2021-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack