rbbt-rest 1.8.157 → 1.9.1

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: 2e4b22bac9c83a30a558edc6a2da6b3472fb4b4fd4e6a656129d80411e2d9e52
4
- data.tar.gz: a2a5802a8dab099897fa5cca2f97c208702509bc72200af6a04113f4f49f1e1e
3
+ metadata.gz: f704f277ce12001953704f8e901241c79f1bc0d6425967ae231455671bfa7879
4
+ data.tar.gz: 07d4ca572f44e36384bd7595f1c36738b6388c4f3da1fa03827a118b5eed3724
5
5
  SHA512:
6
- metadata.gz: f389432ce901f5a7b1c7f41a03b84fe89d32c03db44afbfbb8585aa496a96d7651a627e8db90aff39d4411789ed1bcc51ac7ce166d497204b2823e0c00c35eb0
7
- data.tar.gz: b7af3754e961b7965fefbcca749dc68f40d02fa2bf498484664591e41f280dc53a9d3ef3e0c95b985e0da844d2d024862e7deb0fbcc4262750b0fec3c525f28b
6
+ metadata.gz: ca607c13addb28475b071f500a50e9ccac7c13007e765fb044cba6e9f41735a45e0de2ad403984bbaaf36ba662397140f06d542090bb9936981890d4b5b988c5
7
+ data.tar.gz: d2f72803da7071b5e0d2c743344dc120e7ad56c387ada1d002492ad5b0eeab138b5cd0d630b72af9e5fe8156268d36f65288193c494e2c2ced69c9e6829288b6
@@ -20,10 +20,10 @@ module RbbtRESTHelpers
20
20
  def old_cache(path, check)
21
21
  return false if production?
22
22
  return false if check.nil? or check.empty?
23
- return false if not File.exists? path
23
+ return false if not File.exist? path
24
24
  check = [check] unless Array === check
25
25
  check.each do |file|
26
- if not File.exists?(file)
26
+ if not File.exist?(file)
27
27
  return true
28
28
  end
29
29
  if File.mtime(file) > File.mtime(path)
@@ -207,7 +207,11 @@ module RbbtRESTHelpers
207
207
  data = nil
208
208
  excel_file = TmpFile.tmp_file
209
209
  tsv.excel(excel_file, :sort_by => @excel_sort_by, :sort_by_cast => @excel_sort_by_cast, :name => true, :remove_links => true)
210
- send_file excel_file, :type => 'application/vnd.ms-excel', :filename => 'table.xls'
210
+ name = tsv_options[:table_id]
211
+ name ||= "rbbt-table"
212
+ name = name.sub(/\s/,'_')
213
+ name = name.sub('.tsv','')
214
+ send_file excel_file, :type => 'application/vnd.ms-excel', :filename => "#{name}.xls"
211
215
  when "heatmap"
212
216
  require 'rbbt/util/R'
213
217
  tsv, tsv_options = load_tsv(fragment_file)
@@ -270,7 +274,7 @@ data = NULL
270
274
  if mime && mime.to_s.include?("text/html")
271
275
  halt_html txt || Open.read(fragment_file)
272
276
  else
273
- if File.exists?(fragment_file)
277
+ if File.exist?(fragment_file)
274
278
  send_file fragment_file
275
279
  else
276
280
  halt 200, Open.read(fragment_file)
@@ -325,7 +329,7 @@ data = NULL
325
329
  raise RbbtRESTHelpers::Retry
326
330
  end
327
331
 
328
- #if File.exists?(step.info_file) and Time.now - File.atime(step.info_file) > 60
332
+ #if File.exist?(step.info_file) and Time.now - File.atime(step.info_file) > 60
329
333
  # Log.debug{ "Checking on #{step.info_file}" }
330
334
  # running = (not step.done?) and step.running?
331
335
  # if FalseClass === running
@@ -5,7 +5,7 @@ module RbbtRESTHelpers
5
5
  class Retry < Exception; end
6
6
 
7
7
  def check_step(step)
8
- if File.exists?(step.info_file) and Time.now - File.atime(step.info_file) > 60
8
+ if File.exist?(step.info_file) and Time.now - File.atime(step.info_file) > 60
9
9
  done = step.done?
10
10
  running = done ? false : step.running?
11
11
  Log.debug{ "Checking on #{step.info_file} (done: #{done}; running: #{running})" }
@@ -301,7 +301,7 @@ module RbbtRESTHelpers
301
301
  def permalink(path)
302
302
  id = Misc.digest(Time.now.to_s)
303
303
  dest = File.join(settings.permalink_dir, id)
304
- FileUtils.mkdir_p settings.permalink_dir unless File.exists? settings.permalink_dir
304
+ FileUtils.mkdir_p settings.permalink_dir unless File.exist? settings.permalink_dir
305
305
  FileUtils.ln_s(path, dest)
306
306
  "/permalink/#{ id }"
307
307
  end
@@ -322,36 +322,81 @@ module RbbtRESTHelpers
322
322
 
323
323
  end
324
324
 
325
- class Haml::Filters::DeferJS < Haml::Filters::Base
325
+ if $haml_6
326
+ Haml::Template.options[:escape_html] = false
326
327
 
