Beispiel #1
0
    def func(self, args, request):
        if ('table' not in args):
            raise MudderyError(ERR.missing_args, 'Missing the table name.')

        table_name = args['table']
        file_type = args.get("type", "csv")

        writer_class = writers.get_writer(file_type)
        if not writer_class:
            raise MudderyError(ERR.download_error,
                               "Unknown file type: %s" % file_type)

        # Get tempfile's name.
        temp_name = tempfile.mktemp()
        exporter.export_file(temp_name, table_name, file_type)
        fp = open(temp_name, "rb")
        try:
            filename = table_name + "." + writer_class.file_ext
            return file_response(fp, filename)
        except Exception as e:
            if fp:
                fp.close()
            logger.log_tracemsg("Download error: %s" % e)
            raise MudderyError(ERR.download_error,
                               "Download file error: %s" % e)
Beispiel #2
0
    def func(self, args, request):
        # get data's zip
        fp = tempfile.TemporaryFile()
        try:
            exporter.export_resources(fp)
            fp.seek(0)

            filename = time.strftime("resources_%Y%m%d_%H%M%S.zip", time.localtime())
            return file_response(fp, filename)
        except Exception, e:
            if fp:
                fp.close()
            logger.log_tracemsg("Download error: %s" % e.message)
            raise MudderyError(ERR.download_error, "Download file error: %s" % e)
Beispiel #3
0
    def func(self, args, request):
        file_type = args.get("type", "csv")

        # get data's zip
        fp = tempfile.TemporaryFile()
        try:
            exporter.export_zip_all(fp, file_type)
            fp.seek(0)

            filename = time.strftime("worlddata_%Y%m%d_%H%M%S.zip",
                                     time.localtime())
            return file_response(fp, filename)
        except Exception as e:
            if fp:
                fp.close()
            logger.log_tracemsg("Download error: %s" % e)
            raise MudderyError(ERR.download_error,
                               "Download file error: %s" % e)
Beispiel #4
0
    def func(self, args, request):
        if ('table' not in args):
            raise MudderyError(ERR.missing_args, 'Missing the table name.')

        table_name = args['table']
        file_type = args.get("type", "csv")

        writer_class = writers.get_writer(file_type)
        if not writer_class:
            raise MudderyError(ERR.download_error, "Unknown file type: %s" % file_type)

        # Get tempfile's name.
        temp_name = tempfile.mktemp()
        exporter.export_file(temp_name, table_name, file_type)
        fp = open(temp_name, "rb")
        try:
            filename = table_name + "." + writer_class.file_ext
            return file_response(fp, filename)
        except Exception, e:
            if fp:
                fp.close()
            logger.log_tracemsg("Download error: %s" % e.message)
            raise MudderyError(ERR.download_error, "Download file error: %s" % e)