Skip to content

Commit 9ce69ac

Browse files
committed
update script
1 parent 9a1446a commit 9ce69ac

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

scripts/google_utils.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import os
2+
import time
3+
4+
def gdrive_download(id='1HaXkef9z6y5l4vUnCYgdmEAj61c6bfWO', name='coco.zip'):
5+
# https://gist.github.com/tanaikech/f0f2d122e05bf5f971611258c22c110f
6+
# Downloads a file from Google Drive, accepting presented query
7+
# from utils.google_utils import *; gdrive_download()
8+
t = time.time()
9+
10+
print('Downloading https://drive.google.com/uc?export=download&id=%s as %s... ' % (id, name), end='')
11+
os.remove(name) if os.path.exists(name) else None # remove existing
12+
os.remove('cookie') if os.path.exists('cookie') else None
13+
14+
# Attempt file download
15+
os.system("curl -c ./cookie -s -L \"https://drive.google.com/uc?export=download&id=%s\" > /dev/null" % id)
16+
if os.path.exists('cookie'): # large file
17+
s = "curl -Lb ./cookie \"https://drive.google.com/uc?export=download&confirm=`awk '/download/ {print $NF}' ./cookie`&id=%s\" -o %s" % (
18+
id, name)
19+
else: # small file
20+
s = "curl -s -L -o %s 'https://drive.google.com/uc?export=download&id=%s'" % (name, id)
21+
r = os.system(s) # execute, capture return values
22+
os.remove('cookie') if os.path.exists('cookie') else None
23+
24+
# Error check
25+
if r != 0:
26+
os.remove(name) if os.path.exists(name) else None # remove partial
27+
print('Download error ') # raise Exception('Download error')
28+
return r
29+
30+
# Unzip if archive
31+
if name.endswith('.zip'):
32+
print('unzipping... ', end='')
33+
os.system('unzip -q %s' % name) # unzip
34+
os.remove(name) # remove zip to free space
35+
36+
print('Done (%.1fs)' % (time.time() - t))
37+
return r
38+
39+
# gdrive_download("1cewMfusmPjYWbrnuJRuKhPMwRe_b9PaT", name='yolov4.weights')

0 commit comments

Comments
 (0)