327
- def render(text)
328
- step_path = Thread.current["step_path"]
329
- text = "" if text.nil?
330
- defer_text =<<-EOF
328
+ class Haml::Filters::DeferJS < Haml::Filters::TiltBase
329
+
330
+ def compile(node)
331
+ text = node.value[:text]
332
+ step_path = Thread.current["step_path"]
333
+ text = "" if text.nil?
334
+ defer_text =<<-EOF
331
335
  %script
332
336
  :plain
333
337
  defer(function(step_path){
334
338
 
335
339
  #{text.gsub(/^/," ")}
336
340
  }, '#{step_path}')
337
- EOF
338
- Haml::Engine.new(defer_text).to_html
341
+ EOF
342
+ node.value[:text] = defer_text
343
+ compile_with_tilt(node, 'haml')
344
+ end
339
345
  end
340
- end
341
346
 
342
- class Haml::Filters::Documentation < Haml::Filters::Base
347
+ class Haml::Filters::Documentation < Haml::Filters::TiltBase
343
348
 
344
- def render(text)
345
- text = "<br/>" if text.strip.empty?
349
+ def compile(node)
350
+ text = node.value[:text]
351
+ text = "<br/>" if text.strip.empty?
346
352
 
347
- doc_text =<<-EOF
353
+ doc_text =<<-EOF
348
354
  %section.documentation#{ text.gsub(/\s/,'').length < 80 * 10 ? '.short' : ''}
349
355
  :markdown
350
356
  #{text.gsub(/^/," ")}
351
- EOF
357
+ EOF
352
358
 
353
- Haml::Engine.new(doc_text).to_html
359
+ node.value[:text] = doc_text
360
+ compile_with_tilt(node, 'haml')
361
+ end
354
362
  end
355
363
 
356
- end
364
+ class Haml::Filters
365
+ register :deferjs, Haml::Filters::DeferJS
366
+ register :documentation, Haml::Filters::Documentation
367
+ end
368
+ else
369
+ module Haml::Filters::DeferJS
370
+ include Haml::Filters::Base
371
+
372
+ def render(text)
373
+ step_path = Thread.current["step_path"]
374
+ text = "" if text.nil?
375
+ defer_text =<<-EOF
376
+ %script
377
+ :plain
378
+ defer(function(step_path){
379
+ #{text.gsub(/^/," ")}
380
+ }, '#{step_path}')
381
+ EOF
382
+ Haml::Engine.new(defer_text).to_html
383
+ end
384
+ end
385
+
386
+ module Haml::Filters::Documentation
387
+ include Haml::Filters::Base
388
+
389
+ def render(text)
390
+ text = "<br/>" if text.strip.empty?
357
391
 
392
+ doc_text =<<-EOF
393
+ %section.documentation#{ text.gsub(/\s/,'').length < 80 * 10 ? '.short' : ''}
394
+ :markdown
395
+ #{text.gsub(/^/," ")}
396
+ EOF
397
+
398
+ Haml::Engine.new(doc_text).to_html
399
+ end
400
+
401
+ end
402
+ end
@@ -3,7 +3,6 @@ require 'rbbt/rest/common/cache'
3
3
  require 'tilt'
4
4
 
5
5
  Tilt::SYMBOL_ARRAY_SORTABLE = false
6
-
7
6
  module RbbtRESTHelpers
8
7
  def error_for(job, layout = nil)
9
8
  if ex = job.info[:exception]
@@ -153,7 +152,8 @@ module RbbtRESTHelpers
153
152
  end
154
153
  end
155
154
  Log.low("Fragment started: #{ fragment_file } - #{Process.pid}")
156
- res = capture_haml fragment_code, &block
155
+ #res = capture_haml fragment_code, &block
156
+ res = $haml_6 ? capture(&block) : capture_haml(&block)
157
157
  Log.low("Fragment writing: #{ fragment_file } - #{Process.pid}")
158
158
  Open.write(fragment_file, res)
159
159
  Log.low("Fragment done: #{ fragment_file } - #{Process.pid}")
@@ -196,7 +196,7 @@ module RbbtRESTHelpers
196
196
  end
197
197
  end
198
198
  else
199
- capture_haml &block
199
+ $haml_6 ? capture(&block) : capture_haml(&block)
200
200
  end
201
201
  else
202
202
  if link =~ / class=/
@@ -294,7 +294,8 @@ module RbbtRESTHelpers
294
294
  def reveal(text, id = nil, options = nil, &block)
295
295
  id ||= "rbbt_reveal_" << (rand * 10000).to_i.to_s
296
296
 
297
- content_html = capture_haml(&block)
297
+ #content_html = capture_haml(&block)
298
+ content_html = $haml_6 ? capture(&block) : capture_haml(&block)
298
299
 
299
300
  options = {} if options.nil?
300
301
  options = {:href => "#", "data-reveal-id" => 'modal1', 'attr-reveal_id' => id}.merge(options)
@@ -40,7 +40,7 @@ module RbbtRESTHelpers
40
40
  md5 = Misc.digest(recorded_js_files * ",")
41
41
  filename = settings.file_dir["all_js-#{md5}.js"].find
42
42
 
43
- if not File.exists?(filename)
43
+ if not File.exist?(filename)
44
44
  Log.debug{ "Regenerating JS Compressed file: #{ filename }" }
45
45
 
