Repository: climate Updated Branches: refs/heads/master 14e980fa6 -> c9be83458
CLIMATE-621 - Add configurable save directory to ESGF data source Project: http://git-wip-us.apache.org/repos/asf/climate/repo Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/20707c8c Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/20707c8c Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/20707c8c Branch: refs/heads/master Commit: 20707c8cb264d61ccf55f1421603fb9b8dad85eb Parents: 5207dda Author: Michael Joyce <[email protected]> Authored: Fri Apr 10 12:49:23 2015 -0700 Committer: Michael Joyce <[email protected]> Committed: Fri Apr 10 12:49:23 2015 -0700 ---------------------------------------------------------------------- ocw/data_source/esgf.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/climate/blob/20707c8c/ocw/data_source/esgf.py ---------------------------------------------------------------------- diff --git a/ocw/data_source/esgf.py b/ocw/data_source/esgf.py index fd773d7..3493fc0 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))
