def _get_file(self, params, directory=None, overwrite=False): """Downloads a file and return the filepath to that file""" # Query Helioviewer.org if directory is None: directory = sunpy.config.get('downloads', 'download_dir') else: directory = os.path.abspath(os.path.expanduser(directory)) response = self._request(params) try: filepath = download_fileobj(response, directory, overwrite=overwrite) finally: response.close() return filepath
def _get_file(self, params, directory=None, overwrite=False): """Downloads a file and return the filepath to that file.""" if directory is None: directory = sunpy.config.get('downloads', 'download_dir') else: directory = os.path.abspath(os.path.expanduser(directory)) try: os.makedirs(directory) except OSError as e: # TODO: Check this if e.errno != errno.EEXIST: raise OSError('Tried to create a directory and it failed.') response = self._request(params) try: filepath = download_fileobj(response, directory, overwrite=overwrite) finally: response.close() return filepath