Esempio n. 1
0
def _writeMacroDependenciesTable(theS, theEnv, theAdjList, theItu):
    """Writes all the macro dependencies to a rowspan/colspan HTML
    that references something.
    table with links to the position in the HTML representation of the file
    This uses a particular design pattern that uses a DictTree to sort out the
    rows and columns. In this case the DictTree values are lists of pairs
    (href, nav_text) where nav_text is the line_col of the referencing file."""
    myDt = DictTree.DictTreeHtmlTable('list')
    for branch in theAdjList.branches():
        # I might depend on a macro (that is referenced) but I am not referenced.
        if theEnv.macro(branch[-1]).refCount > 0:
            href = '%s#%s' % (
                _macroHistoryRefName(theItu),
                _retMacroId(theEnv.macro(branch[-1]), 0),
            )
        else:
            href = '%s#%s' % (
                _macroHistoryNorefName(theItu),
                _retMacroId(theEnv.macro(branch[-1]), 0),
            )
        # TODO: theIntOccurence is set 0 here
        myDt.add(branch, (
            href,
            branch[-1],
        ))
    # Now iterate with rowspan/colspan
    if len(myDt) > 0:
        HtmlUtils.writeDictTreeAsTable(theS,
                                       myDt,
                                       tableAttrs={'class': "filetable"},
                                       includeKeyTail=False)
Esempio n. 2
0
 def setUp(self):
     self._dt = DictTree.DictTree()
     self.assertEqual([], list(self._dt.keys()))
     self.assertEqual([], list(self._dt.values()))
     self.assertEqual(0, len(self._dt))
     self.assertNotEqual(True, 'spam' in self._dt)
     self.assertEqual(0, self._dt.depth())
Esempio n. 3
0
 def test_01(self):
     """TestDictTreeCtor: test_01(): constructor fails."""
     try:
         DictTree.DictTree(valIterable='int')
         self.fail('DictTree.ExceptionDictTree not raised.')
     except DictTree.ExceptionDictTree:
         pass
Esempio n. 4
0
    def test_01(self):
        """TestTreeAdd: simple add and convert to a Dict Tree."""
        t = Tree.Tree('A')
        t.addChild('AA')
        t.youngestChild.addChild('AAA')
        t.addChild('AB')
        t.youngestChild.addChild('ABA')
        #         print(t.branches())
        self.assertEquals([['A'], ['A', 'AA'], ['A', 'AA', 'AAA'], ['A', 'AB'],
                           ['A', 'AB', 'ABA']], t.branches())
        dt = DictTree.DictTree('list')
        for branch in t.branches():
            dt.add(branch, None)


#         print(dt.indentedStr())
        self.assertEqual(
            """A
  [None]
  AA
    [None]
    AAA
      [None]
  AB
    [None]
    ABA
      [None]""", dt.indentedStr())
Esempio n. 5
0
 def test_02(self):
     """TestDictTreeCtor: test_02(): constructor OK, change valIterable and fail."""
     myDt = DictTree.DictTree()
     myDt._vI = 'int'
     try:
         myDt.add(list(range(1)), 'one')
         self.fail('DictTree.ExceptionDictTree not raised.')
     except DictTree.ExceptionDictTree as err:
         pass
