Updated the "output" for Analysis task
This commit is contained in:
@@ -15,6 +15,7 @@ import json
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import re # Import the regular expression module
|
||||
import tempfile
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
@@ -28,18 +29,15 @@ class Tee:
|
||||
|
||||
def write(self, obj):
|
||||
# For regular file writes (like logs), replace carriage returns with newlines
|
||||
# to ensure each progress update is on a new line. Also strip ANSI codes.
|
||||
log_obj = re.sub(r'\x1B\[[0-?]*[ -/]*[@-~]', '', obj).replace('\r', '\n')
|
||||
# to ensure each progress update is on a new line.
|
||||
log_obj = obj.replace('\r', '\n')
|
||||
|
||||
for f in self.files:
|
||||
if f in self.terminals:
|
||||
# For terminals, write the object as-is.
|
||||
# The calling code will handle ANSI escape codes for clearing the line.
|
||||
# The `\r` at the end of the object ensures the cursor returns to the start.
|
||||
# The `\x1B[K` escape code clears from the cursor to the end of the line.
|
||||
if obj.endswith('\r'):
|
||||
# This is a progress line. Clear the line and write.
|
||||
f.write(obj.strip() + '\x1B[K\r')
|
||||
# This is a progress line. Pad with spaces to clear the line, then add carriage return.
|
||||
terminal_width = shutil.get_terminal_size(fallback=(80, 24)).columns
|
||||
f.write(obj.strip().ljust(terminal_width) + '\r')
|
||||
else:
|
||||
# This is regular output.
|
||||
f.write(obj)
|
||||
@@ -117,7 +115,7 @@ def convert_audio_track(stream_index, channels, temp_dir, source_file, should_do
|
||||
# Read stderr and print progress updates. The Tee class now handles '\r' correctly.
|
||||
stderr_output = ""
|
||||
for line in iter(process.stderr.readline, ''):
|
||||
stderr_output += line
|
||||
stderr_output += line.strip() + '\n' # Store clean lines for parsing
|
||||
# Write the line, ending with a carriage return to reset the line position.
|
||||
# The Tee class will convert this to a newline for the log file.
|
||||
sys.stdout.write(line.strip() + '\r')
|
||||
|
||||
Reference in New Issue
Block a user