46
46
  text = recorded_js_files.collect{|file|
@@ -53,7 +53,7 @@ module RbbtRESTHelpers
53
53
  "//FILE: #{ File.basename(path) }\n" + Open.read(path)
54
54
  } * "\n"
55
55
 
56
- FileUtils.mkdir_p File.dirname(filename) unless File.exists? File.dirname(filename)
56
+ FileUtils.mkdir_p File.dirname(filename) unless File.exist? File.dirname(filename)
57
57
  Open.write(filename, Uglifier.compile(text))
58
58
  end
59
59
 
@@ -146,6 +146,32 @@ Quality
146
146
  end
147
147
 
148
148
  module RbbtRESTHelpers
149
+
150
+ def capture(*args, &block)
151
+
152
+ variables = block.binding.local_variables
153
+ #variables.each do |v|
154
+ # iif [v, block.binding.local_variable_get(v)]
155
+ #end
156
+ buff_var = variables.select{|v| v.to_s =~ /^_module\d+$/}.sort_by{|v| v.to_s.scan(/\d+/).first.to_i}.last
157
+ buff_was = block.binding.local_variable_get(buff_var) if variables.include? buff_var
158
+ block.binding.local_variable_set(buff_var,'') if buff_var
159
+ begin
160
+ raw = block.call(*args)
161
+ #variables = block.binding.local_variables
162
+ #iii variables
163
+ #variables.each do |v|
164
+ # iif [v, block.binding.local_variable_get(v)]
165
+ #end
166
+ captured = block.binding.local_variable_get(buff_var) if block.binding.local_variables.include?(buff_var)
167
+ captured = "" if captured.nil?
168
+ captured = raw if captured.empty?
169
+ captured
170
+ ensure
171
+ block.binding.local_variable_set(buff_var, buff_was) if buff_was
172
+ end
173
+ end
174
+
149
175
  def tsv_rows_full(tsv)
150
176
  case tsv.type
151
177
  when :single
@@ -390,7 +416,7 @@ module RbbtRESTHelpers
390
416
  tsv = TSV.open(Open.open(file))
391
417
  end
392
418
 
393
- table_options = File.exists?(file + '.table_options') ? YAML.load_file(file + '.table_options') : {}
419
+ table_options = File.exist?(file + '.table_options') ? YAML.load_file(file + '.table_options') : {}
394
420
  tsv.entity_options = table_options[:tsv_entity_options]
395
421
  headers = table_options[:headers]
396
422
  headers.each{|field,p| tsv.entity_templates[field] = Misc.prepare_entity("TEMPLATE", p.first, (tsv.entity_options || {}).merge(p.last)) } unless headers.nil?
@@ -402,10 +428,12 @@ module RbbtRESTHelpers
402
428
  RbbtRESTHelpers.load_tsv(*args)
403
429
  end
404
430
 
405
- def table(options = {})
431
+ def table(options = {},&block)
406
432
  options = {} if options.nil?
407
433
 
408
- tsv = yield
434
+ tsv = $haml_6 ? capture(&block) : block.call
435
+
436
+ raise "Use next to return the table" if String === tsv
409
437
 
410
438
  table_code = options[:table_id] || (rand * 100000).to_i.to_s
411
439
  table_code = Entity::REST.clean_element(table_code)
@@ -1,6 +1,7 @@
1
-
2
1
  module RbbtRESTHelpers
3
2
  class Tabs
3
+ include RbbtRESTHelpers
4
+
4
5
  attr_accessor :headers, :codes, :content, :classes, :tab_classes
5
6
  def initialize(page)
6
7
  @page = page
@@ -13,7 +14,7 @@ module RbbtRESTHelpers
13
14
  @content ||= {}
14
15
 
15
16
  if block_given?
16
- html = @page.capture_haml &block
17
+ html = $haml_6 ? capture(&block) : @page.capture_haml(&block)
17
18
  else
18
19
  html = nil
19
20
  end
@@ -57,10 +57,10 @@ module Entity
57
57
 
58
58
  def self.load_list(entity_type, id, user = nil)
59
59
  path = list_file(entity_type, id, user)
60
- path = list_file(entity_type, id, :public) unless path != nil and File.exists? path
61
- path = list_file(entity_type, id) unless path != nil and File.exists? path
60
+ path = list_file(entity_type, id, :public) unless path != nil and File.exist? path
61
+ path = list_file(entity_type, id) unless path != nil and File.exist? path
62
62
 
63
- raise "List not found: #{ id }" if path.nil? or not File.exists? path
63
+ raise "List not found: #{ id }" if path.nil? or not File.exist? path
64
64
 
65
65
  begin
66
66
  list = Annotated.load_tsv TSV.open(path)
@@ -79,7 +79,7 @@ module Entity
79
79
  begin
80
80
  Open.write(path, Annotated.tsv(list, :all).to_s)
81
81
  rescue
82
- FileUtils.rm path if File.exists? path
82
+ FileUtils.rm path if File.exist? path
83
83
  raise $!
84
84
  end
85
85
  end
@@ -88,11 +88,11 @@ module Entity
88
88
  def self.delete_list(entity_type, id, user)
89
89
  path = list_file(entity_type, id, user)
90
90
 
