Exemple #1
0
def process_request( request, header_text, button_text, callback, format_callback=None,
        mode = 'mlgt', form_modifier = None, stdout=False, stderr=False ):

    global task_ids

    # check whether request have taskid as GET parameter
    taskid = request.GET.get('taskid', None)
    if taskid:

        if taskid not in task_ids:
            return error_page(request, 'task with ID %s is not registered in the system!')

        (procid, login, title, current_route_path, format_callback, path_qs) = task_ids[taskid]

        procunit = getproc(procid)

        if procunit.status in ['D', 'U']:

            result = procunit.result
            if not result and procunit.exc:
                raise procunit.exc

            if format_callback:
                output = format_callback(result, request)
                html = output['html']
                jscode = output['jscode']
                refs = format_refs(output.get('refs', ''))
            else:
                html = result['html']
                jscode = result['jscode']
                refs = format_refs(result.get('refs', ''))

            # dummy
            sample_html, sample_code = result['sample_filtering']
            marker_html, marker_code = result['marker_filtering']

            return render_to_response("genaf:templates/tools/report.mako",
                {   'header_text': result['title'],
                    'sample_report': sample_html,
                    'marker_report': marker_html,
                    'html': html if html is not None else '',
                    'code': sample_code + marker_code + jscode if jscode is not None else '',
                    'path_qs': path_qs,
                    'refs': refs,
                }, request = request )

            clearproc(procid)
            del task_ids[taskid]

        else:
            seconds = 5
            ns = procunit.ns

            return render_to_response('genaf:templates/tools/progress.mako',
                {   'msg': ns.cerr,
                    'title': title,
                    'taskid': taskid,
                    'seconds': seconds,
                }, request = request )


    # prepare form and/or process form

    if not request.GET.get('_method', None) in ['_exec', '_yamlexec']:

        queryform, javacode = create_form( request, mode )

        if form_modifier:
            queryform, javacode = form_modifier(queryform, javacode)

        return render_to_response('genaf:templates/tools/index.mako',
            {   'header_text': header_text,
                'queryform': queryform,
                'code': javacode,
                'yamlform': yaml_query_form(request),
            }, request = request)

    # process request
    if request.GET.get('_method', None) == '_exec':
        params = load_params(form2dict( request ))

    elif request.GET.get('_method', None) == '_yamlexec':
        params = load_yaml( request.params.get('yamlquery') )


    if not asbool(request.registry.settings['genaf.concurrent.analysis']):
        # set this to false for debugging in non-concurrent mode

        result = mp_run_callback(request.registry.settings,
                    callback, params, request.user, mode)

        if format_callback:
            output = format_callback(result, request)
            html = output['html']
            jscode = output['jscode']
            refs = format_refs(output.get('refs', ''))
        else:
            html = result['html']
            jscode = result['jscode']
            refs = format_refs(result.get('refs', ''))


        # dummy
        sample_html, sample_code = result['sample_filtering']
        marker_html, marker_code = result['marker_filtering']

        return render_to_response("genaf:templates/tools/report.mako",
            {   'header_text': result['title'],
                'sample_report': sample_html,
                'marker_report': marker_html,
                'html': html if html is not None else '',
                'code': sample_code + marker_code + jscode if jscode is not None else '',
                'path_qs': request.path_qs,
                'refs': refs,
            }, request = request )

    # this is code for concurrent mode

    with glock:
        procid, msg = subproc( request.user.login, None,
                    mp_run_callback, request.registry.settings, callback, params,
                    request.user, mode )
        task_ids[procid] = ( procid, request.user.login, header_text,
                                request.current_route_path(), format_callback, request.path_qs )

    return HTTPFound(location = request.current_route_path(_query = { 'taskid': procid }))

    raise NotImplementedError()
    ## method stops here

    q = Query( params, get_dbhandler() )

    # callback needs to return (header_text, html, jscode) tuple

    response = callback(q, request)

    if type(response) != tuple:
        return response

    (header_text, html, code) = response

    sample_html, sample_code = format_sample_summary( q.get_sample_summary(mode) )
    marker_html, marker_code = format_marker_summary( q )

    return render_to_response("genaf:templates/tools/report.mako",
            {   'header_text': header_text,
                'sample_report': sample_html,
                'marker_report': marker_html,
                'html': html if html is not None else '',
                'code': sample_code + marker_code + code if code is not None else '',
            }, request = request )
Exemple #2
0
def process(request):

    batch_id = request.matchdict.get('id')

    if batch_id in local_procs:
        (procid, login, batch_code) = local_procs[batch_id]

        if login != request.user.login:
            seconds = 0
            msg = div()[ p('Another task started by %s is currently running batch: %s' %
                                ( login, batch_code ))
                    ]
        else:

            procunit = getproc(procid)
            if procunit.status in ['D', 'U']:
                seconds = 0
                if procunit.exc:
                    msg = div()[
                        p('Assay processing failed. Please see the following error:'),
                        p( procunit.exc ),
                    ]

                else:
                    result = procunit.result
                    msg = div()[ p('Assay processing finished.'),
                             p('Statistics: %s' % str(result[0]) ),
                             p()[ a(href=request.route_url('genaf.famgr-view',id=batch_id))[
                                            span(class_='btn btn-success')[ 'Continue' ]
                                        ]
                            ]
                        ]
                    if result[1]:
                        msg.add( div()[ p( *result[1] ) ] )

                del local_procs[batch_id]

            else:
                seconds = 10
                msg = div()[ p('Output: %s' % procunit.ns.cout), p('Processing...') ]

    else:

        batch = get_dbhandler().get_batch_by_id(batch_id)
        batch_code = batch.code

        # check authorization
        if not request.user.in_group( batch.group ):
            error_page('You are not authorized to view this batch!')

        if False:
            # set the above to True for single-process debugging purpose
            process_assays(batch_id, request.user.login, None)

        with glock:

            procid, msg = subproc( request.user.login, None,
                    mp_process_assays, request.registry.settings,
                    batch_id, request.user.login, request.user.id )
            local_procs[batch_id] = (procid, request.user.login, batch_code)

        msg = div()[ p('Starting assay processing task') ]
        seconds = 10

    return render_to_response('genaf:templates/famgr/process.mako',
        {   'msg': msg,
            'batch_code': batch_code,
            'seconds': seconds,
        }, request = request )