mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Documentation
This commit is contained in:
parent
e124ef7513
commit
82534aeb0a
@ -18,6 +18,7 @@ from calibre.constants import DEBUG
|
|||||||
from calibre.ebooks.chardet import xml_to_unicode
|
from calibre.ebooks.chardet import xml_to_unicode
|
||||||
from calibre.ebooks.metadata import string_to_authors, authors_to_string
|
from calibre.ebooks.metadata import string_to_authors, authors_to_string
|
||||||
|
|
||||||
|
# Utility functions {{{
|
||||||
EMPTY_CARD_CACHE = '''\
|
EMPTY_CARD_CACHE = '''\
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<cache xmlns="http://www.kinoma.com/FskCache/1">
|
<cache xmlns="http://www.kinoma.com/FskCache/1">
|
||||||
@ -54,6 +55,8 @@ def strftime(epoch, zone=time.gmtime):
|
|||||||
def uuid():
|
def uuid():
|
||||||
return str(uuid4()).replace('-', '', 1).upper()
|
return str(uuid4()).replace('-', '', 1).upper()
|
||||||
|
|
||||||
|
# }}}
|
||||||
|
|
||||||
class XMLCache(object):
|
class XMLCache(object):
|
||||||
|
|
||||||
def __init__(self, paths, prefixes):
|
def __init__(self, paths, prefixes):
|
||||||
@ -61,6 +64,8 @@ class XMLCache(object):
|
|||||||
pprint(paths)
|
pprint(paths)
|
||||||
self.paths = paths
|
self.paths = paths
|
||||||
self.prefixes = prefixes
|
self.prefixes = prefixes
|
||||||
|
|
||||||
|
# Parse XML files {{{
|
||||||
parser = etree.XMLParser(recover=True)
|
parser = etree.XMLParser(recover=True)
|
||||||
self.roots = {}
|
self.roots = {}
|
||||||
for source_id, path in paths.items():
|
for source_id, path in paths.items():
|
||||||
@ -79,6 +84,7 @@ class XMLCache(object):
|
|||||||
raw, strip_encoding_pats=True, assume_utf8=True,
|
raw, strip_encoding_pats=True, assume_utf8=True,
|
||||||
verbose=DEBUG)[0],
|
verbose=DEBUG)[0],
|
||||||
parser=parser)
|
parser=parser)
|
||||||
|
# }}}
|
||||||
|
|
||||||
recs = self.roots[0].xpath('//*[local-name()="records"]')
|
recs = self.roots[0].xpath('//*[local-name()="records"]')
|
||||||
if not recs:
|
if not recs:
|
||||||
@ -242,7 +248,8 @@ class XMLCache(object):
|
|||||||
self.roots[0].set('nextID', str(max_id+1))
|
self.roots[0].set('nextID', str(max_id+1))
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
def update_booklist(self, bl, bl_index): # {{{
|
# Update JSON from XML {{{
|
||||||
|
def update_booklist(self, bl, bl_index):
|
||||||
if bl_index not in self.record_roots:
|
if bl_index not in self.record_roots:
|
||||||
return
|
return
|
||||||
root = self.record_roots[bl_index]
|
root = self.record_roots[bl_index]
|
||||||
@ -274,7 +281,7 @@ class XMLCache(object):
|
|||||||
break
|
break
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
# Update XML Cache {{{
|
# Update XML from JSON {{{
|
||||||
def update(self, booklists, collections_attributes):
|
def update(self, booklists, collections_attributes):
|
||||||
playlist_map = self.get_playlist_map()
|
playlist_map = self.get_playlist_map()
|
||||||
|
|
||||||
@ -396,6 +403,7 @@ class XMLCache(object):
|
|||||||
f.write(raw)
|
f.write(raw)
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
# Utility methods {{{
|
||||||
def book_by_lpath(self, lpath, root):
|
def book_by_lpath(self, lpath, root):
|
||||||
matches = root.xpath(u'//*[local-name()="text" and @path="%s"]'%lpath)
|
matches = root.xpath(u'//*[local-name()="text" and @path="%s"]'%lpath)
|
||||||
if matches:
|
if matches:
|
||||||
@ -441,4 +449,5 @@ class XMLCache(object):
|
|||||||
pprint(self.nsmaps)
|
pprint(self.nsmaps)
|
||||||
prints('Found namespaces:')
|
prints('Found namespaces:')
|
||||||
pprint(self.namespaces)
|
pprint(self.namespaces)
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user