91
- "This list does not belong to #{ user }: #{[entity_type, id] * ": "}" unless File.exists? path
91
+ "This list does not belong to #{ user }: #{[entity_type, id] * ": "}" unless File.exist? path
92
92
 
93
93
  Misc.lock path do
94
94
  begin
95
- FileUtils.rm path if File.exists? path
95
+ FileUtils.rm path if File.exist? path
96
96
  rescue
97
97
  raise $!
98
98
  end
@@ -39,7 +39,7 @@ module EntityRESTHelpers
39
39
  path.annotate check_file
40
40
  return false unless check_file.exists?
41
41
  else
42
- return false unless File.exists?(check_file)
42
+ return false unless File.exist?(check_file)
43
43
  end
44
44
 
45
45
  reject?(check_file, binding)
@@ -57,8 +57,8 @@ module Entity
57
57
 
58
58
  def self.load_map(entity_type, column, id, user = nil)
59
59
  path = map_file(entity_type, column, id, user)
60
- path = map_file(entity_type, column, id, :public) unless path != nil and File.exists? path
61
- path = map_file(entity_type, column, id) unless path != nil and File.exists? path
60
+ path = map_file(entity_type, column, id, :public) unless path != nil and File.exist? path
61
+ path = map_file(entity_type, column, id) unless path != nil and File.exist? path
62
62
 
63
63
  begin
64
64
  RbbtRESTHelpers.load_tsv(path).first
@@ -75,7 +75,7 @@ module Entity
75
75
  begin
76
76
  RbbtRESTHelpers.save_tsv(map, path)
77
77
  rescue
78
- FileUtils.rm path if path and File.exists? path
78
+ FileUtils.rm path if path and File.exist? path
79
79
  raise $!
80
80
  end
81
81
  end
@@ -84,11 +84,11 @@ module Entity
84
84
  def self.delete_map(entity_type, column, id, user)
85
85
  path = map_file(entity_type, column, id, user)
86
86
 
87
- "This map does not belong to #{ user }: #{[entity_type, column, id] * ": "}" unless File.exists? path
87
+ "This map does not belong to #{ user }: #{[entity_type, column, id] * ": "}" unless File.exist? path
88
88
 
89
89
  Misc.lock path do
90
90
  begin
91
- FileUtils.rm path if File.exists? path
91
+ FileUtils.rm path if File.exist? path
92
92
  rescue
93
93
  raise $!
94
94
  end
@@ -189,7 +189,7 @@ module Entity
189
189
  reuse = options.delete("reuse") if reuse.nil?
190
190
  reuse = true if reuse.nil?
191
191
 
192
- Entity::List.save_list(entity_type.to_s, id, self) unless reuse and File.exists?(Entity::List.list_file(entity_type.to_s, id))
192
+ Entity::List.save_list(entity_type.to_s, id, self) unless reuse and File.exist?(Entity::List.list_file(entity_type.to_s, id))
193
193
 
194
194
  klasses = self.klasses
195
195
  klasses << 'entity_list'
@@ -212,7 +212,7 @@ module Entity
212
212
  reuse = options.delete("reuse") if reuse.nil?
213
213
  reuse = true if reuse.nil?
214
214
 
215
- Entity::List.save_list(entity_type.to_s, id, self) unless reuse and File.exists? Entity::List.list_file(entity_type.to_s, id, self)
215
+ Entity::List.save_list(entity_type.to_s, id, self) unless reuse and File.exist? Entity::List.list_file(entity_type.to_s, id, self)
216
216
 
217
217
  klasses = self.klasses
218
218
  klasses << 'entity_list_action'
@@ -134,10 +134,10 @@ module Sinatra
134
134
  when :raw, :literal
135
135
  content_type "text/tab-separated-values"
136
136
  user_file = Entity::List.list_file(entity_type.split(":").first, list_id, user)
137
- send_file user_file if File.exists? user_file
137
+ send_file user_file if File.exist? user_file
138
138
 
139
139
  global_file = Entity::List.list_file(entity_type.split(":").first, list_id, nil)
140
- send_file global_file if File.exists? global_file
140
+ send_file global_file if File.exist? global_file
141
141
 
142
142
  raise "List file not found: #{ list_id }"
143
143
  when :json
@@ -296,21 +296,21 @@ module Sinatra
296
296
  case @format
297
297
  when :name
298
298
  file = Entity::Map.map_file(entity_type.split(":").first, column, map_id, user)
299
- file = Entity::Map.map_file(entity_type.split(":").first, column, map_id, nil) unless File.exists? file
299
+ file = Entity::Map.map_file(entity_type.split(":").first, column, map_id, nil) unless File.exist? file
300
300
  new = TSV.open(file).change_key "Associated Gene Name"
301
301
  new_id = map_id << " [Names]"
302
302
  Entity::Map.save_map(entity_type, column, new_id, new, user)
303
303
  redirect to(Entity::REST.entity_map_url(new_id, entity_type, column))
304
304
  when :ensembl
305
305
  file = Entity::Map.map_file(entity_type.split(":").first, column, map_id, user)
306
- file = Entity::Map.map_file(entity_type.split(":").first, column, map_id, nil) unless File.exists? file
306
+ file = Entity::Map.map_file(entity_type.split(":").first, column, map_id, nil) unless File.exist? file
307
307
  new = TSV.open(file).change_key "Ensembl Gene ID"
