Example #1
0
 def test_title(self):  # {{{
     def rt(root):
         return read_title(root, read_prefixes(root), read_refines(root))
     def st(root, title, title_sort=None):
         set_title(root, read_prefixes(root), read_refines(root), title, title_sort)
         return rt(root)
     root = self.get_opf('''<dc:title/><dc:title id='t'>xxx</dc:title>''')
     self.ae(rt(root), 'xxx')
     self.ae(st(root, 'abc', 'cba'), 'abc')
     self.ae(read_title_sort(root, read_prefixes(root), read_refines(root)), 'cba')
     root = self.get_opf('''<dc:title>yyy</dc:title><dc:title id='t'>x  xx
         </dc:title><meta refines='#t' property='title-type'>main</meta><meta name="calibre:title_sort" content="sorted"/>''')
     self.ae(rt(root), 'x xx')
     self.ae(read_title_sort(root, read_prefixes(root), read_refines(root)), 'sorted')
     self.ae(st(root, 'abc'), 'abc')
    def test_title(self):  # {{{
        def rt(root):
            return read_title(root, read_prefixes(root), read_refines(root))

        def st(root, title, title_sort=None):
            set_title(root, read_prefixes(root), read_refines(root), title, title_sort)
            return rt(root)
        root = self.get_opf('''<dc:title/><dc:title id='t'>xxx</dc:title>''')
        self.ae(rt(root), 'xxx')
        self.ae(st(root, 'abc', 'cba'), 'abc')
        self.ae(read_title_sort(root, read_prefixes(root), read_refines(root)), 'cba')
        root = self.get_opf('''<dc:title>yyy</dc:title><dc:title id='t'>x  xx
            </dc:title><meta refines='#t' property='title-type'>main</meta><meta name="calibre:title_sort" content="sorted"/>''')
        self.ae(rt(root), 'x xx')
        self.ae(read_title_sort(root, read_prefixes(root), read_refines(root)), 'sorted')
        self.ae(st(root, 'abc'), 'abc')
    def test_dates(self):  # {{{
        from calibre.utils.date import utcnow

        def rl(root):
            p, r = read_prefixes(root), read_refines(root)
            return read_pubdate(root, p, r), read_timestamp(root, p, r)

        def st(root, pd, ts):
            p, r = read_prefixes(root), read_refines(root)
            set_pubdate(root, p, r, pd)
            set_timestamp(root, p, r, ts)
            return rl(root)

        def ae(root, y1=None, y2=None):
            x1, x2 = rl(root)
            for x, y in ((x1, y1), (x2, y2)):
                if y is None:
                    self.assertIsNone(x)
                else:
                    self.ae(y, getattr(x, 'year', None))
        root = self.get_opf('''<dc:date>1999-3-2</dc:date><meta property="calibre:timestamp" scheme="dcterms:W3CDTF">2001</meta>''')
        ae(root, 1999, 2001)
        n = utcnow()
        q = n.replace(microsecond=0)
        self.ae(st(root, n, n), (n, q))
        root = self.get_opf('''<dc:date>1999-3-2</dc:date><meta name="calibre:timestamp" content="2001-1-1"/>''')
        ae(root, 1999, 2001)
        root = self.get_opf('''<meta property="dcterms:modified">2003</meta>''')
        self.ae(read_last_modified(root, read_prefixes(root), read_refines(root)).year, 2003)
Example #4
0
    def test_dates(self):  # {{{
        from calibre.utils.date import utcnow

        def rl(root):
            p, r = read_prefixes(root), read_refines(root)
            return read_pubdate(root, p, r), read_timestamp(root, p, r)

        def st(root, pd, ts):
            p, r = read_prefixes(root), read_refines(root)
            set_pubdate(root, p, r, pd)
            set_timestamp(root, p, r, ts)
            return rl(root)

        def ae(root, y1=None, y2=None):
            x1, x2 = rl(root)
            for x, y in ((x1, y1), (x2, y2)):
                if y is None:
                    self.assertIsNone(x)
                else:
                    self.ae(y, getattr(x, 'year', None))
        root = self.get_opf('''<dc:date>1999-3-2</dc:date><meta property="calibre:timestamp" scheme="dcterms:W3CDTF">2001</meta>''')
        ae(root, 1999, 2001)
        n = utcnow()
        q = n.replace(microsecond=0)
        self.ae(st(root, n, n), (n, q))
        root = self.get_opf('''<dc:date>1999-3-2</dc:date><meta name="calibre:timestamp" content="2001-1-1"/>''')
        ae(root, 1999, 2001)
        root = self.get_opf('''<meta property="dcterms:modified">2003</meta>''')
        self.ae(read_last_modified(root, read_prefixes(root), read_refines(root)).year, 2003)
