From e6472738b5253aa328f8b2a4f4f2a23abc8582c2 Mon Sep 17 00:00:00 2001 From: cedricbonhomme Date: Sun, 15 Apr 2012 18:59:50 +0200 Subject: Reorganization of folders. --- epub/__init__.py | 1 - epub/epub.py | 343 ----------------------------------------- epub/ez_epub.py | 36 ----- epub/templates/container.xml | 6 - epub/templates/content.opf | 34 ---- epub/templates/ez-section.html | 17 -- epub/templates/image.html | 16 -- epub/templates/title-page.html | 22 --- epub/templates/toc.html | 32 ---- epub/templates/toc.ncx | 28 ---- 10 files changed, 535 deletions(-) delete mode 100644 epub/__init__.py delete mode 100644 epub/epub.py delete mode 100644 epub/ez_epub.py delete mode 100644 epub/templates/container.xml delete mode 100644 epub/templates/content.opf delete mode 100644 epub/templates/ez-section.html delete mode 100644 epub/templates/image.html delete mode 100644 epub/templates/title-page.html delete mode 100644 epub/templates/toc.html delete mode 100644 epub/templates/toc.ncx (limited to 'epub') diff --git a/epub/__init__.py b/epub/__init__.py deleted file mode 100644 index 8d1c8b69..00000000 --- a/epub/__init__.py +++ /dev/null @@ -1 +0,0 @@ - diff --git a/epub/epub.py b/epub/epub.py deleted file mode 100644 index 2c01b54a..00000000 --- a/epub/epub.py +++ /dev/null @@ -1,343 +0,0 @@ -#! /usr/local/bin/python -#-*- coding: utf-8 -*- - -import itertools -import mimetypes -import os -import shutil -import subprocess -import uuid -import zipfile -from genshi.template import TemplateLoader -from lxml import etree - -class TocMapNode: - def __init__(self): - self.playOrder = 0 - self.title = '' - self.href = '' - self.children = [] - self.depth = 0 - - def assignPlayOrder(self): - nextPlayOrder = [0] - self.__assignPlayOrder(nextPlayOrder) - - def __assignPlayOrder(self, nextPlayOrder): - self.playOrder = nextPlayOrder[0] - nextPlayOrder[0] = self.playOrder + 1 - for child in self.children: - child.__assignPlayOrder(nextPlayOrder) - -class EpubItem: - def __init__(self): - self.id = '' - self.srcPath = '' - self.destPath = '' - self.mimeType = '' - self.html = '' - -class EpubBook: - def __init__(self): - self.loader = TemplateLoader('./epub/templates') - - self.rootDir = '' - self.UUID = uuid.uuid1() - - self.lang = 'en-US' - self.title = '' - self.creators = [] - self.metaInfo = [] - - self.imageItems = {} - self.htmlItems = {} - self.cssItems = {} - - self.coverImage = None - self.titlePage = None - self.tocPage = None - - self.spine = [] - self.guide = {} - self.tocMapRoot = TocMapNode() - self.lastNodeAtDepth = {0 : self.tocMapRoot} - - def setTitle(self, title): - self.title = title - - def setLang(self, lang): - self.lang = lang - - def addCreator(self, name, role = 'aut'): - self.creators.append((name, role)) - - def addMeta(self, metaName, metaValue, **metaAttrs): - self.metaInfo.append((metaName, metaValue, metaAttrs)) - - def getMetaTags(self): - l = [] - for metaName, metaValue, metaAttr in self.metaInfo: - beginTag = ' - -%s -

%s

