Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make use of tempfile when writing stdout content for 'buildtest build' #1605

Merged
merged 2 commits into from
Aug 29, 2023
Merged
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
13 changes: 8 additions & 5 deletions buildtest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import shutil
import tempfile
import webbrowser

from rich.traceback import install
Expand Down Expand Up @@ -47,7 +48,6 @@
BUILDTEST_EXECUTOR_DIR,
BUILDTEST_LOGFILE,
BUILDTEST_USER_HOME,
VAR_DIR,
console,
)
from buildtest.exceptions import BuildTestError
Expand Down Expand Up @@ -144,9 +144,8 @@ def main():

# buildtest build command
if args.subcommands in ["build", "bd"]:
fname = os.path.join(VAR_DIR, "output.txt")

with Tee(fname):
stdout_file = tempfile.NamedTemporaryFile(delete=True, suffix=".txt")
with Tee(stdout_file.name):
cmd = BuildTest(
configuration=configuration,
buildspecs=args.buildspec,
Expand Down Expand Up @@ -183,7 +182,11 @@ def main():
if cmd.build_success():
build_history_dir = cmd.get_build_history_dir()

shutil.move(fname, os.path.join(build_history_dir, "output.txt"))
shutil.copyfile(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a good idea to close the file before you copy it in case any write buffering or something else random happens.

stdout_file.name, os.path.join(build_history_dir, "output.txt")
)

stdout_file.close()

# buildtest build history
if args.subcommands in ["history", "hy"]:
Expand Down
Loading