def test_meta_basic03(self):
        """Default value for missing keys.

        - type: ""
        - create: infer from id
        - modify: infer from create (and then id)
        """
        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:Description RDF:about="urn:scrapbook:item20200102030405" />
</RDF:RDF>
""")

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

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

        self.assertDictEqual(book.meta['20200102030405'], {
            'index': '20200102030405/index.html',
            'type': '',
            'create': util.datetime_to_id(util.id_to_datetime_legacy('20200102030405')),
            'modify': util.datetime_to_id(util.id_to_datetime_legacy('20200102030405')),
            })
    def test_meta_basic02(self):
        """A typical item sample of legacy ScrapBook."""
        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:Description RDF:about="urn:scrapbook:item20200102030405"
                   NS1:id="20200102030405"
                   NS1:type=""
                   NS1:title="dummy title"
                   NS1:chars=""
                   NS1:comment="dummy comment __BR__ 2nd line"
                   NS1:icon="favicon.ico"
                   NS1:source="http://example.com/foo" />
</RDF:RDF>
""")

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

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

        self.assertDictEqual(book.meta['20200102030405'], {
            'index': '20200102030405/index.html',
            'title': 'dummy title',
            'type': '',
            'create': util.datetime_to_id(util.id_to_datetime_legacy('20200102030405')),
            'modify': util.datetime_to_id(util.id_to_datetime_legacy('20200102030405')),
            'source': 'http://example.com/foo',
            'icon': 'favicon.ico',
            'comment': 'dummy comment\n2nd line',
            })
Beispiel #3
0
    def test_meta_basic04(self):
        """Should work correctly for another NS name

        (seen in some scrapbook.rdf files)
        """
        with open(self.test_input_rdf, 'w', encoding='UTF-8') as fh:
            fh.write("""\
<?xml version="1.0"?>
<RDF:RDF xmlns:NS2="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:Description RDF:about="urn:scrapbook:item20200102030405"
                   NS2:id="20200102030405"
                   NS2:type=""
                   NS2:title="title"
                   NS2:comment="comment"
                   NS2:icon="favicon.ico"
                   NS2:source="http://example.com" />
</RDF:RDF>
""")

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

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

        self.assertDictEqual(
            book.meta['20200102030405'], {
                'index':
                '20200102030405/index.html',
                'type':
                '',
                'create':
                util.datetime_to_id(
                    util.id_to_datetime_legacy('20200102030405')),
                'modify':
                util.datetime_to_id(
                    util.id_to_datetime_legacy('20200102030405')),
                'title':
                'title',
                'comment':
                'comment',
                'icon':
                'favicon.ico',
                'source':
                'http://example.com',
            })
Beispiel #4
0
    def test_meta_modify02(self):
        """Don't take mtime of index.html if not newer."""
        index_file = os.path.join(self.test_input, 'data', '20200102030405',
                                  'index.html')
        os.makedirs(os.path.dirname(index_file))
        with open(index_file, 'w', encoding='UTF-8') as fh:
            pass
        t = time.mktime((2020, 1, 1, 0, 0, 0, 0, 0, -1))
        os.utime(index_file, (t, t))

        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:Description RDF:about="urn:scrapbook:item20200102030405"
                   NS1:id="20200102030405"
                   NS1:type=""
                   NS1:create="20200102030406"
                   NS1:modify="20200102030407" />
</RDF:RDF>
""")

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

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

        self.assertEqual(
            book.meta['20200102030405']['modify'],
            util.datetime_to_id(util.id_to_datetime_legacy('20200102030407')))
    def test_init_backup(self):
        book = Book(Host(self.test_root))

        book.init_backup(True)
        self.assertRegex(
            book.backup_dir,
            r'^' + re.escape(os.path.join(self.test_root, WSB_DIR, 'backup', '')) + r'\d{17}$',
            )

        ts = util.datetime_to_id()
        book.init_backup(ts)
        self.assertEqual(
            book.backup_dir,
            os.path.join(self.test_root, WSB_DIR, 'backup', ts),
            )

        book.init_backup(False)
        self.assertIsNone(book.backup_dir)