Esempio n. 1
0
    def test_01(self):
        """Test_writeFileListTrippleAsTable.test_01(): writeFileListTrippleAsTable() - Single file list"""
        myFileNameS = [
            '0eggs.lis',
            '1chips.lis',
            '2beans.lis',
        ]
        myFileLinkS = [(f, HtmlUtils.retHtmlFileName(f),
                        'Link text {:d}'.format(i))
                       for i, f in enumerate(myFileNameS)]
        myF = io.StringIO()
        with XmlWrite.XhtmlStream(myF) as myS:
            HtmlUtils.writeFileListTrippleAsTable(myS, myFileLinkS, {}, False)
#        print()
#        print(myFileLinkS)
#        print(myF.getvalue())
        self.assertEqual(
            myF.getvalue(), """<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <table>
    <tr>
      <td> <a href="0eggs.lis_d23a40cf926df40ac0a0567acdadd443.html">Link text 0</a></td>
    </tr>
    <tr>
      <td> <a href="1chips.lis_10659a53a7e19d0a410fff859afda9bf.html">Link text 1</a></td>
    </tr>
    <tr>
      <td> <a href="2beans.lis_45bf4fdc3882cef7e749605e515b7624.html">Link text 2</a></td>
    </tr>
  </table>
</html>
""")
Esempio n. 2
0
    def test_02(self):
        """Test_writeFileListTrippleAsTable.test_02(): writeFileListTrippleAsTable() - Single directory list"""
        myFileNameS = [
            'spam/beans.lis',
            'spam/chips.lis',
            'spam/eggs.lis',
        ]
        myFileLinkS = [(f, HtmlUtils.retHtmlFileName(f),
                        'Link text {:d}'.format(i))
                       for i, f in enumerate(myFileNameS)]
        myF = io.StringIO()
        with XmlWrite.XhtmlStream(myF) as myS:
            HtmlUtils.writeFileListTrippleAsTable(myS, myFileLinkS, {}, False)
        # print()
        # print(myF.getvalue())
        self.assertEqual(
            myF.getvalue(), """<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <table>
    <tr>
      <td rowspan="3">spam/</td>
      <td> <a href="beans.lis_bd0fa0db0dba3d5deae8b324f475096e.html">Link text 0</a></td>
    </tr>
    <tr>
      <td> <a href="chips.lis_8b5af66b7399116b669c1b12a95d7d33.html">Link text 1</a></td>
    </tr>
    <tr>
      <td> <a href="eggs.lis_b6b735a7daac22b82ecd20fae6189ea5.html">Link text 2</a></td>
    </tr>
  </table>
</html>
""")
Esempio n. 3
0
    def test_02(self):
        """Test_writeFileListTrippleAsTable.test_02(): writeFileListTrippleAsTable() - Single directory list"""
        myFileNameS = [
            'spam/beans.lis',
            'spam/chips.lis',
            'spam/eggs.lis',
        ]
        myFileLinkS = [(f, HtmlUtils.retHtmlFileName(f),
                        'Link text {:d}'.format(i))
                       for i, f in enumerate(myFileNameS)]
        myF = io.StringIO()
        with XmlWrite.XhtmlStream(myF) as myS:
            HtmlUtils.writeFileListTrippleAsTable(myS, myFileLinkS, {}, False)
        # print()
        # print(myF.getvalue())
        self.assertEqual(
            fix_hrefs(myF.getvalue()),
            fix_hrefs("""<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <table>
    <tr>
      <td rowspan="3">spam/</td>
      <td> <a href="beans.lis_ef9772ccc720deea37e190898b7167de.html">Link text 0</a></td>
    </tr>
    <tr>
      <td> <a href="chips.lis_4beafb06c2c4383049c520ec80713ad4.html">Link text 1</a></td>
    </tr>
    <tr>
      <td> <a href="eggs.lis_68357c85d8f3631e6db02fe6a036040e.html">Link text 2</a></td>
    </tr>
  </table>
</html>
"""))
Esempio n. 4
0
    def test_01(self):
        """TestXhtmlWrite.test_01(): simple example."""
        myF = io.StringIO()
        with XmlWrite.XhtmlStream(myF) as xS:
            with XmlWrite.Element(xS, 'head'):
                with XmlWrite.Element(xS, 'title'):
                    xS.characters('Virtual Library')
            with XmlWrite.Element(xS, 'body'):
                with XmlWrite.Element(xS, 'p'):
                    xS.characters('Moved to ')
                    with XmlWrite.Element(xS, 'a',
                                          {'href': 'http://example.org/'}):
                        xS.characters('example.org')
                    xS.characters('.')
        #print
        #print myF.getvalue()
        self.assertEqual(
            myF.getvalue(), """<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Virtual Library</title>
  </head>
  <body>
    <p>Moved to <a href="http://example.org/">example.org</a>.</p>
  </body>
</html>
""")
Esempio n. 5
0
    def test_01(self):
        """Test_writeFileListTrippleAsTable.test_01(): writeFileListTrippleAsTable() - Single file list"""
        myFileNameS = [
            '0eggs.lis',
            '1chips.lis',
            '2beans.lis',
        ]
        myFileLinkS = [(f, HtmlUtils.retHtmlFileName(f),
                        'Link text {:d}'.format(i))
                       for i, f in enumerate(myFileNameS)]
        myF = io.StringIO()
        with XmlWrite.XhtmlStream(myF) as myS:
            HtmlUtils.writeFileListTrippleAsTable(myS, myFileLinkS, {}, False)
        # print()
        # print(myF.getvalue())
        self.assertEqual(
            fix_hrefs(myF.getvalue()),
            fix_hrefs("""<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <table>
    <tr>
      <td> <a href="0eggs.lis_794a10f9fa60f4b19f27a7e42e209f01.html">Link text 0</a></td>
    </tr>
    <tr>
      <td> <a href="1chips.lis_48b0b051146cd7a23f5aa347318124b7.html">Link text 1</a></td>
    </tr>
    <tr>
      <td> <a href="2beans.lis_302d2e55820514cd6d7f0636303ea6a1.html">Link text 2</a></td>
    </tr>
  </table>
</html>
"""))
Esempio n. 6
0
    def test_02(self):
        """Test_writeFileListTrippleAsTable.test_02(): writeFileListTrippleAsTable() - Single directory list"""
        myFileNameS = [
            'spam/beans.lis',
            'spam/chips.lis',
            'spam/eggs.lis',
        ]
        myFileLinkS = [(f, HtmlUtils.retHtmlFileName(f),
                        'Link text {:d}'.format(i))
                       for i, f in enumerate(myFileNameS)]
        myF = io.StringIO()
        with XmlWrite.XhtmlStream(myF) as myS:
            HtmlUtils.writeFileListTrippleAsTable(myS, myFileLinkS, {}, False)
#        print()
#        print(myF.getvalue())
        self.assertEqual(
            myF.getvalue(), """<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <table>
    <tr>
      <td rowspan="3">spam/</td>
      <td> <a href="beans.lis_e6a41188a589cc6b52882b9cd7d22eb9.html">Link text 0</a></td>
    </tr>
    <tr>
      <td> <a href="chips.lis_f429ae32a9c46981370bb498ad597041.html">Link text 1</a></td>
    </tr>
    <tr>
      <td> <a href="eggs.lis_4bedd293e6272aaf67cd473127969aac.html">Link text 2</a></td>
    </tr>
  </table>
</html>
""")
Esempio n. 7
0
    def test_01(self):
        """Test_writeFileListTrippleAsTable.test_01(): writeFileListTrippleAsTable() - Single file list"""
        myFileNameS = [
            '0eggs.lis',
            '1chips.lis',
            '2beans.lis',
        ]
        myFileLinkS = [(f, HtmlUtils.retHtmlFileName(f),
                        'Link text {:d}'.format(i))
                       for i, f in enumerate(myFileNameS)]
        myF = io.StringIO()
        with XmlWrite.XhtmlStream(myF) as myS:
            HtmlUtils.writeFileListTrippleAsTable(myS, myFileLinkS, {}, False)
        # print()
        # print(myF.getvalue())


#        print(myF.getvalue())
        self.assertEqual(
            myF.getvalue(), """<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <table>
    <tr>
      <td> <a href="0eggs.lis_5fdd58d724c849dd9d217fbe6a35b3e6.html">Link text 0</a></td>
    </tr>
    <tr>
      <td> <a href="1chips.lis_3cdd79989f0c867f42464c2c02fa184f.html">Link text 1</a></td>
    </tr>
    <tr>
      <td> <a href="2beans.lis_999dc8fa0c627e259d489d8694205092.html">Link text 2</a></td>
    </tr>
  </table>
</html>
""")
Esempio n. 8
0
 def writeHTML(self, theFilePath, theDesc):
     """Write the index.html table."""
     lenCmnPref = os.path.commonprefix([t[0] for t in self._plotS]).rfind(
         os.sep) + 1
     # Put the plot summary data into a DictTree
     myTree = DictTree.DictTreeHtmlTable()
     for aPlt in self._plotS:
         key = (aPlt[0][lenCmnPref:], ) + aPlt[1:3]
         myTree.add([str(s) for s in key], aPlt[3])
     # Write CSS
     with open(
             os.path.join(os.path.dirname(theFilePath), self.CSS_FILE_PATH),
             'w') as f:
         f.write(CSS_CONTENT_INDEX)
     # Write the index
     with XmlWrite.XhtmlStream(open(theFilePath, 'w')) as myS:
         with XmlWrite.Element(myS, 'head'):
             with XmlWrite.Element(
                     myS, 'link', {
                         'href': self.CSS_FILE_PATH,
                         'type': "text/css",
                         'rel': "stylesheet",
                     }):
                 pass
             with XmlWrite.Element(myS, 'title'):
                 myS.characters('LIS plots in SVG')
         with XmlWrite.Element(myS, 'h1'):
             myS.characters('PlotLogPasses: {:s}'.format(theDesc))
         with XmlWrite.Element(myS, 'table', {'border': '1'}):
             self._writeHTMLTh(myS)
             self._writeIndexTableRows(myS, myTree, theFilePath)
Esempio n. 9
0
    def writeIndexHTML(self, theOutDir):
        # Write CSS
        with open(os.path.join(theOutDir, self.CSS_FILE_PATH), 'w') as f:
            f.write(CSS_CONTENT_INDEX)
        # Now Generate the HTML
        with XmlWrite.XhtmlStream(open(os.path.join(theOutDir, 'index.html'), 'w')) as myS:
            with XmlWrite.Element(myS, 'head'):
                with XmlWrite.Element(
                        myS,
                        'link',
                        {
                            'href'  : self.CSS_FILE_PATH,
                            'type'  : "text/css",
                            'rel'   : "stylesheet",
                        }
                    ):
                    pass
                with XmlWrite.Element(myS, 'title'):
                    myS.characters('LIS as HTML')
            cmnPrefix = os.path.commonprefix([os.path.normpath(aF.pathIn) for aF in self._fileInfoS])
            lenCmnPrefixFpIn = cmnPrefix.rfind(os.sep)+1
            with XmlWrite.Element(myS, 'body'):
                #
                with XmlWrite.Element(myS, 'table'):
                    with XmlWrite.Element(myS, 'tr', {}):
                        with XmlWrite.Element(myS, 'th'):
                            myS.characters('LIS File')
                        with XmlWrite.Element(myS, 'th'):
                            myS.characters('Size (MB)')
                        with XmlWrite.Element(myS, 'th'):
                            myS.characters('Record Entries')
                        with XmlWrite.Element(myS, 'th'):
                            myS.characters('CPU Time (s)')
                        with XmlWrite.Element(myS, 'th'):
                            myS.characters('Rate (MB/s)')
                    # Body of table
                    for aF in sorted(set(self._fileInfoS)):
                        with XmlWrite.Element(myS, 'tr'):
                            with XmlWrite.Element(myS, 'td'):
                                with XmlWrite.Element(myS, 'a', {'href' : os.path.basename(aF.pathOut)}):
                                    myS.characters(aF.pathIn[lenCmnPrefixFpIn:])
                            self._writeCols(myS, aF)
#                            with XmlWrite.Element(myS, 'td', {'align' : 'right'}):
#                                myS.characters('{:.3f}'.format(aF.lisSize / 1024**2))
#                            with XmlWrite.Element(myS, 'td', {'align' : 'right'}):
#                                myS.characters('{:d}'.format(aF.numLr))
#                            with XmlWrite.Element(myS, 'td', {'align' : 'right'}):
#                                myS.characters('{:.3f}'.format(aF.cpuTime))
#                            if aF.cpuTime != 0:
#                                with XmlWrite.Element(myS, 'td', {'align' : 'right'}):
#                                    myS.characters('{:.3f}'.format(aF.lisSize / (aF.cpuTime * 1024**2)))
#                            else:
#                                with XmlWrite.Element(myS, 'td', {'align' : 'right'}):
#                                    myS.characters('N/A')
                    with XmlWrite.Element(myS, 'tr'):
                        with XmlWrite.Element(myS, 'td'):
                            myS.characters('Totals')
                        self._writeCols(myS, self)
