Exemplo n.º 1
0
def tag(source):
    mngr = manager.manager(config.MONGO_URI, 'explainshell', [], False, False)
    s = mngr.store
    m = s.findmanpage(source)[0]
    assert m

    if 'paragraphs' in request.form:
        paragraphs = json.loads(request.form['paragraphs'])
        mparagraphs = []
        for d in paragraphs:
            idx = d['idx']
            text = d['text']
            section = d['section']
            short = [s.strip() for s in d['short']]
            long = [s.strip() for s in d['long']]
            expectsarg = _convertvalue(d['expectsarg'])
            nestedcommand = _convertvalue(d['nestedcommand'])
            if isinstance(nestedcommand, str):
                nestedcommand = [nestedcommand]
            elif nestedcommand is True:
                logger.error('nestedcommand %r must be a string or list',
                             nestedcommand)
                abort(503)
            argument = d['argument']
            if not argument:
                argument = None
            p = store.paragraph(idx, text, section, d['is_option'])
            if d['is_option'] and (short or int or argument):
                p = store.option(p, short, int, expectsarg, argument,
                                 nestedcommand)
            mparagraphs.append(p)

        if request.form.get('nestedcommand', '').lower() == 'true':
            m.nestedcommand = True
        else:
            m.nestedcommand = False
        m = mngr.edit(m, mparagraphs)
        if m:
            return redirect(url_for('explain', cmd=m.name))
        else:
            abort(503)
    else:
        helpers.convertparagraphs(m)
        for p in m.paragraphs:
            if isinstance(p, store.option):
                if isinstance(p.expectsarg, list):
                    p.expectsarg = ', '.join(p.expectsarg)
                if isinstance(p.nestedcommand, list):
                    p.nestedcommand = ', '.join(p.nestedcommand)

        return render_template('tagger.html', m=m)
Exemplo n.º 2
0
def tag(source):
    mngr = manager.manager(config.MONGO_URI, 'explainshell', [], False, False)
    s = mngr.store
    m = s.findmanpage(source)[0]
    assert m

    if 'paragraphs' in request.form:
        paragraphs = json.loads(request.form['paragraphs'])
        mparagraphs = []
        for d in paragraphs:
            idx = d['idx']
            text = d['text']
            section = d['section']
            short = [s.strip() for s in d['short']]
            long = [s.strip() for s in d['long']]
            expectsarg = _convertvalue(d['expectsarg'])
            nestedcommand = _convertvalue(d['nestedcommand'])
            if isinstance(nestedcommand, str):
                nestedcommand = [nestedcommand]
            elif nestedcommand is True:
                logger.error('nestedcommand %r must be a string or list', nestedcommand)
                abort(503)
            argument = d['argument']
            if not argument:
                argument = None
            p = store.paragraph(idx, text, section, d['is_option'])
            if d['is_option'] and (short or long or argument):
                p = store.option(p, short, long, expectsarg, argument, nestedcommand)
            mparagraphs.append(p)

        if request.form.get('nestedcommand', '').lower() == 'true':
            m.nestedcommand = True
        else:
            m.nestedcommand = False
        m = mngr.edit(m, mparagraphs)
        if m:
            return redirect(url_for('explain', cmd=m.name))
        else:
            abort(503)
    else:
        helpers.convertparagraphs(m)
        for p in m.paragraphs:
            if isinstance(p, store.option):
                if isinstance(p.expectsarg, list):
                    p.expectsarg = ', '.join(p.expectsarg)
                if isinstance(p.nestedcommand, list):
                    p.nestedcommand = ', '.join(p.nestedcommand)

        return render_template('tagger.html', m=m)
Exemplo n.º 3
0
def tag(source):
    mngr = manager.manager(config.MONGO_URI, 'explainshell', [], False, False)
    s = mngr.store
    m = s.findmanpage(source)[0]
    assert m

    if 'paragraphs' in request.form:
        paragraphs = json.loads(request.form['paragraphs'])
        mparagraphs = []
        for d in paragraphs:
            idx = d['idx']
            text = d['text']
            section = d['section']
            short = [s.strip() for s in d['short']]
            long = [s.strip() for s in d['long']]
            if isinstance(d['expectsarg'], list):
                expectsarg = [s.strip() for s in d['expectsarg']]
            elif d['expectsarg'].lower() == 'true':
                expectsarg = True
            elif d['expectsarg']:
                expectsarg = d['expectsarg']
            else:
                expectsarg = False
            argument = d['argument']
            if not argument:
                argument = None
            p = store.paragraph(idx, text, section, d['is_option'])
            if d['is_option'] and (short or long or argument):
                p = store.option(p, short, long, expectsarg, argument)
            mparagraphs.append(p)

        m = mngr.edit(m, mparagraphs)
        if m:
            return redirect(url_for('explain', program=m.name))
        else:
            abort(503)
    else:
        helpers.convertparagraphs(m)
        for p in m.paragraphs:
            if isinstance(p, store.option) and isinstance(p.expectsarg, list):
                p.expectsarg = ', '.join(p.expectsarg)

        return render_template('tagger.html', m=m)
Exemplo n.º 4
0
def tag(source):
    mngr = manager.manager(config.MONGO_URI, 'explainshell', [], False, False)
    s = mngr.store
    m = s.findmanpage(source)[0]
    assert m

    if 'paragraphs' in request.form:
        paragraphs = json.loads(request.form['paragraphs'])
        mparagraphs = []
        for d in paragraphs:
            idx = d['idx']
            text = d['text']
            section = d['section']
            short = [s.strip() for s in d['short']]
            long = [s.strip() for s in d['long']]
            if isinstance(d['expectsarg'], list):
                expectsarg = [s.strip() for s in d['expectsarg']]
            elif d['expectsarg'].lower() == 'true':
                expectsarg = True
            elif d['expectsarg']:
                expectsarg = d['expectsarg']
            else:
                expectsarg = False
            argument = d['argument']
            if not argument:
                argument = None
            p = store.paragraph(idx, text, section, d['is_option'])
            if d['is_option'] and (short or long or argument):
                p = store.option(p, short, long, expectsarg, argument)
            mparagraphs.append(p)

        m = mngr.edit(m, mparagraphs)
        if m:
            return redirect(url_for('explain', program=m.name))
        else:
            abort(503)
    else:
        helpers.convertparagraphs(m)
        for p in m.paragraphs:
            if isinstance(p, store.option) and isinstance(p.expectsarg, list):
                p.expectsarg = ', '.join(p.expectsarg)

        return render_template('tagger.html', m=m)