Updated the "output" for Analysis task
This commit is contained in:
@@ -15,6 +15,7 @@ import json
|
|||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import re # Import the regular expression module
|
||||||
import tempfile
|
import tempfile
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -28,18 +29,15 @@ class Tee:
|
|||||||
|
|
||||||
def write(self, obj):
|
def write(self, obj):
|
||||||
# For regular file writes (like logs), replace carriage returns with newlines
|
# 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.
|
# to ensure each progress update is on a new line.
|
||||||
log_obj = re.sub(r'\x1B\[[0-?]*[ -/]*[@-~]', '', obj).replace('\r', '\n')
|
log_obj = obj.replace('\r', '\n')
|
||||||
|
|
||||||
for f in self.files:
|
for f in self.files:
|
||||||
if f in self.terminals:
|
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'):
|
if obj.endswith('\r'):
|
||||||
# This is a progress line. Clear the line and write.
|
# This is a progress line. Pad with spaces to clear the line, then add carriage return.
|
||||||
f.write(obj.strip() + '\x1B[K\r')
|
terminal_width = shutil.get_terminal_size(fallback=(80, 24)).columns
|
||||||
|
f.write(obj.strip().ljust(terminal_width) + '\r')
|
||||||
else:
|
else:
|
||||||
# This is regular output.
|
# This is regular output.
|
||||||
f.write(obj)
|
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.
|
# Read stderr and print progress updates. The Tee class now handles '\r' correctly.
|
||||||
stderr_output = ""
|
stderr_output = ""
|
||||||
for line in iter(process.stderr.readline, ''):
|
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.
|
# 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.
|
# The Tee class will convert this to a newline for the log file.
|
||||||
sys.stdout.write(line.strip() + '\r')
|
sys.stdout.write(line.strip() + '\r')
|
||||||
|
|||||||
Reference in New Issue
Block a user