Esempio n. 10
0
    def test_00(self):
        """TestXhtmlWrite.test_00(): construction."""
        myF = io.StringIO()
        with XmlWrite.XhtmlStream(myF):
            pass


#        print()
#        print(myF.getvalue())
        self.assertEqual(
            myF.getvalue(), """<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"/>
""")
Esempio n. 11
0
    def processFile(self, fpIn, fpOut):
        assert(os.path.isfile(fpIn))
        assert(os.path.exists(os.path.dirname(fpOut)))
        try:
            myFile, myIndex = self._retLisFileAndIndex(fpIn)
        except ExceptionTotalDepthLIS as err:
            logging.error('Can not create file and index: {:s}'.format(err))
            return
        clkStart = time.clock()
        # Write the CSS is not already there
        self._writeCss(fpOut)
        numEntries = 0
        # Now Generate the HTML
        with XmlWrite.XhtmlStream(open(fpOut, 'w')) as myS:
            with XmlWrite.Element(myS, 'head'):
                with XmlWrite.Element(
                        myS,
                        'link',
                        {
                            'href'  : self.CSS_FILE_PATH,
                            'type'  : "text/css",
                            'rel'   : "stylesheet",
                        }
                    ):
                    pass
                with XmlWrite.Element(myS, 'title'):
                    myS.characters('LIS analysis of %s' % fpIn)
            with XmlWrite.Element(myS, 'body'):
                with XmlWrite.Element(myS, 'a', {'name' : 'top'}):
                    pass
                self._writeHtmlToc(myFile, myIndex, myS)
                for anIe in myIndex.genAll():
#                    print('anIdx:', anIe)
                    if anIe.lrType in self._despatchLrType:
                        self._despatchLrType[anIe.lrType](anIe, myFile, myS)
                    else:
                        self._HTMLNonSpecific(anIe, myFile, myS)
                    numEntries += 1
                with XmlWrite.Element(myS, 'hr'):
                    pass
                with XmlWrite.Element(myS, 'p', {'class' : 'copyright'}):
                    myS.characters('Produced by LisToHtml version: {:s}, date: {:s}, rights: "{:s}" CPU time: {:.3f} (s)'.format(
                        __version__,
                        __date__,
                        __rights__,
                        time.clock() - clkStart,
                        )
                    )
        # Update the counter
        self._summary.add(fpIn, fpOut, numEntries, time.clock() - clkStart)
Esempio n. 12
0
    def test_all_byte_values(self):
        fout = io.StringIO()
        with XmlWrite.XhtmlStream(fout) as xS:
            with XmlWrite.Element(xS, 'Root', {'version': '12.0'}):
                s = ''.join(chr(v) for v in range(256))
                xS.characters(s)
        result = fout.getvalue()
        self.assertEqual(
            result, r"""<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <Root version="12.0">&#000;&#001;&#002;&#003;&#004;&#005;&#006;&#007;&#008;&#009;&#010;&#011;&#012;&#013;&#014;&#015;&#016;&#017;&#018;&#019;&#020;&#021;&#022;&#023;&#024;&#025;&#026;&#027;&#028;&#029;&#030;&#031; !&quot;#$%&amp;&apos;()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~&#128;&#129;&#130;&#131;&#132;&#133;&#134;&#135;&#136;&#137;&#138;&#139;&#140;&#141;&#142;&#143;&#144;&#145;&#146;&#147;&#148;&#149;&#150;&#151;&#152;&#153;&#154;&#155;&#156;&#157;&#158;&#159;&#160;&#161;&#162;&#163;&#164;&#165;&#166;&#167;&#168;&#169;&#170;&#171;&#172;&#173;&#174;&#175;&#176;&#177;&#178;&#179;&#180;&#181;&#182;&#183;&#184;&#185;&#186;&#187;&#188;&#189;&#190;&#191;&#192;&#193;&#194;&#195;&#196;&#197;&#198;&#199;&#200;&#201;&#202;&#203;&#204;&#205;&#206;&#207;&#208;&#209;&#210;&#211;&#212;&#213;&#214;&#215;&#216;&#217;&#218;&#219;&#220;&#221;&#222;&#223;&#224;&#225;&#226;&#227;&#228;&#229;&#230;&#231;&#232;&#233;&#234;&#235;&#236;&#237;&#238;&#239;&#240;&#241;&#242;&#243;&#244;&#245;&#246;&#247;&#248;&#249;&#250;&#251;&#252;&#253;&#254;&#255;</Root>
</html>
""")
Esempio n. 13
0
    def test_03(self):
        """TestXhtmlWrite.test_03(): writeHtmlFileAnchor()."""
        myF = io.StringIO()
        with XmlWrite.XhtmlStream(myF) as myS:
            HtmlUtils.writeHtmlFileAnchor(myS, 47, theText='Navigation text')
