예제 #1
0
    def test_path03(self):
        """<input dir>/index.html should be indexed as single html page
        """
        index_file = os.path.join(self.test_input, 'index.html')
        with open(index_file, 'w', encoding='UTF-8') as fh:
            fh.write("""\
<!DOCTYPE html>
<html
    data-scrapbook-create="20200101000000000"
    data-scrapbook-modify="20200101000000000"
    data-scrapbook-source="http://example.com">
<head>
<meta charset="UTF-8">
<title>MyTitle 中文</title>
</head>
<body>
page content
</body>
</html>
""")

        for info in file2wsb.run(self.test_input, self.test_output):
            pass

        book = Host(self.test_output).books['']
        book.load_meta_files()
        book.load_toc_files()

        ids = list(book.meta.keys())
        id_item = ids[0]
        self.assertDictEqual(
            book.meta, {
                id_item: {
                    'title': 'MyTitle 中文',
                    'type': '',
                    'index': f'{id_item}.html',
                    'create': '20200101000000000',
                    'modify': '20200101000000000',
                    'source': 'http://example.com',
                    'icon': '',
                    'comment': '',
                },
            })
        self.assertDictEqual(book.toc, {
            'root': [
                id_item,
            ],
        })
        self.assertEqual(
            set(
                glob.iglob(os.path.join(self.test_output, '**'),
                           recursive=True)),
            {
                os.path.join(self.test_output, ''),
                os.path.join(self.test_output, f'{id_item}.html'),
            })
예제 #2
0
    def test_toc(self):
        with open(self.test_input_rdf, 'w', encoding='UTF-8') as fh:
            fh.write("""\
<?xml version="1.0"?>
<RDF:RDF xmlns:NS1="http://amb.vis.ne.jp/mozilla/scrapbook-rdf#"
         xmlns:NC="http://home.netscape.com/NC-rdf#"
         xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <RDF:Seq RDF:about="urn:scrapbook:root">
    <RDF:li RDF:resource="urn:scrapbook:item20200101000000"/>
    <RDF:li RDF:resource="urn:scrapbook:item20200101000001"/>
    <RDF:li RDF:resource="urn:scrapbook:item20200101000002"/>
    <RDF:li RDF:resource="urn:scrapbook:item20200101000003"/>
    <RDF:li RDF:resource="urn:scrapbook:item20200101000004"/>
  </RDF:Seq>
  <RDF:Seq RDF:about="urn:scrapbook:item20200101000001">
    <RDF:li RDF:resource="urn:scrapbook:item20200101000005"/>
    <RDF:li RDF:resource="urn:scrapbook:item20200101000006"/>
  </RDF:Seq>
  <RDF:Seq RDF:about="urn:scrapbook:item20200101000002">
    <RDF:li RDF:resource="urn:scrapbook:item20200101000007"/>
    <RDF:li RDF:resource="urn:scrapbook:item20200101000008"/>
  </RDF:Seq>
  <RDF:Seq RDF:about="urn:scrapbook:item20200101000003">
    <RDF:li RDF:resource="urn:scrapbook:item20200101000009"/>
  </RDF:Seq>
</RDF:RDF>
""")

        for info in sb2wsb.run(self.test_input, self.test_output):
            pass

        book = Host(self.test_output).books['']
        book.load_toc_files()

        self.assertEqual(
            book.toc, {
                'root': [
                    '20200101000000',
                    '20200101000001',
                    '20200101000002',
                    '20200101000003',
                    '20200101000004',
                ],
                '20200101000001': [
                    '20200101000005',
                    '20200101000006',
                ],
                '20200101000002': [
                    '20200101000007',
                    '20200101000008',
                ],
                '20200101000003': [
                    '20200101000009',
                ],
            })