Example #5
0
 def test_raster_cover(self):  # {{{
     def rt(root):
         return read_raster_cover(root, read_prefixes(root), read_refines(root))
     root = self.get_opf('<meta name="cover" content="cover"/>', '<item id="cover" media-type="image/jpeg" href="x.jpg"/>')
     self.ae('x.jpg', rt(root))
     root = self.get_opf('<meta name="cover" content="cover"/>',
                         '<item id="cover" media-type="image/jpeg" href="x.jpg"/><item media-type="image/jpeg" href="y.jpg" properties="cover-image"/>')
     self.ae('y.jpg', rt(root))
     ensure_is_only_raster_cover(root, read_prefixes(root), read_refines(root), 'x.jpg')
     self.ae('x.jpg', rt(root))
     self.ae(['x.jpg'], root.xpath('//*[@properties="cover-image"]/@href'))
     self.assertFalse(root.xpath('//*[@name]'))
 def test_raster_cover(self):  # {{{
     def rt(root):
         return read_raster_cover(root, read_prefixes(root), read_refines(root))
     root = self.get_opf('<meta name="cover" content="cover"/>', '<item id="cover" media-type="image/jpeg" href="x.jpg"/>')
     self.ae('x.jpg', rt(root))
     root = self.get_opf('<meta name="cover" content="cover"/>',
                         '<item id="cover" media-type="image/jpeg" href="x.jpg"/><item media-type="image/jpeg" href="y.jpg" properties="cover-image"/>')
     self.ae('y.jpg', rt(root))
     ensure_is_only_raster_cover(root, read_prefixes(root), read_refines(root), 'x.jpg')
     self.ae('x.jpg', rt(root))
     self.ae(['x.jpg'], root.xpath('//*[@properties="cover-image"]/@href'))
     self.assertFalse(root.xpath('//*[@name]'))
Example #7
0
def upgrade_metadata(root):
    data = Data()
    data.prefixes = read_prefixes(root)
    data.refines = read_refines(root)

    upgrade_identifiers(root, data)
    upgrade_title(root, data)
    upgrade_languages(root, data)
    upgrade_authors(root, data)
    upgrade_timestamp(root, data)
    upgrade_date(root, data)
    upgrade_rating(root, data)
    upgrade_series(root, data)
    upgrade_custom(root, data)
    upgrade_meta(root, data)

    remove_invalid_attrs_in_dc_metadata(root, data)
    pretty_print_opf(root)
Example #8
0
def upgrade_metadata(root):
    data = Data()
    data.prefixes = read_prefixes(root)
    data.refines = read_refines(root)

    upgrade_identifiers(root, data)
    upgrade_title(root, data)
    upgrade_languages(root, data)
    upgrade_authors(root, data)
    upgrade_timestamp(root, data)
    upgrade_date(root, data)
    upgrade_rating(root, data)
    upgrade_series(root, data)
    upgrade_custom(root, data)
    upgrade_meta(root, data)
    upgrade_cover(root, data)

    remove_invalid_attrs_in_dc_metadata(root, data)
    set_last_modified(root, data.prefixes, data.refines)
    pretty_print_opf(root)
Example #9
0
 def rt(root):
     return read_comments(root, read_prefixes(root), read_refines(root))
Example #10
0
 def rl(root):
     return read_pubdate(root, read_prefixes(root), read_refines(root)), read_timestamp(root, read_prefixes(root), read_refines(root))
Example #11
0
 def rl(root):
     return read_book_producers(root, read_prefixes(root), read_refines(root))
Example #12
0
 def su(root, val):
     set_user_metadata(root, read_prefixes(root), read_refines(root), val)
     return ru(root)
Example #13
0
 def st(root, val):
     set_tags(root, read_prefixes(root), read_refines(root), val)
     return rt(root)
Example #14
0
 def st(root, val, i):
     set_series(root, read_prefixes(root), read_refines(root), val, i)
     return rt(root)
Example #15
0
 def rl(root):
     return read_book_producers(root, read_prefixes(root),
                                read_refines(root))
Example #16
0
 def st(root, producers):
     set_book_producers(root, read_prefixes(root), read_refines(root),
                        producers)
     return rl(root)
Example #17
0
 def rl(root):
     return read_authors(root, read_prefixes(root), read_refines(root))
Example #18
0
 def st(root, authors):
     set_authors(root, read_prefixes(root), read_refines(root), authors)
     return rl(root)
Example #19
0
 def st(root, languages):
     set_languages(root, read_prefixes(root), read_refines(root),
                   languages)
     return rl(root)
Example #20
0
 def rl(root):
     return read_languages(root, read_prefixes(root),
                           read_refines(root))
Example #21
0
 def st(root, title, title_sort=None):
     set_title(root, read_prefixes(root), read_refines(root), title,
               title_sort)
     return rt(root)
Example #22
0
 def rt(root):
     return read_publisher(root, read_prefixes(root), read_refines(root))
