Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. class Read
  2. require 'spreadsheet'
  3. require './Model'
  4. require_relative 'Return_coverage_reports'
  5.  
  6. def read_from_ss(ss_path)
  7. model_array = []
  8. Spreadsheet.client_encoding = 'UTF-8'
  9. book = Spreadsheet.open ss_path
  10. sheet = book.worksheet 0
  11. github_url = sheet.row(0)[1]
  12. sheet.each 2 do |row|
  13. model = Model.new
  14. model.task = row[0]
  15. model.task_num = row[1]
  16. model.ruby_v = row[2]
  17. model.rails_v = row[3]
  18. model.coveralls = row[4]
  19. all_tests = row[5].scan /[^;]*/
  20. all_tests.each do |test|
  21. if test.to_s != ''
  22. line_num = /(?<=\().+?(?=\))/.match test
  23. line_content = /.*\(/.match test
  24. line = line_content.to_s[0...-1]
  25. if model.tests.to_s != ''
  26. model.tests = "#{model.tests}," + "#{line}:#{line_num}"
  27. update_file(line, Integer(line_num))
  28. else
  29. model.tests = "#{line}:#{line_num}"
  30. update_file(line, Integer(line_num))
  31. end
  32.  
  33. end
  34. end
  35. model_array.push(model)
  36. end
  37. [model_array, github_url]
  38. end
  39.  
  40. def call_script(ss_path)
  41. modelsAndUrl = read_from_ss(ss_path)
  42. model_array = modelsAndUrl[0]
  43. model_array.each do |model|
  44. git_url = "#{modelsAndUrl[1].to_s}"
  45. ruby_v = "#{model.ruby_v.to_s}"
  46. task_num = "#{model.task_num.to_s}"
  47. rails_v = "#{model.rails_v.to_s}"
  48. tests = "#{model.tests.to_s}"
  49. worked = system("/home/ess/script.sh", git_url, task_num,ruby_v,rails_v,tests)
  50. #if worked != nil
  51. # if worked == 0
  52. rep_name = (/[^\/]*$/.match(git_url)).to_s[0..-5]
  53. Return_coverage_reports.new.save_covered_files("#{__dir__}/#{rep_name}/coverage/index.html", model.task.to_s)
  54. # else
  55. # end
  56. #end
  57. return true
  58. end
  59. end
  60.  
  61. def update_file(path, line_num)
  62. file_lines = read_file(path)
  63. puts file_lines.length
  64. updated_file = []
  65. i = 0
  66. updated = false
  67. while i < file_lines.length
  68. if updated
  69. updated_file.push file_lines[i - 1]
  70. else
  71. if i == line_num - 1
  72. updated_file.push '@cin_ufpe_tan'
  73. updated = true
  74. else
  75. updated_file.push file_lines[i]
  76. end
  77. end
  78. i += 1
  79. end
  80. puts updated_file
  81. write_on_file(updated_file, path)
  82. end
  83. end
  84.  
  85. def write_on_file(text, path)
  86. File.open("#{path}.txt", 'w') do |f|
  87. f.write text
  88. end
  89. end
  90.  
  91. def read_file(path)
  92. array_line = []
  93. File.foreach(path) do |line|
  94. array_line.push line
  95. end
  96. array_line
  97. end
  98.  
  99. end
  100.  
  101. Read.new.call_script('/home/ess/planilhas/TheOdinProject_theodinproject-tests.xls')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement