forked from drprojects/superpoint_transformer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
download.py
57 lines (49 loc) · 1.42 KB
/
download.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import os
import os.path as osp
from six.moves import urllib
import ssl
import subprocess
def download_url(url, folder, log=True):
"""Download the content of an URL to a specific folder.
:param url: string
:param folder: string
:param log: bool
If `False`, will not print anything to the console.
:return:
"""
filename = url.rpartition("/")[2]
path = osp.join(folder, filename)
if osp.exists(path): # pragma: no cover
if log:
print("Using exist file", filename)
return path
if log:
print("Downloading", url)
try:
os.makedirs(folder)
except:
pass
context = ssl._create_unverified_context()
data = urllib.request.urlopen(url, context=context)
with open(path, "wb") as f:
f.write(data.read())
return path
def run_command(cmd):
"""Run a command-line process from Python and print its outputs in
an online fashion.
Credit: https://www.endpointdev.com/blog/2015/01/getting-realtime-output-using-python/
"""
# Create the process
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
# p = subprocess.run(cmd, shell=True)
# Poll process.stdout to show stdout live
while True:
output = p.stdout.readline()
if p.poll() is not None:
break
if output:
print(output.strip())
rc = p.poll()
print('Done')
print('')
return rc