308
308
  new_id = map_id << " [Ensembl]"
309
309
  Entity::Map.save_map(entity_type, column, new_id, new, user)
310
310
  redirect to(Entity::REST.entity_map_url(new_id, entity_type, column))
311
311
  when :pvalue_score
312
312
  file = Entity::Map.map_file(entity_type.split(":").first, column, map_id, user)
313
- file = Entity::Map.map_file(entity_type.split(":").first, column, map_id, nil) unless File.exists? file
313
+ file = Entity::Map.map_file(entity_type.split(":").first, column, map_id, nil) unless File.exist? file
314
314
  tsv = TSV.open(file)
315
315
  tsv.process tsv.fields.first do |value|
316
316
  value = value.flatten.first if Array === value
@@ -325,7 +325,7 @@ module Sinatra
325
325
  redirect to(Entity::REST.entity_map_url(new_id, entity_type, column))
326
326
  when :ranks
327
327
  file = Entity::Map.map_file(entity_type.split(":").first, column, map_id, user)
328
- file = Entity::Map.map_file(entity_type.split(":").first, column, map_id, nil) unless File.exists? file
328
+ file = Entity::Map.map_file(entity_type.split(":").first, column, map_id, nil) unless File.exist? file
329
329
  tsv = TSV.open(file, :cast => :to_f)
330
330
  new = tsv.ranks_for(tsv.fields.first)
331
331
  new_id = map_id << " [Ranks]"
@@ -334,7 +334,7 @@ module Sinatra
334
334
  redirect to(Entity::REST.entity_map_url(new_id, entity_type, column))
335
335
  when :invert_ranks
336
336
  file = Entity::Map.map_file(entity_type.split(":").first, column, map_id, user)
337
- file = Entity::Map.map_file(entity_type.split(":").first, column, map_id, nil) unless File.exists? file
337
+ file = Entity::Map.map_file(entity_type.split(":").first, column, map_id, nil) unless File.exist? file
338
338
  tsv = TSV.open(file)
339
339
  size = tsv.size
340
340
  tsv.process "Rank" do |v|
@@ -351,15 +351,15 @@ module Sinatra
351
351
  when :raw, :literal
352
352
  content_type "text/tab-separated-values"
353
353
  user_file = Entity::Map.map_file(entity_type.split(":").first, column, map_id, user)
354
- send_file user_file if File.exists? user_file
354
+ send_file user_file if File.exist? user_file
355
355
 
356
356
  global_file = Entity::Map.map_file(entity_type.split(":").first, column, map_id, nil)
357
- send_file global_file if File.exists? global_file
357
+ send_file global_file if File.exist? global_file
358
358
 
359
359
  raise "Map file not found: #{ map_id }"
360
360
  when :json
361
361
  file = Entity::Map.map_file(entity_type.split(":").first, column, map_id, user)
362
- file = Entity::Map.map_file(entity_type.split(":").first, column, map_id, nil) unless File.exists? file
362
+ file = Entity::Map.map_file(entity_type.split(":").first, column, map_id, nil) unless File.exist? file
363
363
 
364
364
  content_type "application/json"
365
365
  tsv = TSV.open(file)
@@ -413,13 +413,13 @@ module Sinatra
413
413
  column = Entity::REST.restore_element(column)
414
414
 
415
415
  file1 = Entity::Map.map_file(entity_type.split(":").first, column, map1, user)
416
- file1 = Entity::Map.map_file(entity_type.split(":").first, column, map1, nil) unless File.exists? file1
417
- raise "Map not found: #{ map1 }" unless File.exists? file1
416
+ file1 = Entity::Map.map_file(entity_type.split(":").first, column, map1, nil) unless File.exist? file1
417
+ raise "Map not found: #{ map1 }" unless File.exist? file1
418
418
  tsv1 = TSV.open(file1, :cast => :to_f)
419
419
 
420
420
  file2 = Entity::Map.map_file(entity_type.split(":").first, column2, map2, user)
421
- file2 = Entity::Map.map_file(entity_type.split(":").first, column2, map2, nil) unless File.exists? file2
422
- raise "Map not found: #{ map2 } - #{ file2 }" unless File.exists? file2
421
+ file2 = Entity::Map.map_file(entity_type.split(":").first, column2, map2, nil) unless File.exist? file2
422
+ raise "Map not found: #{ map2 } - #{ file2 }" unless File.exist? file2
423
423
  tsv2 = TSV.open(file2, :cast => :to_f)
424
424
 
425
425
  tsv1 = tsv1.select :key => tsv2.keys
@@ -1,3 +1,6 @@
1
+ require 'haml'
2
+ $haml_6 = Gem::Version.new(Haml::VERSION) >= Gem::Version.new("6.0.0")
3
+
1
4
  require 'rbbt/rest/common/locate'
2
5
  require 'rbbt/rest/common/resources'
3
6
  require 'rbbt/rest/common/users'
@@ -14,6 +17,7 @@ require 'json'
14
17
  require 'nakayoshi_fork'
15
18
 
16
19
  Rbbt.add_version(__FILE__)
20
+
17
21
  module Sinatra
18
22
  module RbbtRESTMain
19
23
 
@@ -55,7 +59,10 @@ module Sinatra
55
59
 
