@@ -51,8 +51,6 @@ def _status(msg: str) -> None:
5151 try :
5252 iso_size = os .path .getsize (iso_path )
5353 _status (f"File size: { iso_size :,} bytes ({ iso_size / (1024 ** 3 ):.2f} GiB)" )
54- if progress_cb :
55- progress_cb (2 )
5654
5755 if iso_path .lower ().endswith (".iso" ):
5856 _status (f"Validating ISO9660 signature for: { iso_path } " )
@@ -64,15 +62,8 @@ def _status(msg: str) -> None:
6462 else :
6563 _status (f"Not an ISO file ({ os .path .basename (iso_path )} ), skipping ISO signature check" )
6664
67- if progress_cb :
68- progress_cb (5 )
69-
7065 _status ("Checking if image contains installation markers..." )
71- iso_type = detect_iso_type (iso_path )
72- if progress_cb :
73- progress_cb (8 )
74-
75- if iso_type == IsoType .WINDOWS :
66+ if is_windows_iso (iso_path ):
7667 _status ("Windows Installation media detected, routing to flash_windows (ISO mode)" )
7768 return flash_windows (
7869 device ,
@@ -82,14 +73,12 @@ def _status(msg: str) -> None:
8273 status_cb = status_cb ,
8374 )
8475
76+ iso_type = detect_iso_type (iso_path )
8577 if iso_type == IsoType .LINUX :
8678 _status ("Linux Installation media detected, will use dd for flashing" )
8779 else :
8880 _status ("Generic or unknown image, will use dd for flashing" )
8981
90- if progress_cb :
91- progress_cb (10 )
92-
9382 dd_args = [
9483 "dd" ,
9584 f"if={ iso_path } " ,
@@ -104,11 +93,7 @@ def _status(msg: str) -> None:
10493 _status (f"Writing { iso_size :,} bytes to { shlex .quote (device )} , this may take several minutes..." )
10594
10695 try :
107- # Use LC_ALL=C to ensure "bytes" is the keyword for progress parsing
108- # and set a consistent output format across different locales.
109- env = os .environ .copy ()
110- env ["LC_ALL" ] = "C"
111- process = subprocess .Popen (dd_args , stderr = subprocess .PIPE , stdout = subprocess .DEVNULL , env = env )
96+ process = subprocess .Popen (dd_args , stderr = subprocess .PIPE , stdout = subprocess .DEVNULL )
11297 except FileNotFoundError :
11398 log .error ("Flash failed: 'dd' utility not found. Install coreutils." )
11499 _status ("Flash failed: 'dd' utility not found. Install coreutils." )
@@ -119,43 +104,27 @@ def _status(msg: str) -> None:
119104 buf = b""
120105 last_pct = - 1
121106 while True :
122- # Read in small chunks to handle \r progress updates from dd without blocking
123- # until a newline (\n) is received. status=progress usually emits \r.
124- try :
125- chunk = process .stderr .read (128 )
126- except Exception as e :
127- log .warning ("Error reading dd stderr: %s" , e )
128- break
129-
107+ chunk = process .stderr .readline ()
130108 if not chunk :
131109 break
132110 buf += chunk
133- # Split by \r or \n to catch all progress updates
134111 parts = re .split (rb"[\r\n]" , buf )
135- # The last part might be incomplete, keep it in the buffer
136112 buf = parts [- 1 ]
137-
138113 for line in parts [:- 1 ]:
139114 line = line .strip ()
140115 if not line :
141116 continue
142117 m = re .match (rb"^(\d+)\s+bytes" , line )
143118 if m and iso_size > 0 :
144119 bytes_done = int (m .group (1 ))
145- # Scale progress to 10-95% range to leave room for early steps and final sync
146- pct_raw = min (int (bytes_done * 100 / iso_size ), 100 )
147- pct = 10 + int (pct_raw * 0.85 )
148-
120+ pct = min (int (bytes_done * 100 / iso_size ), 99 )
149121 if pct != last_pct :
150- _status (f"dd progress: { bytes_done :,} / { iso_size :,} bytes ({ pct_raw } %)" )
122+ _status (f"dd progress: { bytes_done :,} / { iso_size :,} bytes ({ pct } %)" )
151123 last_pct = pct
152124 if progress_cb :
153125 progress_cb (pct )
154126 else :
155- # Filter out common dd output lines to avoid logging noise
156- line_str = line .decode ("utf-8" , errors = "replace" )
157- if not any (x in line_str for x in ["records in" , "records out" , "copied" ]):
158- log .warning ("dd stderr: %s" , line_str )
127+ log .warning ("dd stderr: %s" , line .decode ("utf-8" , errors = "replace" ))
159128
160129 process .wait ()
161130 _status (f"dd process exited with return code { process .returncode } " )
0 commit comments