Esempio n. 1
0
    def createToken(self, parent, info, page):
        design = collections.defaultdict(list)
        category = self.settings.get('category')
        if category == '_empty_':
            return parent

        for requirements in self.extension.requirements(category).values():
            for req in requirements:
                for d in req.design:
                    try:
                        node = self.translator.findPage(d)
                        design[node].append(req)
                    except exceptions.MooseDocsException:
                        msg = "Failed to locate the design page '{}'".format(d)
                        LOG.critical(common.report_error(msg,
                                                         req.filename,
                                                         req.design_line,
                                                         ' '.join(req.design),
                                                         traceback.format_exc(),
                                                         'SQA ERROR'))

        for node, requirements in design.items():
            matrix = SQARequirementMatrix(parent)
            heading = SQARequirementMatrixHeading(matrix, category=category)
            autolink.AutoLink(heading, page=str(node.local))
            for req in requirements:
                self._addRequirement(matrix, info, page, req, requirements)

        return parent
Esempio n. 2
0
    def _addRequirement(self, parent, info, page, req):
        reqname = "{}:{}".format(req.path, req.name) if req.path != '.' else req.name
        item = SQARequirementMatrixItem(parent, label=req.label, reqname=reqname)
        self.reader.tokenize(item, req.text, page, MooseDocs.INLINE, info.line, report=False)
        for token in anytree.PreOrderIter(item):
            if token.name == 'ErrorToken':
                msg = common.report_error("Failed to tokenize SQA requirement.",
                                          req.filename,
                                          req.text_line,
                                          req.text,
                                          token['traceback'],
                                          'SQA TOKENIZE ERROR')
                LOG.critical(msg)

        p = core.Paragraph(item)
        tokens.String(p, content='Specification: ')

        content = common.read(req.filename)
        floats.create_modal_link(p,
                                 string=reqname,
                                 content=core.Code(None, language='text', content=content),
                                 title=str(req.filename))

        p = core.Paragraph(item)
        tokens.String(p, content='Documentation: ')
        filename = getattr(req, info['subcommand'])
        autolink.AutoLink(p, page=str(filename))
Esempio n. 3
0
    def tokenize(self, root, content, page, group=None, line=1, report=True):
        """
        Perform the parsing of the supplied content into an AST with the provided root node.

        Inputs:
            root[tokens.Token]: The root node for the AST.
            content[str:tree.page.PageNodeBase]: The content to parse, either as a str
                                                     string or a page node object.
        """
        # Type checking
        if MooseDocs.LOG_LEVEL == logging.DEBUG:
            common.check_type('root', root, tokens.Token)
            common.check_type('content', content, str)

        # Tokenize
        self.__lexer.tokenize(root, content, page, self.__lexer.grammar(group),
                              line)

        # Report errors
        if report:
            for token in moosetree.iterate(root):
                if token.name == 'ErrorToken':
                    msg = common.report_error(
                        token['message'], page.source,
                        token.info.line if token.info else None,
                        token.info[0] if token.info else token.text(),
                        token['traceback'], 'TOKENIZE ERROR')
                    LOG.error(msg)
Esempio n. 4
0
    def createLatexHelper(self, parent, token, page, desired):
        func = lambda p, t, u, l: latex.Command(p, 'hyperref', token=t,
                                                args=[latex.Bracket(string=l)])
        # Create optional content
        bookmark = token['bookmark']

        if desired is None:
            self._createOptionalContent(parent, token, page)
            return None

        url = str(desired.relativeDestination(page))
        head = heading.find_heading(self.translator, desired, bookmark)

        tok = tokens.Token(None)
        if head is None:
            msg = "The linked page ({}) does not contain a heading, so the filename " \
                  "is being utilized.".format(desired.local)
            LOG.warning(common.report_error(msg, page.source,
                                            token.info.line if token.info else None,
                                            token.info[0] if token.info else token.text(),
                                            prefix='WARNING'))
            latex.String(parent, content=page.local)

        else:
            label = head.get('id') or re.sub(r' +', r'-', head.text().lower())
            href = func(parent, token, url, label)

            if len(token) == 0:
                head.copyToToken(tok)
            else:
                token.copyToToken(tok)

            self.renderer.render(href, tok, page)
        return None
