def downloadTestConfig(system_name):
    user = authenticate_user()
    if not user:
        return Response("Not logged in", mimetype='text/json', status=403)
    contents = controller.getTestsForSystemAsPickledObject(user, SystemDAO(name=system_name))
    response =  Response(contents, mimetype='text/other', status=200)
    response.headers._list.append(('Content-Disposition','attachment;filename="' + system_name +'_tests_config.cfg"'))
    response.content_disposition = 'attachment; filename="' + system_name +'_tests_config.cfg"'
    return response
def getSystemEventHistoryAsCSV(system_name):
    user = authenticate_user()
    if not user:
        return Response("Not logged in", mimetype='text/json', status=403)
    events = controller.getAllEventsForSystem(user, SystemDAO(name=system_name))
    message = ""
    for event in events:
        message = message + str(event.id) +  "!" + str(event.eventType) +  "!" + str(event.details) + "!" + str(event.timestamp) + "\n"
    response =  Response(message, mimetype='text/csv', status=200)
    response.headers._list.append(('Content-Disposition','attachment;filename="' + system_name +'_events.csv"'))
    response.content_disposition = 'attachment; filename="' + system_name +'_events.csv"'
    return response\
示例#3
0
def downloadTestConfig(system_name):
    user = authenticate_user()
    if not user:
        return Response("Not logged in", mimetype='text/json', status=403)
    contents = controller.getTestsForSystemAsPickledObject(
        user, SystemDAO(name=system_name))
    response = Response(contents, mimetype='text/other', status=200)
    response.headers._list.append(
        ('Content-Disposition',
         'attachment;filename="' + system_name + '_tests_config.cfg"'))
    response.content_disposition = 'attachment; filename="' + system_name + '_tests_config.cfg"'
    return response
示例#4
0
def getSystemEventHistoryAsCSV(system_name):
    user = authenticate_user()
    if not user:
        return Response("Not logged in", mimetype='text/json', status=403)
    events = controller.getAllEventsForSystem(user,
                                              SystemDAO(name=system_name))
    message = ""
    for event in events:
        message = message + str(event.id) + "!" + str(
            event.eventType) + "!" + str(event.details) + "!" + str(
                event.timestamp) + "\n"
    response = Response(message, mimetype='text/csv', status=200)
    response.headers._list.append(
        ('Content-Disposition',
         'attachment;filename="' + system_name + '_events.csv"'))
    response.content_disposition = 'attachment; filename="' + system_name + '_events.csv"'
    return response\
示例#5
0
def write_csv(entries, filename=None):
    gen = generate_csv(entries)
    res = Response(gen, mimetype='text/csv')
    if filename:
        res.content_disposition = 'attachment; filename=%s' % filename
    return res
