Exemple #1
0
    def view(self):

        log = logging.getLogger(__name__)
        log.debug('Processing view request in CSV API v1')

        data_url = self.request.GET.getone('data_url')

        out_str = '<table>'

        MyDataMover = FDataMover.get_data_mover_class()
        with MyDataMover.open(data_url=data_url) as csvfile:
            # TODO: Change this to use list comprehension, or to process the csv file in
            # the template.
            first = True
            for row in csv.reader(csvfile):
                if first:
                    out_str = out_str + "<thead>"
                    out_str = out_str + "<tr>"
                    for el in row:
                        out_str = (out_str + "<th>" + el + "</th>")
                    out_str = out_str + "</tr>"
                    out_str = out_str + "</thead><tbody>"
                    first = False
                else:
                    out_str = out_str + "<tr>"
                    for el in row:
                        out_str = (out_str + "<td>" + el + "</td>")
                    out_str = out_str + "</tr>"

            out_str = out_str + '</tbody></table>'

        return {'file_content': out_str}
    def view(self):

        log = logging.getLogger(__name__)
        log.debug('Processing view request in CSV API v1')

        data_url = self.request.GET.getone('data_url')

        tf = tempfile.NamedTemporaryFile(delete=False, prefix='csv_view_v1_', suffix='.csv')
        file_path = tf.name

        out_str = '<table>'

        MyDataMover = FDataMover.get_data_mover_class()
        with MyDataMover.open(data_url=data_url) as csvfile:
            # TODO: Change this to use list comprehension, or to process the csv file in
            # the template.
            first = True
            for row in csv.reader(csvfile):
                if first:
                    out_str = out_str + "<thead>"
                    out_str = out_str + "<tr>"
                    for el in row:
                        out_str = ( out_str + "<th>" + el + "</th>" )
                    out_str = out_str + "</tr>"
                    out_str = out_str + "</thead><tbody>"
                    first = False
                else:
                    out_str = out_str + "<tr>"
                    for el in row:
                        out_str = ( out_str + "<td>" + el + "</td>" )
                    out_str = out_str + "</tr>"

            out_str = out_str + '</tbody></table>'

        return { 'file_content': out_str }
Exemple #3
0
    def visualise_html_zip(self, data_url):
        MyDataMover = FDataMover.get_data_mover_class()

        # Download the zip file
        zip_file_path = MyDataMover.download(data_url=data_url, suffix='.zip')

        time_epoch = int(time.time() * 1000)
        dir_path = '/html_zip_' + str(time_epoch)
        os.mkdir(MyDataMover.PUBLIC_DIR + dir_path)

        try:
            fh = open(zip_file_path, 'rb')
            z = zipfile.ZipFile(fh)
            for name in z.namelist():
                dir_file_path = dir_path + '/' + name
                # write the file
                fd = open(MyDataMover.PUBLIC_DIR + dir_file_path, "w")
                fd.write(z.read(name))
                fd.close()
    
                if name.endswith('html'):
                    index = dir_file_path
        finally:
            # Close and remove file
            if fh is not None:
                fh.close()

            log.debug("deleting the zip file")
            os.remove(zip_file_path)

        new_data_url = self.request.application_url + '/public_data/' + index
        new_query = {'data_url': new_data_url}
        url = self.request.route_url('html_api_v1', traverse='/default', _query=new_query)

        return HTTPFound(location=url)
