From f8902ccb228946b1a4a4ece2c83184fd7ad0338d Mon Sep 17 00:00:00 2001 From: Jonathan Van Eenwyk Date: Mon, 10 Aug 2020 09:46:36 -0700 Subject: [PATCH] Ensure output directory exists If needed, create the directory for the intended output file. This allows outputs to be grouped into subdirectories instead of only in the main history directory. --- openhtf/output/callbacks/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/openhtf/output/callbacks/__init__.py b/openhtf/output/callbacks/__init__.py index d29ce4531..63911b7ce 100644 --- a/openhtf/output/callbacks/__init__.py +++ b/openhtf/output/callbacks/__init__.py @@ -22,6 +22,7 @@ import collections import contextlib +import os import shutil import tempfile @@ -82,6 +83,10 @@ def serialize_test_record(test_record): @staticmethod def open_file(filename): """Override method to alter file open behavior or file types.""" + basepath = os.path.dirname(filename) + if not os.path.exists(basepath): + os.makedirs(basepath) + return Atomic(filename) def create_file_name(self, test_record):