Esempio n. 5
0
    def render(self, parent, token, page):
        """
        Convert the AST defined in the token input into a output node of parent.

        Inputs:
            ast[tree.token]: The AST to convert.
            parent[tree.base.NodeBase]: A tree object that the AST shall be converted to.
        """
        try:
            func = self.__getFunction(token)
            el = func(parent, token, page) if func else parent

        except Exception as e:  #pylint: disable=broad-except
            el = None
            if token.info is not None:
                line = token.info.line
                src = token.info[0]
            else:
                line = None
                src = ''
            msg = common.report_error(e, page.source, line, src,
                                      traceback.format_exc(), 'RENDER ERROR')
            with MooseDocs.base.translators.Translator.LOCK:
                LOG.error(msg)

        if el is not None:
            for child in token.children:
                self.render(el, child, page)
Esempio n. 6
0
    def tokenize(self, root, content, page, group=None, line=1):
        """
        Perform the parsing of the supplied content into an AST with the provided root node.

        Inputs:
            root[tokens.Token]: The root node for the AST.
            content[unicode:tree.page.PageNodeBase]: The content to parse, either as a unicode
                                                     string or a page node object.
        """
        # Type checking
        if MooseDocs.LOG_LEVEL == logging.DEBUG:
            common.check_type('root', root, tokens.Token)
            common.check_type('content', content, unicode)

        # Tokenize
        self.__lexer.tokenize(root, content, page, self.__lexer.grammar(group),
                              line)

        # Report errors
        for token in anytree.PreOrderIter(root):
            if token.name == 'ErrorToken':
                msg = common.report_error(token['message'], page, token.info,
                                          token['traceback'],
                                          u'TOKENIZE ERROR')
                with MooseDocs.base.translators.Translator.LOCK:
                    LOG.error(msg)
Esempio n. 7
0
    def tokenize(self, root, content, page, group=None, line=1, report=True):
        """
        Perform the parsing of the supplied content into an AST with the provided root node.

        Inputs:
            root[tokens.Token]: The root node for the AST.
            content[unicode:tree.page.PageNodeBase]: The content to parse, either as a unicode
                                                     string or a page node object.
        """
        # Type checking
        if MooseDocs.LOG_LEVEL == logging.DEBUG:
            common.check_type('root', root, tokens.Token)
            common.check_type('content', content, unicode)

        # Tokenize
        self.__lexer.tokenize(root, content, page, self.__lexer.grammar(group), line)

        # Report errors
        if report:
            for token in anytree.PreOrderIter(root):
                if token.name == 'ErrorToken':
                    msg = common.report_error(token['message'],
                                              page.source,
                                              token.info.line,
                                              token.info[0],
                                              token['traceback'],
                                              u'TOKENIZE ERROR')
                    LOG.error(msg)
Esempio n. 8
0
    def createLatexHelper(self, parent, token, page, desired):
        func = lambda p, t, u, l: latex.Command(p, 'hyperref', token=t,
                                                args=[latex.Bracket(string=l)])
        # Create optional content
        bookmark = token['bookmark']
        if desired is None:
            self._createOptionalContent(parent, token, page)
            return None

        url = unicode(desired.relativeDestination(page))
        head = heading.find_heading(self.translator, desired, bookmark)#

        if head is None:
            msg = "The linked page ({}) does not contain a heading, so the filename " \
                  "is being utilized.".format(desired.local)
            LOG.warning(common.report_error(msg, page.source, token.info.line, token.info[0],
                                            prefix='WARNING'))

        else:
            label = head.get('id') or re.sub(r' +', r'-', head.text().lower())
            href = func(parent, token, url, label)

            tok = tokens.Token(None)
            if len(token.children) == 0:
                head.copyToToken(tok)
            else:
                token.copyToToken(tok)

            self.renderer.render(href, tok, page)

        return None