Exemple #4
0
    def visualise_single_file(self, data_url, file_name):
        log = logging.getLogger(__name__)

        log.debug('file_name: %s', file_name)

        new_data_url = None
        new_query = None
        new_filename = None
        return_url = None

        MyDataMover = FDataMover.get_data_mover_class()

        zip_file_path = MyDataMover.download(data_url=data_url, suffix='.zip')

        try:
            fh = open(zip_file_path, 'rb')
            z = zipfile.ZipFile(fh)
            for name in z.namelist():
                if name == file_name:
                    # epoch timestamp for unique filename
                    time_epoch = int(time.time() * 1000)

                    (dirname, filename) = os.path.split(name)

                    new_dirname = str(time_epoch) + '_' + dirname
                    os.mkdir(MyDataMover.PUBLIC_DIR + '/' + new_dirname)
                    log.debug("directory to extract: %s", new_dirname)

                    extract_file_path = new_dirname + '/' + filename

                    # write the file
                    fd = open(MyDataMover.PUBLIC_DIR + '/' + extract_file_path,
                              "w")
                    fd.write(z.read(name))
                    fd.close()

                    log.debug("finished writing file")

                    # Prepare url and query to return it to auto detect
                    new_data_url = self.request.application_url + '/public_data/' + extract_file_path
                    new_query = {'data_url': new_data_url}
                    log.debug("new_data_url: %s", new_data_url)
                    return_url = self.request.route_url('auto_detect_api_v1',
                                                        traverse='/default',
                                                        _query=new_query)
                    # extract it
        finally:
            # Close and remove file
            if fh is not None:
                fh.close()

            # delete the zip file
            log.debug("deleting the zip file")
            os.remove(zip_file_path)

        if return_url is not None:
            return HTTPFound(location=return_url)
        else:
            return Response('Could not find the specified file in the zip.')
Exemple #5
0
    def visualise_single_file(self, data_url, file_name):
        log = logging.getLogger(__name__)


        log.debug('file_name: %s', file_name)

        new_data_url = None
        new_query = None
        new_filename = None
        return_url = None

        MyDataMover = FDataMover.get_data_mover_class()

        zip_file_path = MyDataMover.download(data_url=data_url, suffix='.zip')

        try:
            fh = open(zip_file_path, 'rb')
            z = zipfile.ZipFile(fh)
            for name in z.namelist():
                if name == file_name:
                    # epoch timestamp for unique filename
                    time_epoch = int(time.time() * 1000)
    
                    (dirname, filename) = os.path.split(name)
    
                    new_dirname =  str(time_epoch) + '_' + dirname
                    os.mkdir(MyDataMover.PUBLIC_DIR + '/' + new_dirname)
                    log.debug("directory to extract: %s", new_dirname)
    
                    extract_file_path = new_dirname + '/' + filename
    
                    # write the file
                    fd = open(MyDataMover.PUBLIC_DIR + '/' + extract_file_path,"w")
                    fd.write(z.read(name))
                    fd.close()
    
                    log.debug("finished writing file")
    
                    # Prepare url and query to return it to auto detect
                    new_data_url = self.request.application_url + '/public_data/' + extract_file_path
                    new_query = {'data_url':new_data_url}
                    log.debug("new_data_url: %s", new_data_url)
                    return_url = self.request.route_url('auto_detect_api_v1', traverse='/default', _query=new_query)
                    # extract it
        finally:
            # Close and remove file
            if fh is not None:
                fh.close()
            
            # delete the zip file
            log.debug("deleting the zip file")
            os.remove(zip_file_path)
            
        if return_url is not None:
            return HTTPFound(location=return_url)
        else:
            return Response('Could not find the specified file in the zip.')
    def view(self):
        log = logging.getLogger(__name__)
        log.debug('Processing view request in ZIP API v1')

        data_url = self.request.GET.getone('data_url')
        file_name = self.request.GET.getone('file_name')
        log.debug('file_name: %s', file_name)

        new_data_url = None
        new_query = None
        new_filename = None

        MyDataMover = FDataMover.get_data_mover_class()
        content = None

        zip_file_path = MyDataMover.download(data_url=data_url, suffix='.zip')
        log.debug('File path: %s', zip_file_path)
        log.debug('public dir: %s', MyDataMover.PUBLIC_DIR)

        fh = open(zip_file_path, 'rb')
        z = zipfile.ZipFile(fh)
        for name in z.namelist():
            if name == file_name:
                # epoch timestamp for unique filename
                time_epoch = int(time.time() * 1000)


                (dirname, filename) = os.path.split(name)

                new_dirname =  str(time_epoch) + '_' + dirname
                os.mkdir(MyDataMover.PUBLIC_DIR + '/' + new_dirname)
                log.debug("directory to extract: %s", new_dirname)

                extract_file_path = new_dirname + '/' + filename

                # write the file
                fd = open(MyDataMover.PUBLIC_DIR + '/' + extract_file_path,"w")
                fd.write(z.read(name))
                fd.close()

                log.debug("finished writing file")

                # Prepare url and query to return it to auto detect                
                new_data_url = self.request.application_url + '/public_data/' + extract_file_path
                new_query = {'data_url':new_data_url}
                url = self.request.route_url('auto_detect_api_v1', traverse='/default', _query=new_query)
                return HTTPFound(location=url)
                # extract it
        fh.close()
        # delete the zip file
        os.remove(zip_file_path)

        return Response('Could not find the specified file in the zip.')
