Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions diagnostic_analysis/diagnostic_analysis/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def _update(self, topic, msg):

# Use named temp file, will cat this to header on close
datafile, tmp_name = tempfile.mkstemp()
self._stats[name]['data_file'] = os.fdopen(datafile, 'w')
self._stats[name]['data_file'] = os.fdopen(datafile, 'w+')
self._stats[name]['data_name'] = tmp_name


Expand Down Expand Up @@ -164,16 +164,21 @@ def finish_logfile(self):
header_line = ','.join(['Timestamp'] + ['Level', 'Message', 'Hardware ID'] +
[f.replace(',','').replace('\n', ' ') for f in fields]) + '\n'

file_name = os.path.join(self.output_dir, name.replace(' ', '_').replace('(', '').replace(')', '').replace('/', '__').replace('.', '').replace('#', '') + '.csv')

file_name = os.path.join(self.output_dir,
name.replace(' ', '_').replace('(', '').replace(')', '').replace('/', '__').replace('\\', '__').replace('.', '').replace('#', '').replace('>','-').replace(':','-') + '.csv')

output_file = open(file_name, 'w')
output_file.write(header_line)

# Move cursor to beginning of the data file to read all data
self._stats[name]['data_file'].seek(0)
# Append the tmp data file to the header
output_file.write(self._stats[name]['data_file'].read())

output_file.close()

self._stats[name]['data_file'].close() # Close data

# Append the tmp data file to the header
subprocess.call("cat %s >> %s" % (self._stats[name]['data_name'], file_name), shell=True)
# Remove tmp file
os.remove(self._stats[name]['data_name'])
# Store filename
Expand Down