def is_thredds_up(config):
    """
    Is the THREDDS Server running?
    :param config: Pylons configuration
    :return:
    """
    if config.get('run_in_test_mode') == 'true':
        return True
    else:
        try:
            create_request_and_open_url(
                config['thredds.server_url'],
                timeout=int(config['thredds.server_timeout'])).read()
            return True
        except:
            return False
Example #2
0
    def base(self):
        """
        Indirection layer to enable a base map wms service to be wrapped up in our domain
        """

        redirect_url = "http://vmap0.tiles.osgeo.org/wms/vmap0?%s" % request.query_string
        map_request = wmc_util.create_request_and_open_url(redirect_url, external=True)
        return Response(body=map_request.read(), content_type='image/jpeg')
Example #3
0
        def new_request(url):
            """
            Create a new dap request
            :param url: the url
            :return: headers and body tuple
            """
            log = logging.getLogger('pydap')
            log.info('Opening %s' % url)

            f = create_request_and_open_url(url.rstrip('?&'))
            headers = dict(f.info().items())
            body = f.read()
            return headers, body
 def download_file_generator(self, file_path, model_run):
     """
     Download an output file from the THREDDS file server and serve it to the user
     :param file_path: File path to download
     :param model_run: Model run
     :return: Generator (for streamed download)
     """
     url = self.dap_client_factory.get_full_url_for_file(file_path, service="fileServer", config=self.config)
     dataset = create_request_and_open_url(url)
     while True:
         chunk = dataset.read(constants.GENERATORS_SIZE_TO_READ)
         if not chunk:
             break
         yield chunk
Example #5
0
    def wms(self, id):
        """ Indirection layer between ecomaps and the underlying dataset mapping
        server (currently THREDDS)
            @param id - ID of the dataset containing the real URL to the data
        """

        log.debug("Request for %s" % request.query_string)
        user = self._user_service.get_user_by_username(request.environ['REMOTE_USER'])
        ds = self._dataset_service.get_dataset_by_id(id, user_id=user.id)

        redirect_url = "%s?%s" % (ds.wms_url.split('?')[0], request.query_string)

        log.debug("Redirecting to %s" % redirect_url)
        try:
            return wmc_util.create_request_and_open_url(redirect_url, external=False).read()
        except urllib2.HTTPError, e:
            log.exception("exception occurred while access {}".format(redirect_url))
            log.exception("Page read {}".format(e.fp.read()))
            raise e
    def set_response_header(self, header_dict, filepath, model_run, var_name, period, year):
        """
        Set the download information on a Pylons header
        :param header_dict: Pylons Header (response.header)
        :param filepath: File path (relative to run dir)
        :param var_name: Variable name being downloaded
        :param period: Period of run
        :param model_run: Model run
        :param year: Year to download (or None)
        :return:
        """
        # Get the HTTP header from THREDDS to identify the file size
        url = self.dap_client_factory.get_full_url_for_file(filepath, service="fileServer", config=self.config)
        head = create_request_and_open_url(url, method='HEAD').headers

        filename = self._get_filename_for_download(model_run, var_name, period, year, ".nc")
        header_dict['Content-Type'] = str(head['Content-Type'])
        header_dict['Content-Disposition'] = str('attachment; filename="%s"' % filename)
        header_dict['Content-Length'] = str(head['Content-Length'])