3
3
import platform
4
4
import shutil
5
5
import subprocess
6
- import sys
7
6
from contextlib import contextmanager
8
7
from fnmatch import fnmatch
9
8
from shutil import which
10
9
11
10
12
11
from conans .client .downloaders .caching_file_downloader import SourcesCachingDownloader
13
12
from conan .errors import ConanException
13
+ from conans .client .rest .file_uploader import FileProgress
14
14
from conans .util .files import rmdir as _internal_rmdir , human_size , check_with_algorithm_sum
15
15
16
16
@@ -261,7 +261,6 @@ def chdir(conanfile, newdir):
261
261
finally :
262
262
os .chdir (old_path )
263
263
264
-
265
264
def unzip (conanfile , filename , destination = "." , keep_permissions = False , pattern = None ,
266
265
strip_root = False , extract_filter = None ):
267
266
"""
@@ -305,20 +304,7 @@ def unzip(conanfile, filename, destination=".", keep_permissions=False, pattern=
305
304
import zipfile
306
305
full_path = os .path .normpath (os .path .join (os .getcwd (), destination ))
307
306
308
- if hasattr (sys .stdout , "isatty" ) and sys .stdout .isatty ():
309
- def print_progress (the_size , uncomp_size ):
310
- the_size = (the_size * 100.0 / uncomp_size ) if uncomp_size != 0 else 0
311
- txt_msg = "Unzipping %d %%"
312
- if the_size > print_progress .last_size + 1 :
313
- output .rewrite_line (txt_msg % the_size )
314
- print_progress .last_size = the_size
315
- if int (the_size ) == 99 :
316
- output .rewrite_line (txt_msg % 100 )
317
- else :
318
- def print_progress (_ , __ ):
319
- pass
320
-
321
- with zipfile .ZipFile (filename , "r" ) as z :
307
+ with FileProgress (filename , msg = "Unzipping" , mode = "r" ) as file , zipfile .ZipFile (file ) as z :
322
308
zip_info = z .infolist ()
323
309
if pattern :
324
310
zip_info = [zi for zi in zip_info if fnmatch (zi .filename , pattern )]
@@ -343,19 +329,16 @@ def print_progress(_, __):
343
329
output .info ("Unzipping %s" % human_size (uncompress_size ))
344
330
extracted_size = 0
345
331
346
- print_progress .last_size = - 1
347
332
if platform .system () == "Windows" :
348
333
for file_ in zip_info :
349
334
extracted_size += file_ .file_size
350
- print_progress (extracted_size , uncompress_size )
351
335
try :
352
336
z .extract (file_ , full_path )
353
337
except Exception as e :
354
338
output .error (f"Error extract { file_ .filename } \n { str (e )} " , error_type = "exception" )
355
339
else : # duplicated for, to avoid a platform check for each zipped file
356
340
for file_ in zip_info :
357
341
extracted_size += file_ .file_size
358
- print_progress (extracted_size , uncompress_size )
359
342
try :
360
343
z .extract (file_ , full_path )
361
344
if keep_permissions :
@@ -367,11 +350,10 @@ def print_progress(_, __):
367
350
output .error (f"Error extract { file_ .filename } \n { str (e )} " , error_type = "exception" )
368
351
output .writeln ("" )
369
352
370
-
371
353
def untargz (filename , destination = "." , pattern = None , strip_root = False , extract_filter = None ):
372
354
# NOT EXPOSED at `conan.tools.files` but used in tests
373
355
import tarfile
374
- with tarfile .TarFile .open (filename , 'r:*' ) as tarredgzippedFile :
356
+ with FileProgress ( filename , msg = "Uncompressing" ) as fileobj , tarfile .TarFile .open (fileobj = fileobj , mode = 'r:*' ) as tarredgzippedFile :
375
357
f = getattr (tarfile , f"{ extract_filter } _filter" , None ) if extract_filter else None
376
358
tarredgzippedFile .extraction_filter = f or (lambda member_ , _ : member_ )
377
359
if not pattern and not strip_root :
0 commit comments