Fix curl download on Windows (#669)
Browse files* Update ci-testing.yml
* Fix windows download
* Fix cookie and curl download issue from gdrive
* Revert "Update ci-testing.yml"
This reverts commit 7389d2238df4dd8bd3b6ddded0f12e551c8fd0b1.
* Update google_utils.py
PEP8
* Update google_utils.py
Co-authored-by: Glenn Jocher <[email protected]>
- utils/google_utils.py +14 -4
utils/google_utils.py
CHANGED
@@ -3,6 +3,7 @@
|
|
3 |
# from google.cloud import storage
|
4 |
|
5 |
import os
|
|
|
6 |
import time
|
7 |
from pathlib import Path
|
8 |
|
@@ -27,7 +28,7 @@ def attempt_download(weights):
|
|
27 |
|
28 |
if not (r == 0 and os.path.exists(weights) and os.path.getsize(weights) > 1E6): # weights exist and > 1MB
|
29 |
os.remove(weights) if os.path.exists(weights) else None # remove partial downloads
|
30 |
-
s =
|
31 |
r = os.system(s) # execute, capture return values
|
32 |
|
33 |
# Error check
|
@@ -46,10 +47,11 @@ def gdrive_download(id='1n_oKgR81BJtqk75b00eAjdv03qVCQn2f', name='coco128.zip'):
|
|
46 |
os.remove('cookie') if os.path.exists('cookie') else None
|
47 |
|
48 |
# Attempt file download
|
49 |
-
|
|
|
50 |
if os.path.exists('cookie'): # large file
|
51 |
-
s =
|
52 |
-
id, name)
|
53 |
else: # small file
|
54 |
s = 'curl -s -L -o %s "drive.google.com/uc?export=download&id=%s"' % (name, id)
|
55 |
r = os.system(s) # execute, capture return values
|
@@ -71,6 +73,14 @@ def gdrive_download(id='1n_oKgR81BJtqk75b00eAjdv03qVCQn2f', name='coco128.zip'):
|
|
71 |
return r
|
72 |
|
73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
# def upload_blob(bucket_name, source_file_name, destination_blob_name):
|
75 |
# # Uploads a file to a bucket
|
76 |
# # https://cloud.google.com/storage/docs/uploading-objects#storage-upload-object-python
|
|
|
3 |
# from google.cloud import storage
|
4 |
|
5 |
import os
|
6 |
+
import platform
|
7 |
import time
|
8 |
from pathlib import Path
|
9 |
|
|
|
28 |
|
29 |
if not (r == 0 and os.path.exists(weights) and os.path.getsize(weights) > 1E6): # weights exist and > 1MB
|
30 |
os.remove(weights) if os.path.exists(weights) else None # remove partial downloads
|
31 |
+
s = 'curl -L -o %s "storage.googleapis.com/ultralytics/yolov5/ckpt/%s"' % (weights, file)
|
32 |
r = os.system(s) # execute, capture return values
|
33 |
|
34 |
# Error check
|
|
|
47 |
os.remove('cookie') if os.path.exists('cookie') else None
|
48 |
|
49 |
# Attempt file download
|
50 |
+
out = "NUL" if platform.system() == "Windows" else "/dev/null"
|
51 |
+
os.system('curl -c ./cookie -s -L "drive.google.com/uc?export=download&id=%s" > %s ' % (id, out))
|
52 |
if os.path.exists('cookie'): # large file
|
53 |
+
s = 'curl -Lb ./cookie "drive.google.com/uc?export=download&confirm=%s&id=%s" -o %s' % (
|
54 |
+
get_token(), id, name)
|
55 |
else: # small file
|
56 |
s = 'curl -s -L -o %s "drive.google.com/uc?export=download&id=%s"' % (name, id)
|
57 |
r = os.system(s) # execute, capture return values
|
|
|
73 |
return r
|
74 |
|
75 |
|
76 |
+
def get_token(cookie="./cookie"):
|
77 |
+
with open(cookie) as f:
|
78 |
+
for line in f:
|
79 |
+
if "download" in line:
|
80 |
+
return line.split()[-1]
|
81 |
+
return ""
|
82 |
+
|
83 |
+
|
84 |
# def upload_blob(bucket_name, source_file_name, destination_blob_name):
|
85 |
# # Uploads a file to a bucket
|
86 |
# # https://cloud.google.com/storage/docs/uploading-objects#storage-upload-object-python
|