#        print()
#        print(myF.getvalue())
        self.assertEqual(
            myF.getvalue(), """<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <a name="47">Navigation text</a>
</html>
""")
Esempio n. 14
0
def _write_low_level_indexes(path_out: str,
                             index: typing.Dict[str, HTMLResult]) -> None:
    assert os.path.isdir(path_out)
    logging.info(f'_write_low_level_indexes(): to "{path_out}"')
    # Write low level indexes
    for root, dirs, files in os.walk(path_out):
        files_to_link_to = []
        for file in files:
            out_file_path = os.path.join(root, file)
            if out_file_path in index:
                files_to_link_to.append(file)
        if len(files_to_link_to):
            with open(os.path.join(root, INDEX_FILE), 'w') as fout:
                logging.info(
                    f'_write_low_level_indexes(): to "{os.path.join(root, INDEX_FILE)}"'
                )
                with XmlWrite.XhtmlStream(fout) as xhtml_stream:
                    with XmlWrite.Element(xhtml_stream, 'head'):
                        with XmlWrite.Element(
                                xhtml_stream, 'meta', {
                                    'charset': "UTF-8",
                                    'name': "viewport",
                                    'content':
                                    "width=device-width, initial-scale=1",
                                }):
                            pass
                        with XmlWrite.Element(xhtml_stream, 'title'):
                            xhtml_stream.charactersWithBr(
                                f'Index of RP66V1 Scan: {root}')
                        with XmlWrite.Element(xhtml_stream, 'style'):
                            xhtml_stream.literal(CSS_RP66V1_INDEX)
                    with XmlWrite.Element(xhtml_stream, 'body'):
                        with XmlWrite.Element(xhtml_stream, 'h1'):
                            xhtml_stream.charactersWithBr(
                                f'Index of RP66V1 Scan {root}')
                        with XmlWrite.Element(xhtml_stream, 'table',
                                              {'class': 'filetable'}):
                            with XmlWrite.Element(xhtml_stream, 'tr',
                                                  {'class': 'filetable'}):
                                for header in ('Physical File', 'File',
                                               'Frame Array', 'Frames',
                                               'Channels', 'X Start', 'X Stop',
                                               'dX', 'X Units'):
                                    with XmlWrite.Element(
                                            xhtml_stream, 'th',
                                        {'class': 'filetable'}):
                                        xhtml_stream.characters(header)
Esempio n. 15
0
    def test_03(self):
        """Test_writeFileListAsTable.test_03(): writeFileListAsTable() - Multiple directory list"""
        myFileNameS = [
            'spam/eggs.lis',
            'spam/chips.lis',
            'spam/fishfingers/beans.lis',
            'spam/fishfingers/peas.lis',
        ]
        myFileLinkS = [(f, HtmlUtils.retHtmlFileName(f)) for f in myFileNameS]
        myF = io.StringIO()
        with XmlWrite.XhtmlStream(myF) as myS:
            HtmlUtils.writeFileListAsTable(myS, myFileLinkS, {}, False)
        # print()
        # print(myF.getvalue())
        self.assertEqual(
            fix_hrefs(myF.getvalue()),
            fix_hrefs("""<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <table>
    <tr>
      <td rowspan="4">spam/</td>
      <td colspan="2">
        <a href="chips.lis_4beafb06c2c4383049c520ec80713ad4.html">chips.lis</a>
      </td>
    </tr>
    <tr>
      <td colspan="2">
        <a href="eggs.lis_68357c85d8f3631e6db02fe6a036040e.html">eggs.lis</a>
      </td>
    </tr>
    <tr>
      <td rowspan="2">fishfingers/</td>
      <td>
        <a href="beans.lis_07cdde39a527d704f75cb8af7f700d0c.html">beans.lis</a>
      </td>
    </tr>
    <tr>
      <td>
        <a href="peas.lis_1fe674e8faaa8dfc406af9f6b7b62f4e.html">peas.lis</a>
      </td>
    </tr>
  </table>
</html>
"""))
Esempio n. 16
0
    def test_03(self):
        """Test_writeFileListAsTable.test_03(): writeFileListAsTable() - Multiple directory list"""
        myFileNameS = [
            'spam/eggs.lis',
            'spam/chips.lis',
            'spam/fishfingers/beans.lis',
            'spam/fishfingers/peas.lis',
        ]
        myFileLinkS = [(f, HtmlUtils.retHtmlFileName(f)) for f in myFileNameS]
        myF = io.StringIO()
        with XmlWrite.XhtmlStream(myF) as myS:
            HtmlUtils.writeFileListAsTable(myS, myFileLinkS, {}, False)
