def __init__(self, book, server, bookname=None): if bookname is None: bookname = make_book_name(book, server, '.zip') log("*** Extracting TWiki book %s ***" % bookname) self.bookname = bookname self.book = book self.server = server self.workdir = tempfile.mkdtemp(prefix=bookname, dir=config.TMPDIR) os.chmod(self.workdir, 0755) #probable text direction self.dir = guess_text_dir(self.server, self.book)
def _fetch_metadata(self, force=False): """Get information about a twiki book (as much as is easy and useful). If force is False (default) then it will not be reloaded if it has already been set. """ if self.metadata is not None and not force: log("not reloading metadata") return meta = { config.DC: { "publisher": { "": ["FLOSS Manuals http://flossmanuals.net"] }, 'identifier': { "": ['http://%s/epub/%s/%s' % (self.server, self.book, time.strftime('%Y.%m.%d-%H.%M.%S'))] }, 'creator': { "": ['The Contributors'] }, 'date': { "": [time.strftime('%Y-%m-%d')] }, 'title': { "": [self.book] }, }, config.FM: { 'server': {"": [self.server]}, 'book': {"": [self.book]}, } } lang = guess_lang(self.server, self.book) self.dir = guess_text_dir(self.server, self.book) #log(self.server, self.book, lang, self.dir) if lang is not None: add_metadata(meta, 'language', lang) if self.dir is not None: add_metadata(meta, 'dir', self.dir, ns=config.FM) spine = [] toc = [] section = toc waiting_for_url = [] for t in toc_iterator(self.server, self.book): #log(t) if t.is_title(): meta[config.DC]['title'][''] = [t.title] continue item = t.as_zipitem() if item['url'] is None: waiting_for_url.append(item) elif waiting_for_url: for wt in waiting_for_url: wt['url'] = item['url'] waiting_for_url = [] if t.is_chapter(): spine.append(t.chapter) section.append(item) elif t.is_section(): section = item['children'] toc.append(item) self.metadata = { 'version': 1, 'metadata': meta, 'TOC': toc, 'spine': spine, 'manifest': {}, } self._parse_credits() for c in self.contributors: add_metadata(meta, 'contributor', c)
def _fetch_metadata(self, force=False): """Get information about a twiki book (as much as is easy and useful). If force is False (default) then it will not be reloaded if it has already been set. """ if self.metadata is not None and not force: log("not reloading metadata") return meta = { config.DC: { "publisher": { "": ["FLOSS Manuals http://flossmanuals.net"] }, 'identifier': { "": [ 'http://%s/epub/%s/%s' % (self.server, self.book, time.strftime('%Y.%m.%d-%H.%M.%S')) ] }, 'creator': { "": ['The Contributors'] }, 'date': { "": [time.strftime('%Y-%m-%d')] }, 'title': { "": [self.book] }, }, config.FM: { 'server': { "": [self.server] }, 'book': { "": [self.book] }, } } lang = guess_lang(self.server, self.book) self.dir = guess_text_dir(self.server, self.book) #log(self.server, self.book, lang, self.dir) if lang is not None: add_metadata(meta, 'language', lang) if self.dir is not None: add_metadata(meta, 'dir', self.dir, ns=config.FM) spine = [] toc = [] section = toc waiting_for_url = [] for t in toc_iterator(self.server, self.book): #log(t) if t.is_title(): meta[config.DC]['title'][''] = [t.title] continue item = t.as_zipitem() if item['url'] is None: waiting_for_url.append(item) elif waiting_for_url: for wt in waiting_for_url: wt['url'] = item['url'] waiting_for_url = [] if t.is_chapter(): spine.append(t.chapter) section.append(item) elif t.is_section(): section = item['children'] toc.append(item) self.metadata = { 'version': 1, 'metadata': meta, 'TOC': toc, 'spine': spine, 'manifest': {}, } self._parse_credits() for c in self.contributors: add_metadata(meta, 'contributor', c)