Esempio n. 9
0
    def _addRequirement(self, parent, info, page, req):
        item = SQARequirementMatrixItem(parent, requirement=req)
        self.reader.tokenize(item,
                             req.text,
                             page,
                             MooseDocs.INLINE,
                             info.line,
                             report=False)
        for token in anytree.PreOrderIter(item):
            if token.name == 'ErrorToken':
                msg = common.report_error(
                    "Failed to tokenize SQA requirement.", req.filename,
                    req.text_line, req.text, token['traceback'],
                    u'SQA TOKENIZE ERROR')
                LOG.critical(msg)

        p = core.Paragraph(item)
        tokens.String(p, content=u'Specification: ')

        with codecs.open(req.filename, encoding='utf-8') as fid:
            content = fid.read()
            floats.create_modal_link(p,
                                     string=u"{}:{}".format(
                                         req.path, req.name),
                                     content=core.Code(None,
                                                       language=u'text',
                                                       content=content),
                                     title=unicode(req.filename))

        p = core.Paragraph(item)
        tokens.String(p, content=u'Details: ')
        filename = u'{}/{}.md'.format(req.path, req.name)
        autolink.AutoLink(p, page=unicode(filename))
Esempio n. 10
0
    def _addRequirement(self, parent, info, page, req, requirements):
        reqname = "{}:{}".format(req.path, req.name) if req.path != '.' else req.name
        item = SQARequirementMatrixItem(parent, label=req.label, reqname=reqname,
                                        satisfied=req.satisfied)
        text = SQARequirementText(item)

        self.reader.tokenize(text, req.text, page, MooseDocs.INLINE, info.line, report=False)
        for token in anytree.PreOrderIter(item):
            if token.name == 'ErrorToken':
                msg = common.report_error("Failed to tokenize SQA requirement.",
                                          req.filename,
                                          req.text_line,
                                          req.text,
                                          token['traceback'],
                                          'SQA TOKENIZE ERROR')
                LOG.critical(msg)

        if req.details:
            details = SQARequirementDetails(item)
            for detail in req.details:
                ditem = SQARequirementDetailItem(details)
                text = SQARequirementText(ditem)
                self.reader.tokenize(text, detail.text, page, MooseDocs.INLINE, info.line, \
                                     report=False)

        if self.settings['link']:
            if self.settings['link-spec']:
                p = SQARequirementSpecification(item, spec_path=req.path, spec_name=req.name)

                hit_root = mooseutils.hit_load(req.filename)
                h = hit_root.find(req.name)
                content = h.render()

                floats.create_modal_link(p,
                                         title=reqname, string=reqname,
                                         content=core.Code(None, language='text', content=content))

            if self.settings['link-design'] and req.design:
                p = SQARequirementDesign(item, filename=req.filename, design=req.design,
                                         line=req.design_line)

            if self.settings['link-issues'] and req.issues:
                p = SQARequirementIssues(item, filename=req.filename, issues=req.issues,
                                         line=req.issues_line)

            if self.settings.get('link-prerequisites', False) and req.prerequisites:
                labels = []
                for prereq in req.prerequisites:
                    for other in requirements:
                        if (other.name == prereq) and (other.path == req.path):
                            labels.append((other.path, other.name, other.label))
                        for detail in other.details:
                            if (detail.name == prereq) and (detail.path == req.path):
                                labels.append((other.path, other.name, other.label))

                SQARequirementPrequisites(item, specs=labels)
Esempio n. 11
0
 def createToken(self, parent, info, page):
     if info['command'] == 'contents':
         msg = 'The command "!contents" is deprecated, please use "!content list".'
         LOG.warning(
             common.report_error(msg,
                                 page.source,
                                 info.line,
                                 info[0],
                                 prefix='WARNING'))
     ContentToken(parent,
                  location=self.settings['location'],
                  level=self.settings['level'])
     return parent
Esempio n. 12
0
    def _addRequirement(self, parent, info, page, req, requirements):

        item = SQARequirementMatrixItem(parent, requirement=req)
        text = SQARequirementText(item)

        self.reader.tokenize(text,
                             req.text,
                             page,
                             MooseDocs.INLINE,
                             info.line,
                             report=False)
        for token in anytree.PreOrderIter(item):
            if token.name == 'ErrorToken':
                msg = common.report_error(
                    "Failed to tokenize SQA requirement.", req.filename,
                    req.text_line, req.text, token['traceback'],
                    u'SQA TOKENIZE ERROR')
                LOG.critical(msg)

        if self.settings['link']:
            if self.settings['link-spec']:
                p = SQARequirementSpecification(item,
                                                spec_path=req.path,
                                                spec_name=req.name)

                with codecs.open(req.filename, encoding='utf-8') as fid:
                    content = fid.read()
                floats.create_modal_link(p,
                                         title=req.filename,
                                         content=core.Code(None,
                                                           language=u'text',
                                                           content=content),
                                         string=u"{}:{}".format(
                                             req.path, req.name))

            if self.settings['link-design'] and req.design:
                p = SQARequirementDesign(item, design=req.design)

            if self.settings['link-issues'] and req.issues:
                p = SQARequirementIssues(item, issues=req.issues)

            if self.settings['link-prerequisites'] and req.prerequisites:
                labels = []
                for prereq in req.prerequisites:
                    for other in requirements:
                        if (other.name == prereq) and (other.path == req.path):
                            labels.append(
                                (other.path, other.name, other.label))

                SQARequirementPrequisites(item, specs=labels)