#        print()
#        print(myF.getvalue())
        self.assertEqual(
            myF.getvalue(), """<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <table>
    <tr>
      <td rowspan="4">spam/</td>
      <td colspan="2">
        <a href="chips.lis_f429ae32a9c46981370bb498ad597041.html">chips.lis</a>
      </td>
    </tr>
    <tr>
      <td colspan="2">
        <a href="eggs.lis_4bedd293e6272aaf67cd473127969aac.html">eggs.lis</a>
      </td>
    </tr>
    <tr>
      <td rowspan="2">fishfingers/</td>
      <td>
        <a href="beans.lis_611b98b30977cffa010f98516f0f1d3f.html">beans.lis</a>
      </td>
    </tr>
    <tr>
      <td>
        <a href="peas.lis_b33b7e7dc77fb7179df194fc00f6db0b.html">peas.lis</a>
      </td>
    </tr>
  </table>
</html>
""")
Esempio n. 17
0
    def test_03(self):
        """Test_writeFileListAsTable.test_03(): writeFileListAsTable() - Multiple directory list"""
        myFileNameS = [
            'spam/eggs.lis',
            'spam/chips.lis',
            'spam/fishfingers/beans.lis',
            'spam/fishfingers/peas.lis',
        ]
        myFileLinkS = [(f, HtmlUtils.retHtmlFileName(f)) for f in myFileNameS]
        myF = io.StringIO()
        with XmlWrite.XhtmlStream(myF) as myS:
            HtmlUtils.writeFileListAsTable(myS, myFileLinkS, {}, False)
        # print()
        # print(myF.getvalue())
        self.assertEqual(
            myF.getvalue(), """<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <table>
    <tr>
      <td rowspan="4">spam/</td>
      <td colspan="2">
        <a href="chips.lis_8b5af66b7399116b669c1b12a95d7d33.html">chips.lis</a>
      </td>
    </tr>
    <tr>
      <td colspan="2">
        <a href="eggs.lis_b6b735a7daac22b82ecd20fae6189ea5.html">eggs.lis</a>
      </td>
    </tr>
    <tr>
      <td rowspan="2">fishfingers/</td>
      <td>
        <a href="beans.lis_cc44d87fd7fc57302bb8f53e90981986.html">beans.lis</a>
      </td>
    </tr>
    <tr>
      <td>
        <a href="peas.lis_2cff29fa003c0ea829c7a7d877cae67c.html">peas.lis</a>
      </td>
    </tr>
  </table>
</html>
""")
Esempio n. 18
0
    def test_02(self):
        """TestXhtmlWrite.test_02(): writeHtmlFileLink() with class."""
        myF = io.StringIO()
        with XmlWrite.XhtmlStream(myF) as myS:
            HtmlUtils.writeHtmlFileLink(myS,
                                        'spam/eggs/chips.lis',
                                        47,
                                        theText='Navigation text',
                                        theClass='CSS_class')
#        print()
#        print(myF.getvalue())
        self.assertEqual(
            """<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <a href="chips.lis_b19f66531f1ae9e3a9a56f5f309adbe9.html#47">
    <span class="CSS_class">Navigation text</span>
  </a>
</html>
""", myF.getvalue())
Esempio n. 19
0
    def test_01(self):
        """TestXhtmlWrite.test_01(): writeHtmlFileLink() simple."""
        myF = io.StringIO()
        with XmlWrite.XhtmlStream(myF) as myS:
            HtmlUtils.writeHtmlFileLink(myS,
                                        'spam/eggs/chips.lis',
                                        47,
                                        theText='Navigation text',
                                        theClass=None)
#        print()
#        print(myF.getvalue())
        self.assertEqual(
            """<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <a href="chips.lis_ca9b0f0a4f166e8fbd1ca3795e8adc76.html#47">Navigation text</a>
</html>
""",
            myF.getvalue(),
        )