Example #23
0
 def rl(root):
     return read_pubdate(root, read_prefixes(root),
                         read_refines(root)), read_timestamp(
                             root, read_prefixes(root),
                             read_refines(root))
Example #24
0
 def rl(root):
     p, r = read_prefixes(root), read_refines(root)
     return read_pubdate(root, p, r), read_timestamp(root, p, r)
Example #25
0
 def ru(root):
     return read_user_metadata(root, read_prefixes(root),
                               read_refines(root))
Example #26
0
 def st(root, val):
     set_rating(root, read_prefixes(root), read_refines(root), val)
     return rt(root)
Example #27
0
 def rl(root):
     return read_languages(root, read_prefixes(root), read_refines(root))
Example #28
0
 def st(root, name, val):
     f = globals()['set_' + name]
     f(root, read_prefixes(root), read_refines(root), val)
     return rt(root, name)
Example #29
0
 def rl(root):
     return read_authors(root, read_prefixes(root), read_refines(root))
Example #30
0
 def st(root, pd, ts):
     set_pubdate(root, read_prefixes(root), read_refines(root), pd)
     set_timestamp(root, read_prefixes(root), read_refines(root), ts)
     return rl(root)
Example #31
0
 def rl(root):
     p, r = read_prefixes(root), read_refines(root)
     return read_pubdate(root, p, r), read_timestamp(root, p, r)
Example #32
0
 def su(root, val):
     set_user_metadata(root, read_prefixes(root), read_refines(root),
                       val)
     return ru(root)
Example #33
0
 def rt(root):
     return read_comments(root, read_prefixes(root), read_refines(root))
Example #34
0
 def st(root, languages):
     set_languages(root, read_prefixes(root), read_refines(root), languages)
     return rl(root)
Example #35
0
 def st(root, val):
     set_comments(root, read_prefixes(root), read_refines(root), val)
     return rt(root)
Example #36
0
 def st(root, authors):
     set_authors(root, read_prefixes(root), read_refines(root), authors)
     return rl(root)
Example #37
0
 def rt(root):
     return read_publisher(root, read_prefixes(root),
                           read_refines(root))
Example #38
0
 def st(root, producers):
     set_book_producers(root, read_prefixes(root), read_refines(root), producers)
     return rl(root)
Example #39
0
 def st(root, val):
     set_publisher(root, read_prefixes(root), read_refines(root), val)
     return rt(root)
Example #40
0
 def st(root, pd, ts):
     set_pubdate(root, read_prefixes(root), read_refines(root), pd)
     set_timestamp(root, read_prefixes(root), read_refines(root), ts)
     return rl(root)
Example #41
0
 def rt(root):
     return read_raster_cover(root, read_prefixes(root),
                              read_refines(root))
Example #42
0
 def st(root, val):
     set_comments(root, read_prefixes(root), read_refines(root), val)
     return rt(root)
Example #43
0
 def rt(root):
     return read_tags(root, read_prefixes(root), read_refines(root))
Example #44
0
 def st(root, val):
     set_publisher(root, read_prefixes(root), read_refines(root), val)
     return rt(root)
Example #45
0
 def st(root, val):
     set_tags(root, read_prefixes(root), read_refines(root), val)
     return rt(root)
Example #46
0
 def rt(root):
     return read_raster_cover(root, read_prefixes(root), read_refines(root))
Example #47
0
 def rt(root):
     return read_rating(root, read_prefixes(root), read_refines(root))
Example #48
0
 def rt(root):
     return read_rating(root, read_prefixes(root), read_refines(root))
Example #49
0
 def st(root, val):
     set_rating(root, read_prefixes(root), read_refines(root), val)
     return rt(root)
Example #50
0
 def rt(root):
     return read_series(root, read_prefixes(root), read_refines(root))
Example #51
0
 def rt(root):
     return read_series(root, read_prefixes(root), read_refines(root))
Example #52
0
 def rt(root, name):
     f = globals()['read_' + name]
     return f(root, read_prefixes(root), read_refines(root))
Example #53
0
 def rt(root):
     return read_title(root, read_prefixes(root), read_refines(root))
Example #54
0
 def ru(root):
     return read_user_metadata(root, read_prefixes(root), read_refines(root))
Example #55
0
 def st(root, name, val):
     f = globals()['set_' + name]
     f(root, read_prefixes(root), read_refines(root), val)
     return rt(root, name)
Example #56
0
 def st(root, val, i):
     set_series(root, read_prefixes(root), read_refines(root), val, i)
     return rt(root)
Example #57
0
 def rt(root):
     return read_title(root, reserved_prefixes, read_refines(root))
Example #58
0
 def st(root, title, title_sort=None):
     set_title(root, read_prefixes(root), read_refines(root), title, title_sort)
     return rt(root)
Example #59
0
 def rt(root, name):
     f = globals()['read_' + name]
     return f(root, read_prefixes(root), read_refines(root))