56
60
  set :environment, ENV["RACK_ENV"].to_sym if ENV["RACK_ENV"]
57
61
 
58
- attr_accessor :ajax, :layout, :format, :size, :update, :cache_type, :_, :profile
62
+ attr_accessor :ajax, :layout, :size, :update, :cache_type, :_, :profile
63
+
64
+ # This collides with a function in sinatra
65
+ #attr_accessor :format
59
66
 
60
67
 
61
68
  enable :cross_origin
@@ -121,7 +128,7 @@ module Sinatra
121
128
  printer = RubyProf::MultiPrinter.new(result)
122
129
  dir = TmpFile.tmp_file
123
130
  dir = settings.file_dir
124
- FileUtils.mkdir_p dir unless File.exists? dir
131
+ FileUtils.mkdir_p dir unless File.exist? dir
125
132
  printer.print(:path => dir, :profile => 'profile')
126
133
  Log.info{ "Profile saved at #{ dir }: #{@uri}" }
127
134
  end
@@ -52,8 +52,9 @@ module WorkflowRESTHelpers
52
52
 
53
53
  def execution_type(workflow, task)
54
54
  export = type_of_export(workflow, task)
55
+ return :slurm if ENV["RBBT_REST_USE_SLURM"] == 'true'
55
56
  return cache_type if cache_type
56
- return :sync if export == :exec and format == :html
57
+ return :sync if export == :exec and @format == :html
57
58
  return export if export == :exec
58
59
  return :asynchronous
59
60
  end
@@ -82,7 +83,7 @@ module WorkflowRESTHelpers
82
83
  end
83
84
 
84
85
  def show_exec_result(result, workflow, task)
85
- case format.to_sym
86
+ case @format.to_sym
86
87
  when :html
87
88
  show_result_html result, workflow, task, nil
88
89
  when :json
@@ -108,14 +109,14 @@ module WorkflowRESTHelpers
108
109
  when :jobname
109
110
  halt 200, nil
110
111
  else
111
- raise "Unsupported format: #{ format }"
112
+ raise "Unsupported format: #{ @format }"
112
113
  end
113
114
  end
114
115
 
115
116
  def show_result(job, workflow, task, params = nil)
116
117
  return show_result_html nil, workflow, task, job.name, job, params if @fragment
117
118
 
118
- case format.to_sym
119
+ case @format.to_sym
119
120
  when :html
120
121
  show_result_html :load, workflow, task, job.name, job, params
121
122
  when :table
@@ -151,7 +152,7 @@ module WorkflowRESTHelpers
151
152
  if job.path
152
153
  if Open.remote? job.path
153
154
  Open.open(job.path, :nocache => true)
154
- elsif File.exists? job.path
155
+ elsif File.exist? job.path
155
156
  send_file(job.path, :filename => (params[:filename] || File.basename(job.path)))
156
157
  else
157
158
  halt 200, job.load
@@ -183,7 +184,7 @@ module WorkflowRESTHelpers
183
184
  EOF
184
185
  send_file png_file, :type => 'image/png', :filename => job.name + ".heatmap.png"
185
186
  else
186
- raise "Unsupported format: #{ format }"
187
+ raise "Unsupported format: #{ @format }"
187
188
  end
188
189
  end
189
190
 
@@ -249,7 +250,7 @@ module WorkflowRESTHelpers
249
250
  job.join
250
251
  end
251
252
 
252
- if format == :jobname
253
+ if @format == :jobname
253
254
  job.name
254
255
  else
255
256
  job_url = job.respond_to?(:url)? job.url : File.join("/", workflow.to_s, task, job.name)
@@ -270,7 +271,7 @@ module WorkflowRESTHelpers
270
271
  # $rest_cache_semaphore is defined in rbbt-util etc/app.d/semaphores.rb
271
272
  job.fork($rest_cache_semaphore) unless job.started?
272
273
 
273
- if format == :jobname
274
+ if @format == :jobname
274
275
  job.soft_grace
275
276
  content_type :text
276
277
  job.name
@@ -283,6 +284,15 @@ module WorkflowRESTHelpers
283
284
  rescue Exception
284
285
  Log.exception $!
285
286
  end
287
+ when :slurm
288
+ require 'rbbt/hpc'
289
+ batch_system = ENV["BATCH_SYSTEM"] || "SLURM"
290
+ system = HPC.batch_system batch_system
291
+ system.orchestrate_job(job, {})
292
+ job_url = job.respond_to?(:url)? job.url : File.join("/", workflow.to_s, task, job.name)
293
+ job_url += "?_format=#{@format}" if @format
294
+ iii job_url
295
+ redirect to(job_url)
286
296
  else
287
297
  raise "Unsupported execution_type: #{ execution_type }"
288
298
  end
@@ -291,7 +301,7 @@ module WorkflowRESTHelpers
291
301
  def recursive_clean_job(workflow, job)
292
302
  job.recursive_clean
293
303
 
294
- if format == :jobname
304
+ if @format == :jobname
295
305
  halt 200, job.name
296
306
  elsif ajax
297
307
  halt 200
@@ -309,9 +319,9 @@ module WorkflowRESTHelpers
309
319
  def clean_job(workflow, job)
310
320
  job.clean
311
321
 