Esempio n. 20
0
def html_scan_RP66V1_file_data_content(
        path_in: str, fout: typing.TextIO, label_process: bool,
        frame_slice: Slice.Slice) -> HTMLBodySummary:
    """
    Scans all of every EFLR and IFLR in the file and writes to HTML.
    Similar to TotalDepth.RP66V1.core.Scan.scan_RP66V1_file_data_content
    Returns the text to use as a link.
    """
    with LogicalFile.LogicalIndex(path_in) as logical_index:
        if label_process:
            process.add_message_to_queue(os.path.basename(path_in))
        logger.info(
            f'html_scan_RP66V1_file_data_content(): Creating File.FileRead() from "{os.path.basename(path_in)}"'
        )
        logger.info(
            f'html_scan_RP66V1_file_data_content(): Creating LogicalFile.LogicalIndex()'
            f' from "{os.path.basename(path_in)}"')
        logger.info(f'html_scan_RP66V1_file_data_content(): Writing HTML')
        if label_process:
            process.add_message_to_queue('Writing HTML')
        with XmlWrite.XhtmlStream(fout) as xhtml_stream:
            with XmlWrite.Element(xhtml_stream, 'head'):
                with XmlWrite.Element(
                        xhtml_stream, 'meta', {
                            'charset': "UTF-8",
                            'name': "viewport",
                            'content': "width=device-width, initial-scale=1",
                        }):
                    pass
                with XmlWrite.Element(xhtml_stream, 'title'):
                    xhtml_stream.charactersWithBr(f'RP66V1 Scan of {path_in}')
                with XmlWrite.Element(xhtml_stream, 'style'):
                    xhtml_stream.literal(CSS_RP66V1)
            with XmlWrite.Element(xhtml_stream, 'body'):
                ret = html_write_body(logical_index, frame_slice, xhtml_stream)
    logger.info(
        f'html_scan_RP66V1_file_data_content(): Done "{os.path.basename(path_in)}"'
    )
    return ret
Esempio n. 21
0
    def test_01(self):
        """Test_writeFileListAsTable.test_01(): writeFileListAsTable() - Single file list"""
        myFileNameS = [
            'eggs.lis',
            'chips.lis',
            'beans.lis',
        ]
        myFileLinkS = [(f, HtmlUtils.retHtmlFileName(f)) for f in myFileNameS]
        myF = io.StringIO()
        with XmlWrite.XhtmlStream(myF) as myS:
            HtmlUtils.writeFileListAsTable(myS, myFileLinkS, {}, False)
        # print()
        # print(myF.getvalue())
        self.assertEqual(
            fix_hrefs(myF.getvalue()),
            fix_hrefs("""<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <table>
    <tr>
      <td>
        <a href="beans.lis_506d7b33f7f4f5e91a27014670a2afe0.html">beans.lis</a>
      </td>
    </tr>
    <tr>
      <td>
        <a href="chips.lis_3a5c2c41629c341d4a67dcd26f0876c9.html">chips.lis</a>
      </td>
    </tr>
    <tr>
      <td>
        <a href="eggs.lis_3e73430bc9a88a153b4239114e1e0149.html">eggs.lis</a>
      </td>
    </tr>
  </table>
</html>
"""))
Esempio n. 22
0
def _write_top_level_index(path_out: str,
                           index_map: typing.Dict[str, HTMLResult]) -> None:
    # Create a DictTree from the paths.
    dict_tree = DictTree.DictTreeHtmlTable(None)
    for k in index_map:
        branch = k.split(os.sep)
        dict_tree.add(branch, index_map[k])
    index_file_path = os.path.join(path_out, INDEX_FILE)
    logging.info(f'_write_top_level_index(): to "{index_file_path}"')
    with open(index_file_path, 'w') as fout:
        with XmlWrite.XhtmlStream(fout) as xhtml_stream:
            with XmlWrite.Element(xhtml_stream, 'head'):
                with XmlWrite.Element(
                        xhtml_stream, 'meta', {
                            'charset': "UTF-8",
                            'name': "viewport",
                            'content': "width=device-width, initial-scale=1",
                        }):
                    pass
                with XmlWrite.Element(xhtml_stream, 'title'):
                    xhtml_stream.charactersWithBr(f'RP66V1 Scan of {path_out}')
                with XmlWrite.Element(xhtml_stream, 'style'):
                    xhtml_stream.literal(CSS_RP66V1_INDEX)
            with XmlWrite.Element(xhtml_stream, 'body'):
                with XmlWrite.Element(xhtml_stream, 'h1'):
                    xhtml_stream.charactersWithBr(
                        f'Index of RP66V1 Scan: {path_out}')
                with XmlWrite.Element(xhtml_stream, 'p'):
                    xhtml_stream.characters('Command:')
                with XmlWrite.Element(xhtml_stream, 'p'):
                    with XmlWrite.Element(xhtml_stream, 'pre'):
                        xhtml_stream.characters(' '.join(sys.argv))
                with XmlWrite.Element(xhtml_stream, 'table',
                                      {'class': 'filetable'}):
                    _write_top_level_index_table_body(index_file_path,
                                                      dict_tree, xhtml_stream)
