Example #1
0
    def test(self):
        mngr = manager.manager(
            'localhost',
            'explainshell_tests',
            [os.path.join(os.path.dirname(__file__), 'echo.1.gz')],
            drop=True)
        mngr.run()

        cmd = 'echo -en foobar --version'

        m = matcher.matcher(cmd, mngr.store)
        group = m.match()[1]
        matchprog, matches = group.manpage.name, group.results

        self.assertEquals(matchprog, 'echo')

        #self.assertEquals(matches[0].text, 'display a line of text')
        self.assertEquals(matches[0].match, 'echo')

        self.assertEquals(
            matches[1].text,
            '<b>-e</b>     enable interpretation of backslash escapes')
        self.assertEquals(matches[1].match, '-e')

        self.assertEquals(matches[2].text,
                          '<b>-n</b>     do not output the trailing newline')
        self.assertEquals(matches[2].match, 'n')

        self.assertEquals(matches[3].text, None)
        self.assertEquals(matches[3].match, 'foobar')

        self.assertEquals(
            matches[4].text,
            '<b>--version</b>\n       output version information and exit')
        self.assertEquals(matches[4].match, '--version')
    def test(self):
        mngr = manager.manager('localhost', 'explainshell_tests', [os.path.join(os.path.dirname(__file__), 'echo.1.gz')], drop=True)
        mngr.run()

        cmd = 'echo -en foobar --version'

        m = matcher.matcher(cmd, mngr.store)
        matchprog, matches = m.match()[0]

        self.assertEquals(matchprog, 'echo')

        #self.assertEquals(matches[0].text, 'display a line of text')
        self.assertEquals(matches[0].match, 'echo')

        self.assertEquals(matches[1].text, '<b>-e</b>     enable interpretation of backslash escapes')
        self.assertEquals(matches[1].match, '-e')

        self.assertEquals(matches[2].text, '<b>-n</b>     do not output the trailing newline')
        self.assertEquals(matches[2].match, 'n')

        self.assertEquals(matches[3].text, None)
        self.assertEquals(matches[3].match, 'foobar')

        self.assertEquals(matches[4].text, '<b>--version</b>\n       output version information and exit')
        self.assertEquals(matches[4].match, '--version')
Example #3
0
    def _getmanager(self, names, **kwargs):
        l = []
        for n in names:
            l.append(os.path.join(config.MANPAGEDIR, '1', n))

        m = manager.manager('localhost', 'explainshell_tests', l, **kwargs)
        return m
    def _getmanager(self, names, **kwargs):
        l = []
        for n in names:
            l.append(os.path.join(config.MANPAGEDIR, '1', n))

        m = manager.manager(config.MONGO_URI, 'explainshell_tests', l, **kwargs)
        return m
Example #5
0
    def test_overwrite(self):
        m = self._getmanager(['tar.1.gz'], overwrite=False)
        self.assertEquals(len(list(m.store)), 0)

        a, e = m.run()
        self.assertTrue(a)
        self.assertFalse(e)
        self.assertEquals(m.store.mapping.count(), 1)
        self.assertEquals(len(list(m.store)), 1)

        a, e = m.run()
        self.assertFalse(a)
        self.assertTrue(e)
        self.assertEquals(m.store.mapping.count(), 1)
        self.assertEquals(len(list(m.store)), 1)

        m = manager.manager('localhost',
                            'explainshell_tests',
                            [os.path.join(config.MANPAGEDIR, '1', 'tar.1.gz')],
                            overwrite=True)
        a, e = m.run()
        self.assertTrue(a)
        self.assertFalse(e)
        self.assertEquals(m.store.mapping.count(), 1)
        self.assertEquals(len(list(m.store)), 1)

        m.store.verify()
 def test_samename(self):
     pages = [os.path.join(config.MANPAGEDIR, '1', 'node.1.gz'), os.path.join(config.MANPAGEDIR, '8', 'node.8.gz')]
     m = manager.manager(config.MONGO_URI, 'explainshell_tests', pages)
     a, e = m.run()
     self.assertEquals(len(a), 2)
     self.assertEquals(len(m.store.findmanpage('node')), 2)
     mps = m.store.findmanpage('node.8')
     self.assertEquals(len(mps), 2)
     self.assertEquals(mps[0].section, '8')
Example #7
0
 def test_samename(self):
     pages = [os.path.join(config.MANPAGEDIR, '1', 'node.1.gz'), os.path.join(config.MANPAGEDIR, '8', 'node.8.gz')]
     m = manager.manager(config.MONGO_URI, 'explainshell_tests', pages)
     a, e = m.run()
     self.assertEqual(len(a), 2)
     self.assertEqual(len(m.store.findmanpage('node')), 2)
     mps = m.store.findmanpage('node.8')
     self.assertEqual(len(mps), 2)
     self.assertEqual(mps[0].section, '8')
Example #8
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)
Example #9
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)
Example #10
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)
Example #11
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)
    def test_overwrite(self):
        m = self._getmanager(['tar.1.gz'], overwrite=False)
        self.assertEquals(len(list(m.store)), 0)

        a, e = m.run()
        self.assertTrue(a)
        self.assertFalse(e)
        self.assertEquals(m.store.mapping.count(), 1)
        self.assertEquals(len(list(m.store)), 1)

        a, e = m.run()
        self.assertFalse(a)
        self.assertTrue(e)
        self.assertEquals(m.store.mapping.count(), 1)
        self.assertEquals(len(list(m.store)), 1)

        m = manager.manager(config.MONGO_URI, 'explainshell_tests', [os.path.join(config.MANPAGEDIR, '1', 'tar.1.gz')], overwrite=True)
        a, e = m.run()
        self.assertTrue(a)
        self.assertFalse(e)
        self.assertEquals(m.store.mapping.count(), 1)
        self.assertEquals(len(list(m.store)), 1)

        m.store.verify()