Exemple #7
0
    def view(self):

        log = logging.getLogger(__name__)
        log.debug('Processing view request in R API v1')

        data_url = self.request.GET.getone('data_url')

        MyDataMover = FDataMover.get_data_mover_class()
        content = None
        with MyDataMover.open(data_url=data_url) as f:
            content = f.read()

        return { 'file_content': content.decode('utf-8', 'replace') }
Exemple #8
0
    def view(self):

        log = logging.getLogger(__name__)
        log.debug('Processing view request in R API v1')

        data_url = self.request.GET.getone('data_url')

        MyDataMover = FDataMover.get_data_mover_class()
        content = None
        with MyDataMover.open(data_url=data_url) as f:
            content = f.read()

        return {'file_content': content.decode('utf-8', 'replace')}
Exemple #9
0
    def view(self):

        log = logging.getLogger(__name__)
        log.debug('Processing view request in PNG API v1')

        data_url = self.request.GET.getone('data_url')

        MyDataMover = FDataMover.get_data_mover_class()
        content = None
        with MyDataMover.open(data_url=data_url) as f:
            content = f.read()

        response = Response(content, content_type='image/png')
        return response
Exemple #10
0
    def view(self):

        log = logging.getLogger(__name__)
        log.debug('Processing view request in PNG API v1')

        data_url = self.request.GET.getone('data_url')

        MyDataMover = FDataMover.get_data_mover_class()
        content = None
        with MyDataMover.open(data_url=data_url) as f:
            content = f.read()

        response = Response(content, content_type='image/png')
        return response
    def view(self):

        log = logging.getLogger(__name__)
        log.debug('Processing view request in HTML API v1')

        data_url = self.request.GET.getone('data_url')

        content = None
        MyDataMover = FDataMover.get_data_mover_class()
        with MyDataMover.open(data_url=data_url) as f:
            content = f.read()

        out_str = HTMLAPIv1.replace_urls(content, data_url)

        response = Response(out_str, content_type="text/html")
        return response
    def view(self):

        log = logging.getLogger(__name__)
        log.debug('Processing view request in HTML API v1')

        data_url = self.request.GET.getone('data_url')

        content = None
        MyDataMover = FDataMover.get_data_mover_class()
        with MyDataMover.open(data_url=data_url) as f:
            content = f.read()

        out_str = HTMLAPIv1.replace_urls(content, data_url)

        response = Response(out_str, content_type="text/html")
        return response
Exemple #13
0
    def visualise_html_zip(self, data_url):
        MyDataMover = FDataMover.get_data_mover_class()

        # Download the zip file
        zip_file_path = MyDataMover.download(data_url=data_url, suffix='.zip')

        time_epoch = int(time.time() * 1000)
        dir_path = '/html_zip_' + str(time_epoch)
        os.mkdir(MyDataMover.PUBLIC_DIR + dir_path)

        try:
            fh = open(zip_file_path, 'rb')
            z = zipfile.ZipFile(fh)
            for name in z.namelist():
                dir_file_path = dir_path + '/' + name
                # write the file
                fd = open(MyDataMover.PUBLIC_DIR + dir_file_path, "w")
                fd.write(z.read(name))
                fd.close()

                if name.endswith('html'):
                    index = dir_file_path
        finally:
            # Close and remove file
            if fh is not None:
                fh.close()

            log.debug("deleting the zip file")
            os.remove(zip_file_path)

        new_data_url = self.request.application_url + '/public_data/' + index
        new_query = {'data_url': new_data_url}
        url = self.request.route_url('html_api_v1',
                                     traverse='/default',
                                     _query=new_query)

        return HTTPFound(location=url)