Esempio n. 23
0
    def test_charactersWithBr_00(self):
        """TestXhtmlWrite.test_00(): simple example."""
        myF = io.StringIO()
        with XmlWrite.XhtmlStream(myF) as xS:
            with XmlWrite.Element(xS, 'head'):
                pass
            with XmlWrite.Element(xS, 'body'):
                with XmlWrite.Element(xS, 'p'):
                    xS.charactersWithBr('No break in this line.')
                with XmlWrite.Element(xS, 'p'):
                    xS.charactersWithBr("""Several
breaks in
this line.""")
                with XmlWrite.Element(xS, 'p'):
                    xS.charactersWithBr('\nBreak at beginning.')
                with XmlWrite.Element(xS, 'p'):
                    xS.charactersWithBr('Break at end\n')
                with XmlWrite.Element(xS, 'p'):
                    xS.charactersWithBr(
                        '\nBreak at beginning\nmiddle and end\n')
        #print
        #print myF.getvalue()
        self.assertEqual(
            myF.getvalue(), """<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <head/>
  <body>
    <p>No break in this line.</p>
    <p>Several<br/>breaks in<br/>this line.</p>
    <p><br/>Break at beginning.</p>
    <p>Break at end<br/></p>
    <p><br/>Break at beginning<br/>middle and end<br/></p>
  </body>
</html>
""")
Esempio n. 24
0
    def test_01(self):
        """Test_writeFileListAsTable.test_01(): writeFileListAsTable() - Single file list"""
        myFileNameS = [
            'eggs.lis',
            'chips.lis',
            'beans.lis',
        ]
        myFileLinkS = [(f, HtmlUtils.retHtmlFileName(f)) for f in myFileNameS]
        myF = io.StringIO()
        with XmlWrite.XhtmlStream(myF) as myS:
            HtmlUtils.writeFileListAsTable(myS, myFileLinkS, {}, False)
#        print()
#        print(myF.getvalue())
        self.assertEqual(
            myF.getvalue(), """<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <table>
    <tr>
      <td>
        <a href="beans.lis_c80c1ea43cf3e65a59a2552cb3476ace.html">beans.lis</a>
      </td>
    </tr>
    <tr>
      <td>
        <a href="chips.lis_e47053d61ff16de8204d458465683dba.html">chips.lis</a>
      </td>
    </tr>
    <tr>
      <td>
        <a href="eggs.lis_6ea3da99bedf99f85e5ab62345077268.html">eggs.lis</a>
      </td>
    </tr>
  </table>
</html>
""")
Esempio n. 25
0
    def test_01(self):
        """Test_writeFileListAsTable.test_01(): writeFileListAsTable() - Single file list"""
        myFileNameS = [
            'eggs.lis',
            'chips.lis',
            'beans.lis',
        ]
        myFileLinkS = [(f, HtmlUtils.retHtmlFileName(f)) for f in myFileNameS]
        myF = io.StringIO()
        with XmlWrite.XhtmlStream(myF) as myS:
            HtmlUtils.writeFileListAsTable(myS, myFileLinkS, {}, False)
        # print()
        # print(myF.getvalue())
        self.assertEqual(
            myF.getvalue(), """<?xml version='1.0' encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <table>
    <tr>
      <td>
        <a href="beans.lis_71bb0c26c74b06cd02a4f56f3e17667f.html">beans.lis</a>
      </td>
    </tr>
    <tr>
      <td>
        <a href="chips.lis_a11b6c9b0a5036efc32e9b30a09252fc.html">chips.lis</a>
      </td>
    </tr>
    <tr>
      <td>
        <a href="eggs.lis_97cf6bc2288e920398a47aee155da4a8.html">eggs.lis</a>
      </td>
    </tr>
  </table>
</html>
""")