Skip to content

Commit

Permalink
Sanitize dut_id for use in output file name
Browse files Browse the repository at this point in the history
Sometimes the DUT id may contain characters that aren't appropriate for
file names. Sanitize the dut_id, so that we can safely use any ID.
  • Loading branch information
Jonathan Van Eenwyk committed Aug 19, 2020
1 parent 95f15c4 commit e0f6f0f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions openhtf/output/callbacks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import collections
import contextlib
import os
import re
import shutil
import tempfile

Expand Down Expand Up @@ -90,6 +92,12 @@ def create_file_name(self, test_record):
record_dict = data.convert_to_base_types(
test_record, ignore_keys=('code_info', 'phases', 'log_records'))
if self._pattern_formattable:
# Reference: https://stackoverflow.com/a/46801075
dut_id = record_dict['dut_id']
dut_id = str(dut_id).strip().replace(' ', '_')
dut_id = re.sub(r'(?u)[^-\w.]', '_', dut_id)
record_dict['dut_id'] = dut_id

return util.format_string(self.filename_pattern, record_dict)
else:
raise ValueError(
Expand Down

0 comments on commit e0f6f0f

Please sign in to comment.