Esempio n. 6
0
def writeFilePathsAsTable(valueType, theS, theKvS, tableStyle, fnTd):
    """Writes file paths as a table, for example as a directory structure.
    
    *valueType*
        The type of the value; ``None, |'list' | 'set'``
        
    *theKvS*
        A list of pairs ``(file_path, value)``.
    
    *tableStyle*
        The style used for the table.
        
    *fnTd*
        A callback function that is executed for a ``<td>`` element when
        there is a non-None value. This is called with the following arguments:
        
            *theS*
                The HTML stream.
                
            *attrs*
                A map of attrs that include the rowspan/colspan for the <td>
                
            *k*
                The key as a list of path components.
                
            *v*
                The value given by the caller.
    """
    myDict = DictTree.DictTreeHtmlTable(valueType)
    for k, v in theKvS:
        myDict.add(pathSplit(k), v)
    # Propagate table class attribute
    with XmlWrite.Element(theS, 'table', {'class': tableStyle}):
        for anEvent in myDict.genColRowEvents():
            if anEvent == myDict.ROW_OPEN:
                # Write out the '<tr>' element
                theS.startElement('tr', {})
            elif anEvent == myDict.ROW_CLOSE:
                # Write out the '</tr>' element
                theS.endElement('tr')
            else:
                #print 'TRACE: anEvent', anEvent
                k, v, r, c = anEvent
                # Write '<td rowspan="%d" colspan="%d">%s</td>' % (r, c, txt[-1])
                myTdAttrs = {'class': tableStyle}
                if r > 1:
                    myTdAttrs['rowspan'] = "%d" % r
                if c > 1:
                    myTdAttrs['colspan'] = "%d" % c
                if v is not None:
                    fnTd(theS, myTdAttrs, k, v)
                else:
                    with XmlWrite.Element(theS, 'td', myTdAttrs):
                        # Write out part of the file name
                        theS.characters(k[-1])
Esempio n. 7
0
def writeFileListTrippleAsTable(theS, theFileLinkS, tableAttrs, includeKeyTail):
    """Writes a list of file names as an HTML table looking like a directory
    structure. *theFileLinkS* is a list of triples ``(file_name, href, nav_text)``."""
    #print 'TRACE: theFileLinkS', theFileLinkS
    myDict = DictTree.DictTreeHtmlTable('list')
    for f, h, n in theFileLinkS:
        keyList = pathSplit(f)
        myDict.add(keyList, (h, n))
    #print 'TRACE:   myDict.keys():', myDict.keys()
    #print 'TRACE: myDict.values():', myDict.values()
    writeDictTreeAsTable(theS, myDict, tableAttrs, includeKeyTail)
Esempio n. 8
0
def writeFileListAsTable(theS, theFileLinkS, tableAttrs, includeKeyTail):
    """Writes a list of file names as an HTML table looking like a directory
    structure. theFileLinkS is a list of pairs (file_path, href).
    The navigation text in the cell will be the basename of the file_path."""
    #myList = [(f, h, os.path.basename(f)) for f, h in theFileLinkS]
    #writeFileListTrippleAsTable(theS, myList, tableAttrs, includeKeyTail)
    #print 'TRACE: theFileLinkS', theFileLinkS
    myDict = DictTree.DictTreeHtmlTable(None)
    for f, h in theFileLinkS:
        keyList = pathSplit(f)
        myDict.add(keyList, (h, os.path.basename(f)))
    writeDictTreeAsTable(theS, myDict, tableAttrs, includeKeyTail)
Esempio n. 9
0
def _writeMacroDependenciesTable(theS, theEnv, theAdjList, theItu):
    """Writes all the macro dependencies to a rowspan/colspan HTML
    that references something.

    table with links to the position in the HTML representation of the file

    This uses a particular design pattern that uses a DictTree to sort out the
    rows and columns. In this case the DictTree values are lists of pairs
    ``(href, nav_text)`` where ``nav_text`` is the line_col of the referencing file.

    :param theS: HTML stream.
    :type theS: :py:class:`cpip.util.XmlWrite.XhtmlStream`

    :param theEnv: The macro environment.
    :type theEnv: :py:class:`cpip.core.MacroEnv.MacroEnv`

    :param theAdjList: Dependency adjacency list.
    :type theAdjList: :py:class:`cpip.util.Tree.Tree`

    :param theItu: The Initial Translation Unit (ITU).
    :type theItu: ``str``

    :returns: ``NoneType``
    """
    myDt = DictTree.DictTreeHtmlTable('list')
    for branch in theAdjList.branches():
        # I might depend on a macro (that is referenced) but I am not referenced.
        if theEnv.macro(branch[-1]).refCount > 0:
            href = '%s#%s' % (
                _macroHistoryRefName(theItu),
                _retMacroId(theEnv.macro(branch[-1]), 0),
            )
        else:
            href = '%s#%s' % (
                _macroHistoryNorefName(theItu),
                _retMacroId(theEnv.macro(branch[-1]), 0),
            )
        # TODO: theIntOccurence is set 0 here
        myDt.add(branch, (
            href,
            branch[-1],
        ))
    # Now iterate with rowspan/colspan
    if len(myDt) > 0:
        HtmlUtils.writeDictTreeAsTable(theS,
                                       myDt,
                                       tableAttrs={'class': "filetable"},
                                       includeKeyTail=False)
