def build_config(path):
    "Tries to build the config dictionary for the given path"
    try:
        config = parsing.initial(getabspath(path))
    except:
        logger.exception(
            "Error parsing gbk: %r", getabspath(path, raise_on_missing=False))
        raise

    parsing.detect_format(config)
    for k in VALID_KEYS:
        v = request.args.get(k)
        if v:
            nv = parsing.number(v)
            config[k] = v if nv is None else nv
    parsing.endBase(config)
    parsing.mycoplasma(config)

    # fixup nucleotides list
    if 'nucleotides' in request.args:
        config['nucleotides'] = request.args.getlist('nucleotides')

    for key in MAGIC_PARAMS:
        if key in request.args:
            config[key] = request.args[key]

    return config
def run_frame(path):
    """This is the main processing page.

    Rather this is the frame of the main processing page, a lot of the
    detail is done in javascript on the client.

    In here we kickstart the computation and serve down set of jobids
    for the client to work with.

    """

    if not os.path.exists(getabspath(path, False)):
        flash("Couldn't find genome in: %s" % path)
        return redirect(url_for('start'))

    return render_template(
        'processing.html', **{
            'BASE_URL': app.config['APPLICATION_ROOT'],
            'PATH': path,
            'status_base': url_for('.run_status', path=''),
            'kickstart': url_for('kickstart', path=path),  # args=[path]
            'fetch_base': url_for('raw', path=''),
            'STATIC_BASE': url_for('static', filename=''),
            'base_href': url_for('run_frame', path=path)
        })
def run_status(path):
    "This checks on the status of jobid=path"
    result = {'tid': path}
    status = 200
    try:
        abspath = getabspath(path, raise_on_missing=False)
        # Task IDs == filenames on disk, if the file exists don't even
        # bother to check with the server
        if os.path.exists(abspath):
            result['ready'] = True
        elif gexec.ready(abspath):
            result['ready'] = True
            # Ensure the task finished correctly, this could except
            gexec.result(abspath)
        else:
            result['ready'] = False

    except KeyError:  # TODO: Use a restored NoSuchTak
        result['message'] = 'Unknown task identifier.'
        status = 404
    except Exception as e:
        result['message'] = 'Fatal error.'
        result['exception'] = str(e)
        status = 500
        logger.exception("Error getting job status. %r", path)

    return flask.make_response(json.dumps(result), status)
def blockon(path):
    # Task IDs == filenames on disk
    try:
        abspath = getabspath(path, raise_on_missing=False)
        # Task IDs == filenames on disk, if the file exists don't even
        # bother to check with the server
        if os.path.exists(abspath) or gexec.result(abspath, timeout=None):
            return send_file(abspath)
        else:
            raise NotFound()
    except KeyError:
        raise NotFound()
    except Exception as e:
        logger.exception("Error getting job status. %r", path)
        r = jsonify(message='Fatal error.', exception=str(e))
        r.status_code = 500
        return r