Esempio n. 13
0
    def createToken(self, parent, info, page):
        if info['command'] == 'contents':
            msg = 'The command "!contents toc" is deprecated, please use "!content toc".'
            LOG.warning(
                common.report_error(msg,
                                    page.source,
                                    info.line,
                                    info[0],
                                    prefix='WARNING'))

        levels = self.settings['levels']
        if isinstance(levels, (str, unicode)):
            levels = [int(l) for l in levels.split()]

        return TableOfContents(parent,
                               hide=self.settings['hide'].split(),
                               levels=levels,
                               columns=int(self.settings['columns']))
Esempio n. 14
0
    def render(self, parent, token, page):
        """
        Convert the AST defined in the token input into a output node of parent.

        Inputs:
            ast[tree.token]: The AST to convert.
            parent[tree.base.NodeBase]: A tree object that the AST shall be converted to.
        """
        try:
            func = self.__getFunction(token)
            el = func(parent, token, page) if func else parent

        except Exception as e: #pylint: disable=broad-except
            el = None
            msg = common.report_error(e.message, page, token.info, traceback.format_exc(),
                                      u'RENDER ERROR')
            with MooseDocs.base.translators.Translator.LOCK:
                LOG.error(msg)

        if el is not None:
            for child in token.children:
                self.render(el, child, page)
Esempio n. 15
0
    def _addRequirement(self, parent, info, page, req, requirements):
        item = SQARequirementMatrixItem(parent,
                                        label=unicode(req.label),
                                        satisfied=req.satisfied,
                                        id_=req.path)

        self.reader.tokenize(item,
                             req.text,
                             page,
                             MooseDocs.INLINE,
                             info.line,
                             report=False)
        for token in anytree.PreOrderIter(item):
            if token.name == 'ErrorToken':
                msg = common.report_error(
                    "Failed to tokenize SQA requirement.", req.filename,
                    req.text_line, req.text, token['traceback'],
                    u'SQA TOKENIZE ERROR')
                LOG.critical(msg)

        if self.settings['link']:
            if self.settings['link-spec']:
                p = core.Paragraph(item)
                tokens.String(p, content=u'Specification: ')

                with codecs.open(req.filename, encoding='utf-8') as fid:
                    content = fid.read()

                floats.create_modal_link(p,
                                         title=req.filename,
                                         content=core.Code(None,
                                                           language=u'text',
                                                           content=content),
                                         string=u"{}:{}".format(
                                             req.path, req.name))

            if self.settings['link-design'] and req.design:
                p = core.Paragraph(item)
                tokens.String(p, content=u'Design: ')
                for design in req.design:
                    autolink.AutoLink(p, page=unicode(design))

            if self.settings['link-issues'] and req.issues:
                p = core.Paragraph(item)
                tokens.String(p, content=u'Issue(s): ')
                for issue in req.issues:
                    if issue.startswith('#'):
                        url = u"https://github.com/idaholab/moose/issues/{}".format(
                            issue[1:])
                    else:
                        url = u"https://github.com/idaholab/moose/commit/{}".format(
                            issue[1:])
                    core.Link(p, url=url, string=unicode(issue))
                    core.Space(p)

            if self.settings['link-prerequisites'] and req.prerequisites:
                labels = []
                for prereq in req.prerequisites:
                    for other in requirements:
                        if other.name == prereq:
                            labels.append(other.label)

                p = core.Paragraph(item)
                tokens.String(p,
                              content=u'Prerequisites: {}'.format(
                                  ' '.join(labels)))