Esempio n. 10
0
 def setUp(self):
     self._dt = DictTree.DictTreeHtmlTable('list')
     self.assertEqual([], list(self._dt.keys()))
     self.assertEqual([], list(self._dt.values()))
     self.assertEqual(0, len(self._dt))
     self.assertNotEqual(True, 'spam' in self._dt)
Esempio n. 11
0
 def test_00(self):
     """TestDictTreeCtor: test_00(): constructor."""
     DictTree.DictTree()
     self.assertTrue(True)
Esempio n. 12
0
def writeFilePathsAsTable(valueType, theS, theKvS, tableStyle, fnTd, fnTrTh=None):
    """Writes file paths as a table, for example as a directory structure.

    :param valueType: The type of the value: ``None, |'list' | 'set'``
    :type valueType: ``NoneType, str``

    :param theS: The HTML stream.
    :type theS: ``cpip.util.XmlWrite.XhtmlStream``

    :param theKvS: A list of pairs ``(file_path, value)``.
    :type theKvS: ``list([tuple([str, tuple([str, str, tuple([<class 'int'>, int, int])])]), tuple([str, tuple([str, str, tuple([int, int, int])])])]), list([tuple([str, tuple([str, str])])])``

    :param tableStyle: The CSS style used for the table.
    :type tableStyle: ``str``

    :param fnTd:
        A callback function that is executed for a ``<td>`` element when
        there is a non-None value. This is called with the following arguments:

            *theS*
                The HTML stream.

            *attrs : dict*
                A map of attrs that include the rowspan/colspan for the <td>

            *k : list*
                The key as a list of path components.

            *v*
                The value given by the caller.
    :type fnTd: ``function``

    :param fnTrTh:
        Optional callback function for the header that will be called with the following
        arguments:

            *theS*
                The HTML stream.

            *pathDepth*
                Maximum depth of the largest path, this can be used for
                ``<th colspan="...">File path</th>``.
    :type fnTrTh: ``NoneType, function``

    :returns: ``NoneType``

    :raises: ``StopIteration``
    """
    myDict = DictTree.DictTreeHtmlTable(valueType)
    for k, v in theKvS:
        myDict.add(pathSplit(k), v)
    # Propagate table class attribute
    with XmlWrite.Element(theS, 'table', {'class' : tableStyle}):
        if fnTrTh is not None:
            # Here we will write the first row <th colspan="...">&nbsp</th>
            # or <th colspan="...">File path</th>
            fnTrTh(theS, myDict.depth())
        for anEvent in myDict.genColRowEvents():
            if anEvent == myDict.ROW_OPEN:
                # Write out the '<tr>' element
                theS.startElement('tr', {})
            elif anEvent == myDict.ROW_CLOSE:
                # Write out the '</tr>' element
                theS.endElement('tr')
            else:
                #print 'TRACE: anEvent', anEvent
                k, v, r, c = anEvent
                # Write '<td rowspan="%d" colspan="%d">%s</td>' % (r, c, txt[-1])
                myTdAttrs = {'class' : tableStyle}
                if r > 1:
                    myTdAttrs['rowspan'] = "%d" % r
                if c > 1:
                    myTdAttrs['colspan'] = "%d" % c
                if v is not None:
                    fnTd(theS, myTdAttrs, k, v)
                else:
                    with XmlWrite.Element(theS, 'td', myTdAttrs):
                        # Write out part of the file name
                        theS.characters(k[-1])