1919from rich .progress import track
2020
2121from mpflash .common import PORT_FWTYPES , FWInfo
22+ from mpflash .downloaded import clean_downloaded_firmwares
2223from mpflash .errors import MPFlashError
2324from mpflash .mpboard_id import get_known_ports
2425from mpflash .vendor .versions import clean_version
@@ -194,6 +195,17 @@ def download_firmwares(
194195 force : bool = False ,
195196 clean : bool = True ,
196197) -> int :
198+ """
199+ Downloads firmware files based on the specified firmware folder, ports, boards, versions, force flag, and clean flag.
200+
201+ Args:
202+ firmware_folder : The folder to save the downloaded firmware files.
203+ ports : The list of ports to check for firmware.
204+ boards : The list of boards to download firmware for.
205+ versions : The list of versions to download firmware for.
206+ force : A flag indicating whether to force the download even if the firmware file already exists.
207+ clean : A flag indicating to clean the date from the firmware filename.
208+ """
197209 skipped = downloaded = 0
198210 versions = [] if versions is None else [clean_version (v ) for v in versions ]
199211 # handle renamed boards
@@ -234,6 +246,8 @@ def download_firmwares(
234246 continue
235247 writer .write (board .to_dict ())
236248 downloaded += 1
249+ if downloaded > 0 :
250+ clean_downloaded_firmwares (firmware_folder )
237251 log .success (f"Downloaded { downloaded } firmwares, skipped { skipped } existing files." )
238252 return downloaded + skipped
239253
@@ -295,7 +309,7 @@ def download(
295309 boards : The list of boards to download firmware for.
296310 versions : The list of versions to download firmware for.
297311 force : A flag indicating whether to force the download even if the firmware file already exists.
298- clean : A flag indicating whether to perform a clean download .
312+ clean : A flag indicating whether to clean the date from the firmware filename .
299313
300314 Returns:
301315 int: The number of downloaded firmware files.
@@ -308,7 +322,6 @@ def download(
308322 log .critical ("No boards found, please connect a board or specify boards to download firmware for." )
309323 raise MPFlashError ("No boards found" )
310324
311- # versions = [clean_version(v, drop_v=True) for v in versions] # remove leading v from version
312325 try :
313326 destination .mkdir (exist_ok = True , parents = True )
314327 except (PermissionError , FileNotFoundError ) as e :
0 commit comments