312
- if format == :jobname
322
+ if @format == :jobname
313
323
  halt 200, job.name
314
- elsif ajax or format == :json
324
+ elsif @ajax or @format == :json
315
325
  halt 200
316
326
  else
317
327
  redirect to(File.join("/", workflow.to_s, job.task_name.to_s))
@@ -41,10 +41,10 @@ module Sinatra
41
41
  workflow.export *workflow.tasks.keys
42
42
  end
43
43
 
44
- self.instance_eval workflow.libdir.lib['sinatra.rb'].read, workflow.libdir.lib['sinatra.rb'].find if workflow.respond_to?(:libdir) and File.exists? workflow.libdir.lib['sinatra.rb']
44
+ self.instance_eval workflow.libdir.lib['sinatra.rb'].read, workflow.libdir.lib['sinatra.rb'].find if workflow.respond_to?(:libdir) and File.exist? workflow.libdir.lib['sinatra.rb']
45
45
 
46
46
  get "/#{workflow.to_s}" do
47
- case format
47
+ case @format
48
48
  when :json
49
49
  content_type "application/json"
50
50
 
@@ -56,14 +56,14 @@ module Sinatra
56
56
  end
57
57
 
58
58
  get "/#{workflow.to_s}/documentation" do
59
- case format
59
+ case @format
60
60
  when :html
61
61
  workflow_render('tasks', workflow)
62
62
  when :json
63
63
  content_type "application/json"
64
64
  workflow.documentation.to_json
65
65
  else
66
- raise "Unsupported format specified: #{ format }"
66
+ raise "Unsupported format specified: #{ @format }"
67
67
  end
68
68
  end
69
69
 
@@ -72,14 +72,14 @@ module Sinatra
72
72
 
73
73
  raise Workflow::TaskNotFoundException.new workflow, task unless workflow.tasks.include? task.to_sym
74
74
 
75
- case format
75
+ case @format
76
76
  when :html
77
77
  workflow_render('task_info', workflow, nil, :cache => false )
78
78
  when :json
79
79
  content_type "application/json"
80
80
  workflow.task_info(task.to_sym).to_json
81
81
  else
82
- raise "Unsupported format specified: #{ format }"
82
+ raise "Unsupported format specified: #{ @format }"
83
83
  end
84
84
  end
85
85
 
@@ -88,14 +88,14 @@ module Sinatra
88
88
 
89
89
  raise Workflow::TaskNotFoundException.new workflow, task unless workflow.tasks.include? task.to_sym
90
90
 
91
- case format
91
+ case @format
92
92
  when :html
93
93
  workflow_render('task_dependencies', workflow)
94
94
  when :json
95
95
  content_type "application/json"
96
96
  workflow.task_dependencies[task.to_sym].to_json
97
97
  else
98
- raise "Unsupported format specified: #{ format }"
98
+ raise "Unsupported format specified: #{ @format }"
99
99
  end
100
100
  end
101
101
 
@@ -116,7 +116,7 @@ module Sinatra
116
116
 
117
117
  task_parameters[:jobname] = jobname
118
118
 
119
- if complete_input_set(workflow, task, task_parameters) || format != :html || jobname
119
+ if complete_input_set(workflow, task, task_parameters) || @format != :html || jobname
120
120
  issue_job(workflow, task, jobname, task_parameters)
121
121
  else
122
122
  workflow_render('form', workflow, task, task_parameters)
@@ -185,7 +185,7 @@ module Sinatra
185
185
  error_for job
186
186
  when error
187
187
  error_for job
188
- when (exec_type == :asynchronous or exec_type == :async)
188
+ when (exec_type == :asynchronous or exec_type == :async or exec_type == :slurm)
189
189
  case @format.to_s
190
190
  when 'json', 'raw', 'binary'
191
191
  halt 202
@@ -226,7 +226,7 @@ module Sinatra
226
226
 
227
227
  halt 404, "Job not found: #{job.path} (#{job.status})" if job.status == :noinfo and not job.done?
228
228
 
229
- case format
229
+ case @format
230
230
  when :html
231
231
  workflow_render('job_info', workflow, task, :job => job, :info => job.info)
232
232
  when :input_bundle
@@ -262,7 +262,7 @@ module Sinatra
262
262
  end
263
263
  halt 200, info_json.to_json
264
264
  else
265
- raise "Unsupported format specified: #{ format }"
265
+ raise "Unsupported format specified: #{ @format }"
266
266
  end
267
267
  end
268
268
 
@@ -276,14 +276,14 @@ module Sinatra
276
276
 
277
277
  job = workflow.fast_load_id(File.join(task, job))
278
278
 
279
- case format
279
+ case @format
280
280
  when :html
281
281
  workflow_render('job_files', workflow, task, :info => job.info, :job => job)
282
282
  when :json
283
283
  content_type "application/json"
284
284
  job.files.to_json
285
285
  else
286
- raise "Unsupported format specified: #{ format }"
286
+ raise "Unsupported format specified: #{ @format }"
287
287
  end
288
288
  end
289
289
 
@@ -141,7 +141,7 @@ $cyan: rgba(50, 211, 255, 1)
141
141
  .dependencies, .job_info
142
142
  .status
143
143
  color: $cyan