예제 #3
0
    def test_path01(self):
        """Test hierarchical folders for */index.html
        """
        index_file = os.path.join(self.test_input, 'folder1#中文', 'folder2',
                                  'folder_data', 'index.html')
        os.makedirs(os.path.dirname(index_file), exist_ok=True)
        with open(index_file, 'w', encoding='UTF-8') as fh:
            fh.write("""\
<!DOCTYPE html>
<html
    data-scrapbook-create="20200101000000000"
    data-scrapbook-modify="20200101000000000"
    data-scrapbook-source="http://example.com">
<head>
<meta charset="UTF-8">
<title>MyTitle 中文</title>
</head>
<body>
page content
</body>
</html>
""")

        for info in file2wsb.run(self.test_input, self.test_output):
            pass

        book = Host(self.test_output).books['']
        book.load_meta_files()
        book.load_toc_files()

        ids = list(book.meta.keys())
        id_folder1 = ids[0]
        id_folder2 = ids[1]
        id_item = ids[2]
        self.assertDictEqual(
            book.meta, {
                id_folder1: {
                    'title': 'folder1#中文',
                    'type': 'folder',
                    'create': id_folder1,
                    'modify': id_folder1,
                },
                id_folder2: {
                    'title': 'folder2',
                    'type': 'folder',
                    'create': id_folder2,
                    'modify': id_folder2,
                },
                id_item: {
                    'title': 'MyTitle 中文',
                    'type': '',
                    'index': f'{id_item}/index.html',
                    'create': '20200101000000000',
                    'modify': '20200101000000000',
                    'source': 'http://example.com',
                    'icon': '',
                    'comment': '',
                },
            })
        self.assertDictEqual(
            book.toc, {
                'root': [
                    id_folder1,
                ],
                id_folder1: [
                    id_folder2,
                ],
                id_folder2: [
                    id_item,
                ],
            })
        self.assertEqual(
            set(
                glob.iglob(os.path.join(self.test_output, '**'),
                           recursive=True)),
            {
                os.path.join(self.test_output, ''),
                os.path.join(self.test_output, id_item),
                os.path.join(self.test_output, id_item, 'index.html'),
            })
예제 #4
0
    def test_supporting_folder02(self):
        """Test for supporting folder *_files
        """
        index_file = os.path.join(self.test_input, 'mypage.html')
        with open(index_file, 'w', encoding='UTF-8') as fh:
            fh.write("""\
<!DOCTYPE html>
<html
    data-scrapbook-create="20200101000000000"
    data-scrapbook-modify="20200101000000000"
    data-scrapbook-source="http://example.com">
<head>
<meta charset="UTF-8">
<title>MyTitle 中文</title>
</head>
<body>
page content
<img src="mypage_files/picture.bmp">
</body>
</html>
""")
        img_file = os.path.join(self.test_input, 'mypage_files', 'picture.bmp')
        os.makedirs(os.path.dirname(img_file), exist_ok=True)
        with open(img_file, 'wb') as fh:
            fh.write(b'dummy')

        for info in file2wsb.run(self.test_input, self.test_output):
            pass

        book = Host(self.test_output).books['']
        book.load_meta_files()
        book.load_toc_files()

        ids = list(book.meta.keys())
        id_item = ids[0]
        self.assertDictEqual(
            book.meta, {
                id_item: {
                    'title': 'MyTitle 中文',
                    'type': '',
                    'index': f'{id_item}/index.html',
                    'create': '20200101000000000',
                    'modify': '20200101000000000',
                    'source': 'http://example.com',
                    'icon': '',
                    'comment': '',
                },
            })
        self.assertDictEqual(book.toc, {
            'root': [
                id_item,
            ],
        })
        self.assertEqual(
            set(
                glob.iglob(os.path.join(self.test_output, '**'),
                           recursive=True)),
            {
                os.path.join(self.test_output, ''),
                os.path.join(self.test_output, id_item),
                os.path.join(self.test_output, id_item, 'index.html'),
                os.path.join(self.test_output, id_item, 'mypage.html'),
                os.path.join(self.test_output, id_item, 'mypage_files'),
                os.path.join(self.test_output, id_item, 'mypage_files',
                             'picture.bmp'),
            })