Exemple #14
0
    def visualise_multiple_layers(self, data_url):
        url_list = []

        log = logging.getLogger(__name__)

        MyDataMover = FDataMover.get_data_mover_class()

        # Download the zip file
        zip_file_path = MyDataMover.download(data_url=data_url, suffix='.zip')

        try:
            # Unzip the file
            fh = open(zip_file_path, 'rb')
            z = zipfile.ZipFile(fh)
    
            # Validate the files - make sure they end in .tif
            for name in z.namelist():
                if name.endswith('/'):
                    # ignore folders within zip
                    continue
                if not name.endswith('.tif'):
                    # ignore non tif files
                    continue
                    #return Response('This zip either does not have a flat file directory or have inconsistent file types.')
    
            # Extract
            for name in z.namelist():
                if name.endswith('/') or not name.endswith('.tif'):
                    # ignore folders within zip
                    continue
                time_epoch = int(time.time() * 1000)
    
                (dirname, filename) = os.path.split(name)
    
                new_dirname =  str(time_epoch) + '_' + dirname
    
                extract_file_path = new_dirname + '/' + filename
    
                hash_string = hashlib.sha224(extract_file_path).hexdigest()
                new_filename = hash_string + ".tif"
    
                path = os.path.join(MyDataMover.MAP_FILES_DIR, new_filename)
    
                # write the file
                fd = open(path,"w")
                fd.write(z.read(name))
                fd.close()
    
                url_list.append(extract_file_path)
        finally:
            # Close and remove file
            if fh is not None:
                fh.close()

            log.debug("deleting the zip file")
            os.remove(zip_file_path)

        # Send it off to the raster api
        new_query = {'raster_list_url':url_list}
        url = self.request.route_url('raster_api_v1', traverse='/default', _query=new_query)
        return HTTPFound(location=url)
Exemple #15
0
    def visualise_multiple_layers(self, data_url):
        url_list = []

        log = logging.getLogger(__name__)

        MyDataMover = FDataMover.get_data_mover_class()

        # Download the zip file
        zip_file_path = MyDataMover.download(data_url=data_url, suffix='.zip')

        try:
            # Unzip the file
            fh = open(zip_file_path, 'rb')
            z = zipfile.ZipFile(fh)

            # Validate the files - make sure they end in .tif
            for name in z.namelist():
                if name.endswith('/'):
                    # ignore folders within zip
                    continue
                if not name.endswith('.tif'):
                    # ignore non tif files
                    continue
                    #return Response('This zip either does not have a flat file directory or have inconsistent file types.')

            # Extract
            for name in z.namelist():
                if name.endswith('/') or not name.endswith('.tif'):
                    # ignore folders within zip
                    continue
                time_epoch = int(time.time() * 1000)

                (dirname, filename) = os.path.split(name)

                new_dirname = str(time_epoch) + '_' + dirname

                extract_file_path = new_dirname + '/' + filename

                hash_string = hashlib.sha224(extract_file_path).hexdigest()
                new_filename = hash_string + ".tif"

                path = os.path.join(MyDataMover.MAP_FILES_DIR, new_filename)

                # write the file
                fd = open(path, "w")
                fd.write(z.read(name))
                fd.close()

                url_list.append(extract_file_path)
        finally:
            # Close and remove file
            if fh is not None:
                fh.close()

            log.debug("deleting the zip file")
            os.remove(zip_file_path)

        # Send it off to the raster api
        new_query = {'raster_list_url': url_list}
        url = self.request.route_url('raster_api_v1',
                                     traverse='/default',
                                     _query=new_query)
        return HTTPFound(location=url)