Download the data from source url, unless it's already here. Args: filename: string, name of the file in the directory. work_directory: string, path to working directory. source_url: url to download from if file doesn't exist. Returns: Path to resulting file.
(filename, work_directory, source_url)
| 235 | |
| 236 | @deprecated(None, 'Please write your own downloading logic.') |
| 237 | def maybe_download(filename, work_directory, source_url): |
| 238 | """Download the data from source url, unless it's already here. |
| 239 | |
| 240 | Args: |
| 241 | filename: string, name of the file in the directory. |
| 242 | work_directory: string, path to working directory. |
| 243 | source_url: url to download from if file doesn't exist. |
| 244 | |
| 245 | Returns: |
| 246 | Path to resulting file. |
| 247 | """ |
| 248 | if not gfile.Exists(work_directory): |
| 249 | gfile.MakeDirs(work_directory) |
| 250 | filepath = os.path.join(work_directory, filename) |
| 251 | if not gfile.Exists(filepath): |
| 252 | temp_file_name, _ = urlretrieve_with_retry(source_url) |
| 253 | gfile.Copy(temp_file_name, filepath) |
| 254 | with gfile.GFile(filepath) as f: |
| 255 | size = f.size() |
| 256 | print('Successfully downloaded', filename, size, 'bytes.') |
| 257 | return filepath |
nothing calls this directly
no test coverage detected