Skip to content

Commit

Permalink
Merge pull request #821 from Webperf-se/output-ensure-path
Browse files Browse the repository at this point in the history
Ensures that the parent directory of the output file exists
  • Loading branch information
7h3Rabbit authored Dec 28, 2024
2 parents d6ab297 + e19c648 commit 1708d9c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions helpers/test_helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import json
from datetime import datetime
import os
import traceback
from helpers.setting_helper import get_config, get_used_configuration
from helpers.models import SiteTests
Expand Down Expand Up @@ -350,5 +351,26 @@ def write_test_results(sites, output_filename, test_results, global_translation)
else:
write_tests = json_write_tests

ensure_parent_path(output_filename)

# use loaded engine to write tests
write_tests(output_filename, test_results, sites, global_translation)

def ensure_parent_path(output_filename):
"""
Ensures that the parent directory of the output file exists.
This function takes an output filename and
ensures that the directory structure up to the file exists.
It handles both relative and absolute paths.
Parameters:
output_filename (str): The name of the output file.
Returns: None
"""

# Get the absolute path of the output file
abs_path = os.path.abspath(output_filename)
# Get the parent directory of the output file
parent_dir = os.path.dirname(abs_path)
# Create the parent directory if it doesn't exist
if not os.path.exists(parent_dir):
os.makedirs(parent_dir)

0 comments on commit 1708d9c

Please sign in to comment.