MCPcopy
hub / github.com/opengeos/segment-geospatial / download_file

Function download_file

samgeo/common.py:92–176  ·  view source on GitHub ↗

Download a file from URL, including Google Drive shared URL. Args: url (str, optional): Google Drive URL is also supported. Defaults to None. output (str, optional): Output filename. Default is basename of URL. quiet (bool, optional): Suppress terminal output. Default is

(
    url=None,
    output=None,
    quiet=False,
    proxy=None,
    speed=None,
    use_cookies=True,
    verify=True,
    id=None,
    fuzzy=False,
    resume=False,
    unzip=True,
    overwrite=False,
    subfolder=False,
)

Source from the content-addressed store, hash-verified

90
91
92def download_file(
93 url=None,
94 output=None,
95 quiet=False,
96 proxy=None,
97 speed=None,
98 use_cookies=True,
99 verify=True,
100 id=None,
101 fuzzy=False,
102 resume=False,
103 unzip=True,
104 overwrite=False,
105 subfolder=False,
106):
107 """Download a file from URL, including Google Drive shared URL.
108
109 Args:
110 url (str, optional): Google Drive URL is also supported. Defaults to None.
111 output (str, optional): Output filename. Default is basename of URL.
112 quiet (bool, optional): Suppress terminal output. Default is False.
113 proxy (str, optional): Proxy. Defaults to None.
114 speed (float, optional): Download byte size per second (e.g., 256KB/s = 256 * 1024). Defaults to None.
115 use_cookies (bool, optional): Flag to use cookies. Defaults to True.
116 verify (bool | str, optional): Either a bool, in which case it controls whether the server's TLS certificate is verified, or a string,
117 in which case it must be a path to a CA bundle to use. Default is True.. Defaults to True.
118 id (str, optional): Google Drive's file ID. Defaults to None.
119 fuzzy (bool, optional): Fuzzy extraction of Google Drive's file Id. Defaults to False.
120 resume (bool, optional): Resume the download from existing tmp file if possible. Defaults to False.
121 unzip (bool, optional): Unzip the file. Defaults to True.
122 overwrite (bool, optional): Overwrite the file if it already exists. Defaults to False.
123 subfolder (bool, optional): Create a subfolder with the same name as the file. Defaults to False.
124
125 Returns:
126 str: The output file path.
127 """
128 import zipfile
129
130 try:
131 import gdown
132 except ImportError:
133 print(
134 "The gdown package is required for this function. Use `pip install gdown` to install it."
135 )
136 return
137
138 if output is None:
139 if isinstance(url, str) and url.startswith("http"):
140 output = os.path.basename(url)
141
142 out_dir = os.path.abspath(os.path.dirname(output))
143 if not os.path.exists(out_dir):
144 os.makedirs(out_dir)
145
146 if isinstance(url, str):
147 if os.path.exists(os.path.abspath(output)) and (not overwrite):
148 print(
149 f"{output} already exists. Skip downloading. Set overwrite=True to overwrite."

Callers 15

_download_modelMethod · 0.90
download_sample_dataFunction · 0.90
generateMethod · 0.90
set_imageMethod · 0.90
generateMethod · 0.90
set_imageMethod · 0.90
__init__Method · 0.90
set_imageMethod · 0.90
set_imageMethod · 0.90
predictMethod · 0.90
download_checkpointFunction · 0.85

Calls 1

github_raw_urlFunction · 0.85

Tested by

no test coverage detected