mesa_test 0.2.10 → 0.2.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/mesa_test +136 -1
  3. data/lib/mesa_test.rb +2 -4
  4. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bdf4d458ea3733da43762a06b695393c56a77fdbeaa3519becb67b4507940b59
4
- data.tar.gz: 918b07c122c8ab69e036cb2e79b73c8bd375ee347575f8f9fd86474a9a58be87
3
+ metadata.gz: fe89bd48cc117d3f99a1e59878fde6ea14528a4e199d8d3bcf6c4af9fcc4937c
4
+ data.tar.gz: 98932d0fb73af742986ee25235a21c9f4b119ce01ee9dd03026cbd714dff85e9
5
5
  SHA512:
6
- metadata.gz: 375a410fe0c4d17e39d1c4e5a13b4bccc390edeb1afe19e3b4ec8ae150f72ad3d352ac4cdcd7bc64bda9baf512eb0547e43cf4444b38a3492a441b7677005094
7
- data.tar.gz: 99f875807d7828c2f1274600ed39877b18b4a37ff8d49b2fb88eb9db859183cc843b831fd6a6e738c0abd7c746b9d4b647872e32b1aa974d2f93c686547a1ec3
6
+ metadata.gz: c589f58abeec628b835557f5be281f496a81fbbbf0697005d8bc7fd0525b613cae8e9ba9175bdf21ec2fb05945a41d8ed38130cd56ba8528eb9bf1b13cda0cad
7
+ data.tar.gz: c524f613c87f04f4547285f0b9e804b1ac0edfc3a99618769aac67ade265dcd475baad5307f28474a4401fe876a4dc03d0c14cdf16b91b9b5d095112f349f116
data/bin/mesa_test CHANGED
@@ -320,10 +320,145 @@ class MesaTest < Thor
320
320
  # directory
321
321
  m.destroy if successfully_submitted && options[:destroy] && m.installed?
322
322
  end
323
- end
323
+ end
324
+
325
+ desc 'search "SEARCH_QUERY" [EMAIL] [PASSWORD]', 'retrieve JSON array of ' \
326
+ 'test instances matching SEARCH_QUERY'
327
+ long_desc <<-LONGDESC
328
+ Sends a JSON request to the Mesa TestHub API. All of your SEARCH_QUERY should
329
+ be in quotes. For details on how to form a proper search query, visit
330
+ testhub.mesastar.org/test_instances/search, where you can also test out
331
+ the search capability in a browser interface. Result is a single line of
332
+ JSON printed to STDOUT.
333
+
334
+ To prevent abuse, the API requires authentication with email and password.
335
+ By default, these are pulled from ~/.mesa_test.yml, but you may override
336
+ these with optional arguments.
337
+ LONGDESC
338
+
339
+ def search(search_query, email=nil, password=nil)
340
+ # get/confirm email and password
341
+ yml_file = File.join(ENV['HOME'], '.mesa_test.yml')
342
+ email, password = get_email_and_password(yml_file, email, password)
343
+ # prep API request
344
+ base_uri = if DEVELOPMENT_MODE
345
+ 'http://localhost:3000'
346
+ else
347
+ 'https://testhub.mesastar.org'
348
+ end
349
+ uri_search = URI.parse(base_uri + '/test_instances/search.json')
350
+ params = {
351
+ email: email,
352
+ password: password,
353
+ query_text: search_query
354
+ }
355
+ uri_search.query = URI.encode_www_form(params)
356
+
357
+ # perform search query
358
+ search_response = nil
359
+ Net::HTTP.start(uri_search.host, uri_search.port, use_ssl: base_uri.include?('https')) do |https|
360
+ request = Net::HTTP::Get.new(
361
+ uri_search,
362
+ initheader = { 'Content-Type' => 'application/json' }
363
+ )
364
+ search_response = JSON.parse(https.request(request).body)
365
+ end
366
+
367
+ # parse results
368
+ if search_response['error']
369
+ STDERR.puts "Error: #{search_response['error']}"
370
+ else
371
+ # break into sections
372
+ results = search_response["results"]
373
+ failures = search_response["failures"]
374
+
375
+ unless failures.empty?
376
+ STDERR.puts "The folloiwng options were invalid and ignored:"
377
+ failures.each { |failure| STDERR.puts "- #{failure}"}
378
+ end
379
+
380
+ shell.say results.to_json
381
+ end
382
+ end
383
+
384
+ desc 'count "SEARCH_QUERY" [EMAIL] [PASSWORD]', 'count number of test ' \
385
+ 'instances matching SEARCH_QUERY'
386
+ long_desc <<-LONGDESC
387
+ Sends a JSON request to the Mesa TestHub API. All of your SEARCH_QUERY should
388
+ be in quotes. For details on how to form a proper search query, visit
389
+ testhub.mesastar.org/test_instances/search, where you can also test out
390
+ the search capability in a browser interface. Result is a single integer.
391
+
392
+ To prevent abuse, the API requires authentication with email and password.
393
+ By default, these are pulled from ~/.mesa_test.yml, but you may override
394
+ these with optional arguments.
395
+ LONGDESC
396
+
397
+ def count(search_query, email=nil, password=nil)
398
+ # get/confirm email and password
399
+ yml_file = File.join(ENV['HOME'], '.mesa_test.yml')
400
+ email, password = get_email_and_password(yml_file, email, password)
401
+ # prep API request
402
+ base_uri = if DEVELOPMENT_MODE
403
+ 'http://localhost:3000'
404
+ else
405
+ 'https://testhub.mesastar.org'
406
+ end
407
+ uri_count = URI.parse(base_uri + '/test_instances/search_count.json')
408
+ params = {
409
+ email: email,
410
+ password: password,
411
+ query_text: search_query
412
+ }
413
+ uri_count.query = URI.encode_www_form(params)
414
+
415
+ # perform count query
416
+ count_response = nil
417
+ Net::HTTP.start(uri_count.host, uri_count.port, use_ssl: base_uri.include?('https')) do |https|
418
+ request = Net::HTTP::Get.new(
419
+ uri_count,
420
+ initheader = { 'Content-Type' => 'application/json' }
421
+ )
422
+ count_response = JSON.parse(https.request(request).body)
423
+ end
424
+
425
+ # parse results
426
+ if count_response['error']
427
+ STDERR.puts "Error: #{count_response['error']}"
428
+ else
429
+ # break into sections
430
+ count = count_response["count"]
431
+ failures = count_response["failures"]
432
+
433
+ unless failures.empty?
434
+ STDERR.puts "The folloiwng options were invalid and ignored:"
435
+ failures.each { |failure| STDERR.puts "- #{failure}"}
436
+ end
437
+
438
+ shell.say count, :blue
439
+ end
440
+ end
324
441
 
