11
11
12
12
13
13
def get_filename_from_url (url : str ) -> str :
14
- local_filename = url .split ('/' )[- 1 ]
14
+ local_filename = url .split ("/" )[- 1 ]
15
15
return os .path .join (meshes_path , local_filename )
16
16
17
17
18
18
def is_download_needed (target_file_path : str ) -> bool :
19
19
if not os .path .exists (meshes_path ):
20
20
os .mkdir (meshes_path )
21
21
return True
22
- if not os .path .exists (os .path .join (meshes_path , ' trees' )):
23
- if not os .path .isfile (os .path .join (meshes_path , ' pybullet-tree-sim-meshes.zip' )): # TODO: pass name into func
22
+ if not os .path .exists (os .path .join (meshes_path , " trees" )):
23
+ if not os .path .isfile (os .path .join (meshes_path , " pybullet-tree-sim-meshes.zip" )): # TODO: pass name into func
24
24
return True
25
25
else :
26
26
return False
27
27
else :
28
28
return False
29
29
30
+
30
31
def is_unzip_needed (target_file_path : str ) -> bool :
31
- if not os .path .exists (os .path .join (meshes_path , ' trees' )):
32
+ if not os .path .exists (os .path .join (meshes_path , " trees" )):
32
33
return True
33
34
else :
34
35
return False
@@ -40,25 +41,24 @@ def download_file(url: str, target_file_path: str) -> bool:
40
41
with requests .get (url , stream = True ) as r :
41
42
r .raise_for_status ()
42
43
total_size = int (r .headers .get ("content-length" , 0 ))
43
- with tqdm (total = total_size , unit = 'B' , unit_scale = True ) as progress_bar :
44
- with open (target_file_path , 'wb' ) as f :
45
- for chunk in r .iter_content (chunk_size = 8192 ):
44
+ with tqdm (total = total_size , unit = "B" , unit_scale = True ) as progress_bar :
45
+ with open (target_file_path , "wb" ) as f :
46
+ for chunk in r .iter_content (chunk_size = 8192 ):
46
47
# If you have chunk encoded response uncomment if
47
48
# and set chunk_size parameter to None.
48
- # if chunk:
49
+ # if chunk:
49
50
progress_bar .update (len (chunk ))
50
51
f .write (chunk )
51
-
52
+
52
53
return True
53
-
54
+
54
55
except Exception as e :
55
- print (f' { e } ' )
56
+ print (f" { e } " )
56
57
return False
57
-
58
58
59
59
60
60
def unzip (zip_file : str ):
61
- with zipfile .ZipFile (zip_file , 'r' ) as zipper :
61
+ with zipfile .ZipFile (zip_file , "r" ) as zipper :
62
62
zipper .extractall (os .path .dirname (zip_file ))
63
63
return
64
64
@@ -71,7 +71,7 @@ def main():
71
71
download_needed = is_download_needed (target_file_path = file_abs_path )
72
72
if download_needed :
73
73
download_file (url = url , target_file_path = file_abs_path )
74
-
74
+
75
75
unzip_needed = is_unzip_needed (target_file_path = file_abs_path )
76
76
if unzip_needed :
77
77
unzip (zip_file = file_abs_path )
0 commit comments