Skip to content

Commit

Permalink
Merge pull request #1452 from bsipocz/data_adding_overwrite_to_downlo…
Browse files Browse the repository at this point in the history
…ad_sample

Add overwrite option to sample download to avoid unnecessary downloads
  • Loading branch information
Cadair committed Jun 20, 2015
2 parents 4f5729c + a5b2763 commit 1c873b3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion sunpy/data/_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@
sample_files[key] = os.path.abspath(os.path.join(sampledata_dir, _files[key][0]))


def download_sample_data(progress=True):
def download_sample_data(progress=True, overwrite=True):
"""
Download the sample data.
Parameters
----------
progress: bool
Show a progress bar during download
overwrite: bool
If exist overwrites the downloaded sample data.
Returns
-------
Expand All @@ -59,6 +61,12 @@ def download_sample_data(progress=True):
number_of_files_fetched = 0
print("Downloading sample files to " + sampledata_dir)
for file_name in _files.itervalues():
if not overwrite:
if os.path.isfile(os.path.join(sampledata_dir,
file_name[0])):
number_of_files_fetched += 1
continue

for base_url in _base_urls:
full_file_name = file_name[0] + file_name[1]
if url_exists(os.path.join(base_url, full_file_name)):
Expand Down

0 comments on commit 1c873b3

Please sign in to comment.