From 20707c8cb264d61ccf55f1421603fb9b8dad85eb Mon Sep 17 00:00:00 2001 From: Michael Joyce Date: Fri, 10 Apr 2015 12:49:23 -0700 Subject: [PATCH] CLIMATE-621 - Add configurable save directory to ESGF data source --- ocw/data_source/esgf.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ocw/data_source/esgf.py b/ocw/data_source/esgf.py index fd773d78..3493fc0c 100644 --- a/ocw/data_source/esgf.py +++ b/ocw/data_source/esgf.py @@ -17,6 +17,7 @@ # under the License. # +import os import urllib2 from ocw.esgf.constants import DEFAULT_ESGF_SEARCH @@ -35,6 +36,7 @@ def load_dataset(dataset_id, search_url=DEFAULT_ESGF_SEARCH, elevation_index=0, name='', + save_path='/tmp', **additional_constraints): ''' Load an ESGF dataset. @@ -61,6 +63,9 @@ def load_dataset(dataset_id, :param name: (Optional) A name for the loaded dataset. :type name: :mod:`string` + :param save_path: (Optional) Path to where downloaded files should be saved. + :type save_path: :mod:`string` + :param additional_constraints: (Optional) Additional key,value pairs to pass as constraints to the search wrapper. These can be anything found on the ESGF metadata page for a dataset. @@ -78,8 +83,13 @@ def load_dataset(dataset_id, datasets = [] for url, var in download_data: - _download_files([url], esgf_username, esgf_password) - datasets.append(local.load_file('/tmp/' + url.split('/')[-1], + _download_files([url], + esgf_username, + esgf_password, + download_directory=save_path) + + file_save_path = os.path.join(save_path, url.split('/')[-1]) + datasets.append(local.load_file(file_save_path, var, name=name, elevation_index=elevation_index))