144
- .status.waiting, .status.noinfo
144
+ .status.waiting, .status.noinfo, .status.cleaned
145
145
  color: $yellow
146
146
  .status.started
147
147
  color: $cyan
@@ -22,7 +22,7 @@
22
22
  - when String
23
23
  %p= card.description
24
24
  - when Proc
25
- = capture_haml &card.description
25
+ = capture &card.description
26
26
  - else
27
27
  - raise "Unknown description: #{fff card.description}"
28
28
 
@@ -36,7 +36,7 @@
36
36
  - inputs, input_block = input
37
37
  - if inputs.select{|input| @params[input.to_s].nil? }.any?
38
38
  - require_parameters = true
39
- - exception_html = capture_haml &input_block
39
+ - exception_html = capture &input_block
40
40
  - break
41
41
 
42
42
  - else
@@ -51,5 +51,5 @@
51
51
  - if require_parameters
52
52
  .ui.message.warning Please configure the parameters to execute the action
53
53
  - else
54
- = capture_haml &block
54
+ = capture &block
55
55
 
@@ -96,7 +96,7 @@
96
96
  - if defined? block and block
97
97
  /-- description block --
98
98
  .description.ui.basic.segment<
99
- = capture_haml &block
99
+ = capture &block
100
100
 
101
101
  - card.sections.each do |name,section_block|
102
102
  .ui.very.basic.segment(id="#{Misc.snake_case(name)}")
@@ -98,7 +98,7 @@
98
98
  - if defined? block and block
99
99
  /-- description block --
100
100
  .description.ui.basic.segment<
101
- = capture_haml &block
101
+ = capture &block
102
102
 
103
103
  - card.sections.each do |name,section_block|
104
104
  .ui.very.basic.segment(id="#{Misc.snake_case(name)}")
@@ -30,7 +30,7 @@
30
30
  - pvalue = pvalue.collect{|p| p == 0 ? 0.000000000000000000001 : p }
31
31
  = resource map_id + '.qqplot.png', nil, :image do |file|
32
32
  = fragment do
33
- - FileUtils.mkdir_p File.dirname(file) unless File.exists? File.dirname(file)
33
+ - FileUtils.mkdir_p File.dirname(file) unless File.exist? File.dirname(file)
34
34
  :ruby
35
35
  script =<<-EOF
36
36
  library(ggplot2)
@@ -31,7 +31,7 @@
31
31
  - name = File.basename(example_dir)
32
32
  - task_info = workflow.task_info task
33
33
  - inputs = Workflow.load_inputs(example_dir, task_info[:inputs], task_info[:input_types])
34
- - inputs.each{|k,v| v.replace Open.read(v) if String === v and File.exists? v }
34
+ - inputs.each{|k,v| v.replace Open.read(v) if String === v and File.exist? v }
35
35
  - new = {}
36
36
  - inputs.each{|k,v| v.filename = nil if TSV === v ; v = v * "\n" if Array === v; new[k] = v.to_s }
37
37
  - inputs = new
@@ -4,7 +4,7 @@
4
4
  - page = result.size > 50 ? "1" : nil
5
5
 
6
6
  = table :table_id => table_id, :page => page, :table_class => table_class, :row_ids => :use, :table_url => jobname ? to(File.join('/', workflow.to_s, task, jobname)) : nil do
7
- - result
7
+ - next result
8
8
 
9
9
  -#
10
10
  - begin
@@ -4,8 +4,11 @@
4
4
  %ul.dependencies
5
5
  - job.dependencies.reverse.each do |dep|
6
6
  - dep_workflow = dep.workflow
7
+ - dep_workflow = nil if dep_workflow == ""
7
8
  - dep_workflow ||= dep.task.workflow if dep.task
9
+ - dep_workflow = nil if dep_workflow == ""
8
10
  - dep_workflow ||= File.basename(File.dirname(File.dirname(dep.path)))
11
+ - dep_workflow = nil if dep_workflow == ""
9
12
  - str = [dep_workflow, dep.task_name, dep.name].compact * " - "
10
13
  - remote = true if Open.remote?(dep.path) || Open.ssh?(dep.path)
11
14
 
@@ -66,7 +66,7 @@
66
66
  $('.step.progress').progress({label: 'ratio',text:{ratio: '{value}'}})
67
67
 
68
68
  %hr
69
- - if defined? job.info_file and File.exists? job.info_file and @uri.include? job.name
69
+ - if defined? job.info_file and File.exist? job.info_file and @uri.include? job.name
70
70
  - abort_url = add_GET_param(remove_GET_param(@uri, "_layout"), "_update", "abort")
71
71
  %a.ui.button.red.abort(href=abort_url) Abort
72
72
  -#- clean_url = add_GET_param(remove_GET_param(@uri, "_layout"), "_update", "clean")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbbt-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.157
4
+ version: 1.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-07 00:00:00.000000000 Z
11
+ date: 2023-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: modular-scale
@@ -1853,7 +1853,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1853
1853
  - !ruby/object:Gem::Version
1854
1854
  version: '0'
1855
1855
  requirements: []
1856
- rubygems_version: 3.1.4
1856
+ rubygems_version: 3.5.0.dev
1857
1857
  signing_key:
1858
1858
  specification_version: 4
1859
1859
  summary: Rbbt Web and REST interfaces