Module: TDriverReportFileCapture

Included in:
TDriverReportCrashFileCapture
Defined in:
lib/tdriver/report/report_file_capture.rb

Instance Method Summary collapse

Instance Method Details

#capture_filesObject



143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/tdriver/report/report_file_capture.rb', line 143

def capture_files()
  if @monitor_files == 'true'
    begin
      dump_folder=@test_case_folder+'/files'
      if File::directory?(dump_folder)==false
        FileUtils.mkdir_p dump_folder
      end
      download_files(dump_folder)
    rescue Exception => e
      @test_case_execution_log=@test_case_execution_log.to_s + '<br />' + "Unable to capture files: " + e.message + e.backtrace.to_s
    end
  end
end

#check_if_files_existObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/tdriver/report/report_file_capture.rb', line 107

def check_if_files_exist()
  sut_files=Array.new
  if @monitor_files == 'true'
    TDriver::SUTFactory.connected_suts.each do |sut_id, sut_attributes|
      if sut_attributes[:is_connected]
        @file_suts.each do |monitored_sut|
          if monitored_sut == sut_id.to_s
            sut_files << list_sut_files(sut_attributes[:sut])
          end
        end
      end
    end
    @file_count
  else
    @file_count
  end
end

#clean_files_from_sutObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/tdriver/report/report_file_capture.rb', line 47

def clean_files_from_sut()

  if @monitor_files == 'true' && @clean_files == 'true'
    TDriver::SUTFactory.connected_suts.each do |sut_id, sut_attributes|
      if sut_attributes[:is_connected]
        @file_suts.each do |monitored_sut|
          if monitored_sut == sut_id.to_s
            sut_files=Array.new
            sut_files=list_sut_files(sut_attributes[:sut])
            sut_files.each do |file|
              delete_file(sut_attributes[:sut],file)
            end
          end
        end
      end
    end
  end
end

#delete_file(current_sut, file_name) ⇒ Object



99
100
101
102
103
104
105
# File 'lib/tdriver/report/report_file_capture.rb', line 99

def delete_file(current_sut,file_name)
  begin
    current_sut.delete_from_sut(:file => file_name )
  rescue => ex
    #puts ex.message
  end
end

#download_file(current_sut, file_name, download_folder) ⇒ Object



91
92
93
94
95
96
97
# File 'lib/tdriver/report/report_file_capture.rb', line 91

def download_file(current_sut,file_name,download_folder)
  begin
    current_sut.copy_from_sut(:file => file_name, :to => download_folder )
  rescue => ex
    #puts ex.message
  end
end

#download_files(download_folder) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/tdriver/report/report_file_capture.rb', line 125

def download_files(download_folder)
  if @monitor_files == 'true'
    TDriver::SUTFactory.connected_suts.each do |sut_id, sut_attributes|
      if sut_attributes[:is_connected]
        @file_suts.each do |monitored_sut|
          if monitored_sut == sut_id.to_s
            sut_files=Array.new
            sut_files=list_sut_files(sut_attributes[:sut])
            sut_files.each do |file|
              download_file(sut_attributes[:sut],file,download_folder.gsub("\\",'/')+'/')
            end
          end
        end
      end
    end
  end
end

#initializeObject



23
24
25
26
27
28
29
30
# File 'lib/tdriver/report/report_file_capture.rb', line 23

def initialize
  @file_locations=Array.new
  @file_suts=Array.new
  @file_names=Array.new
  @file_count=0
  @monitor_files='false'
  read_file_monitor_settings()
end

#list_sut_files(current_sut) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/tdriver/report/report_file_capture.rb', line 66

def list_sut_files(current_sut)
  file_arr=Array.new
  @file_count=0
  #for every location:
  @file_locations.each do |location|
    begin
      #get file names
      current_location_files=Array.new
      @file_names.each do |file_name|
        current_location_files = current_sut.list_files_from_sut( :from => location, :file=> file_name.to_s )
        #collect crash names and add paths
        current_location_files.each do |sut_file|
          #if file_is_file(sut_file)
          file_arr << sut_file.to_s
          @file_count+=1
          #end
        end
      end
    rescue => ex
      #puts ex.message
    end
  end
  file_arr
end

#read_file_monitor_settingsObject



39
40
41
42
43
44
45
# File 'lib/tdriver/report/report_file_capture.rb', line 39

def read_file_monitor_settings()
  @file_locations=return_settings_value_array($parameters[ :report_file_locations, nil ])
  @file_suts=return_settings_value_array($parameters[ :report_file_monitored_sut_ids, nil ])
  @file_names=return_settings_value_array($parameters[ :report_file_names, nil ])
  @clean_files=$parameters[ :report_clean_files_from_sut_after_capture, 'true' ]
  @monitor_files = $parameters[ :report_file_monitor, 'false' ]
end

#return_settings_value_array(setting) ⇒ Object



32
33
34
35
36
37
# File 'lib/tdriver/report/report_file_capture.rb', line 32

def return_settings_value_array(setting)
  setting_value=setting
  setting_arr=Array.new
  setting_arr=setting_value.split(',')
  setting_arr
end