55
66
77class BaseArchive (ABC ):
8- def __init__ (self , path ):
8+ def __init__ (self , path , status = None ):
99 self .path = path
10+ self .status = status
11+
12+ def updateStatus (self , type , progress ):
13+ if hasattr (self , "status" ):
14+ self .status .update (type , progress )
1015
1116 def extract (self ):
1217 print ("TODO" )
@@ -23,6 +28,7 @@ def test(path):
2328 return re .search (r"\.tar\.zstd?$" , path )
2429
2530 def extract (self , dir , dry_run = False ):
31+ self .updateStatus ("extract" , 0 )
2632 if not dir :
2733 dir = os .path .dirname (self .path )
2834 base , ext , subext = self .splitext ()
@@ -41,8 +47,10 @@ def extract(self, dir, dry_run=False):
4147 ],
4248 check = True ,
4349 )
50+ subprocess .run (["ls" , "-l" ])
4451 os .remove (self .path )
4552
53+ self .updateStatus ("extract" , 1 )
4654 return dir # , base, ext, subext
4755
4856
@@ -63,6 +71,11 @@ def test(url):
6371
6472 def __init__ (self , url , ** kwargs ):
6573 self .url = url
74+ self .status = kwargs .get ("status" , None )
75+
76+ def updateStatus (self , type , progress ):
77+ if hasattr (self , "status" ):
78+ self .status .update (type , progress )
6679
6780 def splitext (self ):
6881 base , ext = os .path .splitext (self .url )
@@ -77,7 +90,7 @@ def download_file(self, dest):
7790 """Download the file to `dest`"""
7891 pass
7992
80- def download_and_extract (self , fname , dry_run = False ):
93+ def download_and_extract (self , fname , dir = None , dry_run = False ):
8194 """
8295 Downloads the file, and if it's an archive, extract it too. Returns
8396 the filename if not, or directory name (fname without extension) if
@@ -86,12 +99,11 @@ def download_and_extract(self, fname, dry_run=False):
8699 if not fname :
87100 fname = self .get_filename ()
88101
89- dir = None
90- archive = Archive (fname , dry_run = dry_run )
102+ archive = Archive (fname , status = self .status )
91103 if archive :
92104 # TODO, streaming pipeline
93105 self .download_file (fname )
94- return archive .extract ()
106+ return archive .extract (dir )
95107 else :
96108 self .download_file (fname )
97109 return fname
0 commit comments