325
442
  private
326
443
 
444
+ def get_email_and_password(file, email=nil, password=nil)
445
+ if email && password
446
+ return [email, password]
447
+ end
448
+ raise("File does not exist: #{file}.") unless File.exist?(file)
449
+ contents = File.read(file)
450
+ email_matcher = /^email\:\s*(?<email>.+@.+\..+)$/
451
+ password_matcher = /^password\:\s*(?<password>.+)$/
452
+
453
+ m = email_matcher.match(contents)
454
+ email ||= m[:email] if m
455
+
456
+ m = password_matcher.match(contents)
457
+ password ||= m[:password] if m
458
+
459
+ return [email, password]
460
+ end
461
+
327
462
  def check_user_and_computer(submitter)
328
463
  computer_check = submitter.confirm_computer
329
464
  if computer_check['valid']
data/lib/mesa_test.rb CHANGED
@@ -1335,8 +1335,7 @@ class MesaTestCase
1335
1335
  run_start = Time.now
1336
1336
 
1337
1337
  # do the run
1338
- have_time = system('which time')
1339
- rn_command = if have_time
1338
+ rn_command = if ENV['MESASDK_ROOT'] && File.exist?(File.join(ENV['MESASDK_ROOT'], 'bin', 'time'))
1340
1339
  %q(command time -f '%M' -o mem-rn.txt ./rn > out.txt 2> ) +
1341
1340
  'err.txt'
1342
1341
  else
@@ -1416,8 +1415,7 @@ class MesaTestCase
1416
1415
 
1417
1416
  # do restart and consolidate output. Command depends on if we have access
1418
1417
  # to SDK version of gnu time.
1419
- have_time = system('which time')
1420
- re_command = if have_time
1418
+ re_command = if ENV['MESASDK_ROOT'] && File.exist?(File.join(ENV['MESASDK_ROOT'], 'bin', 'time'))
1421
1419
  %q(command time -f '%M' -o mem-re.txt ./re ) + "#{photo}" \
1422
1420
  ' >> out.txt 2> err.txt'
1423
1421
  else
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mesa_test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.10
4
+ version: 0.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Wolf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-17 00:00:00.000000000 Z
11
+ date: 2019-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -53,7 +53,8 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.19'
55
55
  description: mesa_test is a command-line interface for running the test suites in
56
- MESA and submitting them to the companion website MESATestHub.
56
+ MESA and submitting them to the companion website MESATestHub. It also allows for
57
+ querying the database through a commandline interface.
57
58
  email: wmwolf@asu.edu
58
59
  executables:
59
60
  - mesa_test