- -""" % (text, text) - - book = EpubBook() - book.setTitle('Most Wanted Tips for Aspiring Young Pirates') - book.addCreator('Monkey D Luffy') - book.addCreator('Guybrush Threepwood') - book.addMeta('contributor', 'Smalltalk80', role = 'bkp') - book.addMeta('date', '2010', event = 'publication') - - book.addTitlePage() - book.addTocPage() - book.addCover(r'D:\epub\blank.png') - - book.addCss(r'main.css', 'main.css') - - n1 = book.addHtml('', '1.html', getMinimalHtml('Chapter 1')) - n11 = book.addHtml('', '2.html', getMinimalHtml('Section 1.1')) - n111 = book.addHtml('', '3.html', getMinimalHtml('Subsection 1.1.1')) - n12 = book.addHtml('', '4.html', getMinimalHtml('Section 1.2')) - n2 = book.addHtml('', '5.html', getMinimalHtml('Chapter 2')) - - book.addSpineItem(n1) - book.addSpineItem(n11) - book.addSpineItem(n111) - book.addSpineItem(n12) - book.addSpineItem(n2) - - # You can use both forms to add TOC map - #t1 = book.addTocMapNode(n1.destPath, '1') - #t11 = book.addTocMapNode(n11.destPath, '1.1', parent = t1) - #t111 = book.addTocMapNode(n111.destPath, '1.1.1', parent = t11) - #t12 = book.addTocMapNode(n12.destPath, '1.2', parent = t1) - #t2 = book.addTocMapNode(n2.destPath, '2') - - book.addTocMapNode(n1.destPath, '1') - book.addTocMapNode(n11.destPath, '1.1', 2) - book.addTocMapNode(n111.destPath, '1.1.1', 3) - book.addTocMapNode(n12.destPath, '1.2', 2) - book.addTocMapNode(n2.destPath, '2') - - rootDir = r'd:\epub\test' - book.createBook(rootDir) - EpubBook.createArchive(rootDir, rootDir + '.epub') - -if __name__ == '__main__': - test() \ No newline at end of file diff --git a/epub/ez_epub.py b/epub/ez_epub.py deleted file mode 100644 index ecfd4f5a..00000000 --- a/epub/ez_epub.py +++ /dev/null @@ -1,36 +0,0 @@ -#! /usr/local/bin/python -#-*- coding: utf-8 -*- - -import epub -from genshi.template import TemplateLoader - -class Section: - def __init__(self): - self.title = '' - self.paragraphs = [] - self.tocDepth = 1 - -def makeBook(title, authors, sections, outputDir, lang='en-US', cover=None): - book = epub.EpubBook() - book.setLang(lang) - book.setTitle(title) - for author in authors: - book.addCreator(author) - #book.addTitlePage() - #book.addTocPage() - #if cover: - #book.addCover(cover) - - loader = TemplateLoader('./epub/templates') - tmpl = loader.load('ez-section.html') - - for i, section in enumerate(sections): - stream = tmpl.generate(section = section) - html = stream.render('xhtml', doctype='xhtml11', drop_xml_decl=False) - item = book.addHtml('', 's%d.html' % (i + 1), html) - book.addSpineItem(item) - book.addTocMapNode(item.destPath, section.title, section.tocDepth) - - outputFile = outputDir + 'article.epub' - book.createBook(outputDir) - book.createArchive(outputDir, outputFile) \ No newline at end of file diff --git a/epub/templates/container.xml b/epub/templates/container.xml deleted file mode 100644 index eecf7a0d..00000000 --- a/epub/templates/container.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/epub/templates/content.opf b/epub/templates/content.opf deleted file mode 100644 index 67f3f5c6..00000000 --- a/epub/templates/content.opf +++ /dev/null @@ -1,34 +0,0 @@ - - - - urn:uuid:${book.UUID} - ${book.lang} - ${book.title} - - $name - - - ${Markup(beginTag)}$content${Markup(endTag)} - - - - - - - - - - - - - - - - - - - - diff --git a/epub/templates/ez-section.html b/epub/templates/ez-section.html deleted file mode 100644 index 0a715e7f..00000000 --- a/epub/templates/ez-section.html +++ /dev/null @@ -1,17 +0,0 @@ - - - ${section.title} - - - -

${section.title}

- -

$p

-
- - diff --git a/epub/templates/image.html b/epub/templates/image.html deleted file mode 100644 index 9a838c7e..00000000 --- a/epub/templates/image.html +++ /dev/null @@ -1,16 +0,0 @@ - - - ${item.destPath} - - - -
${item.destPath}
- - diff --git a/epub/templates/title-page.html b/epub/templates/title-page.html deleted file mode 100644 index de0f55f0..00000000 --- a/epub/templates/title-page.html +++ /dev/null @@ -1,22 +0,0 @@ - - - ${book.title} - - - -

${book.title}

-

- - $creator - -

- - diff --git a/epub/templates/toc.html b/epub/templates/toc.html deleted file mode 100644 index b14c9da3..00000000 --- a/epub/templates/toc.html +++ /dev/null @@ -1,32 +0,0 @@ - - - ${book.title} - - - - - - - ${tocEntry(child)} - - - - ${tocEntry(child)} - - - diff --git a/epub/templates/toc.ncx b/epub/templates/toc.ncx deleted file mode 100644 index e7dd391a..00000000 --- a/epub/templates/toc.ncx +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - ${book.title} - - - - - ${node.title} - - - ${navPoint(child)} - - - - - ${navPoint(child)} - - - -- cgit