示例#6
0
def index():
    global source_root, temp_root
    # if request.method == 'GET':
    #     return json.dumps({'ok':''})

    if request.method == 'POST' or request.method == 'GET':
        print("we got something!")
        # load payload
        try:
            payload = json.loads(request.values['data'])  #request.json['data']
        except Exception as e:
            return json.dumps({'error': e.message, 'request': request.json})

        if 'books' not in payload:
            return json.dumps({'error': 'missing the "books" parameter'})
        if 'lang' not in payload:
            return json.dumps({'error': 'missing the "lang" parameter'})
        if 'resource' not in payload:
            return json.dump({'error': 'missing the "resource" parameter'})

        # read fields
        if 'format' in payload:
            format = payload['format']
        else:
            format = "epub"
        books = payload['books']
        lang = payload['lang']
        resource = payload['resource']
        chapters = []
        if 'chapters' in payload and isinstance(books,
                                                list) and len(books) is 1:
            chapters = payload['chapters']
            if 'start' not in chapters or 'end' not in chapters:
                chapters = []

        filename = "translation." + format
        output_path = temp_root + "/" + filename
        command = "/usr/local/bin/pandoc -f html -t " + format + " -o " + output_path
        input_path = source_root + "/" + lang + "/" + resource + "/"

        # TODO: select the proper source
        if not isinstance(books, list):
            # TODO: add all the books to the command
            pass
        else:
            for b in books:
                print("loading book: " + b)
                if len(chapters) == 2:
                    for i in range(chapters["start"], chapters["end"]):
                        print("loading chapter: " + str(i))
                        # add selected chapters
                        command += " " + input_path + b + "/" + str(
                            i) + ".html"
                else:
                    # add all the chapters
                    command += " " + input_path + b + "/*"

        # docx
        # pandoc -f html -t docx -o translation.docx /Users/joel/git/Door43/book_renderer/source/test/*
        # latex
        # pandoc -f html -t latex -o translation.txt /Users/joel/git/Door43/book_renderer/source/test/*
        #command = "/usr/local/bin/pandoc -f html -t epub -o " + output + " " + path

        # debug the command
        print(command)
        os.system(command)
        if (os.path.isfile(output_path)):
            try:
                with open(output_path, 'r') as content_file:
                    response = Response(
                        content_file.read(),
                        content_type='application/octet-stream')
                    response.content_disposition = 'attachment; filename="export.epub"'
                    response.headers[
                        'Content-Disposition'] = 'attachment; filename="export.epub"'
                    return response
            except Exception as e:
                return json.dumps({'error': e.message})
        else:
            return json.dumps({'ok': 'We are done'})
示例#7
0
def index():
    global source_root, temp_root
    # if request.method == 'GET':
    #     return json.dumps({'ok':''})

    if request.method == 'POST' or request.method == 'GET':
        print("we got something!")
        # load payload
        try:
            payload = json.loads(request.values['data']) #request.json['data']
        except Exception as e:
            return json.dumps({'error': e.message,
                               'request': request.json})

        if 'books' not in payload:
            return json.dumps({'error':'missing the "books" parameter'})
        if 'lang' not in payload:
            return json.dumps({'error':'missing the "lang" parameter'})
        if 'resource' not in payload:
            return json.dump({'error':'missing the "resource" parameter'})

        # read fields
        if 'format' in payload:
            format = payload['format']
        else:
            format = "epub"
        books = payload['books']
        lang = payload['lang']
        resource = payload['resource']
        chapters = []
        if 'chapters' in payload and isinstance(books, list) and len(books) is 1:
            chapters = payload['chapters']
            if 'start' not in chapters or 'end' not in chapters:
                chapters = []

        filename = "translation." + format
        output_path = temp_root + "/" + filename
        command = "/usr/local/bin/pandoc -f html -t " + format + " -o " + output_path
        input_path = source_root + "/" + lang + "/" + resource + "/"

        # TODO: select the proper source
        if not isinstance(books, list):
            # TODO: add all the books to the command
            pass
        else:
            for b in books:
                print("loading book: " + b)
                if len(chapters) == 2:
                    for i in range(chapters["start"], chapters["end"]):
                        print("loading chapter: " + str(i))
                        # add selected chapters
                        command += " " + input_path + b + "/" + str(i) + ".html"
                else:
                    # add all the chapters
                    command += " " + input_path + b + "/*"

        # docx
        # pandoc -f html -t docx -o translation.docx /Users/joel/git/Door43/book_renderer/source/test/*
        # latex
        # pandoc -f html -t latex -o translation.txt /Users/joel/git/Door43/book_renderer/source/test/*
        #command = "/usr/local/bin/pandoc -f html -t epub -o " + output + " " + path

        # debug the command
        print(command)
        os.system(command)
        if(os.path.isfile(output_path)):
            try:
                with open(output_path, 'r') as content_file:
                    response = Response(content_file.read(),  content_type='application/octet-stream')
                    response.content_disposition = 'attachment; filename="export.epub"'
                    response.headers['Content-Disposition'] = 'attachment; filename="export.epub"'
                    return response
            except Exception as e:
                return json.dumps({'error': e.message})
        else:
            return json.dumps({'ok':'We are done'})