3131import shutil
3232import stat
3333import subprocess
34+ import tarfile
3435from urllib .parse import urlparse
3536import path_cleaner
3637
@@ -155,7 +156,8 @@ def clone(name: str, url: str, ref: str = None):
155156
156157
157158def download (name : str , url : str ):
158- """Directly downloads some sort of compressed format file and decompresses it using a system-installed 7-zip"""
159+ """Directly downloads some sort of compressed format file and decompresses it (either using an internal
160+ python method, or using a system-installed 7-zip)"""
159161 print (f"Downloading { name } from { url } " )
160162 os .mkdir (name )
161163 request_result = requests .get (url )
@@ -169,12 +171,31 @@ def download(name: str, url: str):
169171def decompress (name : str , filename : str ):
170172 original_dir = os .getcwd ()
171173 os .chdir (name )
172- try :
173- subprocess .run ([path_to_7zip , "x" , filename ], capture_output = True , check = True )
174- except subprocess .CalledProcessError as e :
175- print ("ERROR: failed to unzip {filename} at from {name} using {path_to_7zip}" )
176- print (e .output )
177- exit (e .returncode )
174+ if filename .endswith ("7z" ) or filename .endswith ("7zip" ):
175+ try :
176+ subprocess .run ([path_to_7zip , "x" , filename ], capture_output = True , check = True )
177+ except subprocess .CalledProcessError as e :
178+ print ("ERROR: failed to unzip {filename} at from {name} using {path_to_7zip}" )
179+ print (e .output )
180+ exit (e .returncode )
181+ elif (
182+ filename .endswith (".tar.gz" )
183+ or filename .endswith (".tar.bz2" )
184+ or filename .endswith (".tar.xz" )
185+ ):
186+ try :
187+ with tarfile .open (filename ) as f :
188+ f .extractall (filter = "data" )
189+ except tarfile .TarError as e :
190+ print (e )
191+ exit (1 )
192+ else : # Try to use 7-zip to see if it's something understandable to that program
193+ try :
194+ subprocess .run ([path_to_7zip , "x" , filename ], capture_output = True , check = True )
195+ except subprocess .CalledProcessError as e :
196+ print ("ERROR: failed to unzip {filename} at from {name} using {path_to_7zip}" )
197+ print (e .output )
198+ exit (e .returncode )
178199 os .chdir (original_dir )
179200
180201
0 commit comments