示例#1
0
文件: epub.py 项目: cnf/geo2ebook
 def prep_dir(self):
     """docstring for prepDir"""
     # setup all the file directories and default files
     os.mkdir(self.build_path)
     os.mkdir(self.build_path + '/META-INF')
     os.mkdir(self.build_path + '/OEBPS')
     os.mkdir(self.build_path + '/OEBPS/css')
     #os.mkdir(self.tmp_path + '/OEBPS/img')
     shutil.copytree(base_path() + '/resources/images', self.build_path + '/OEBPS/img')
     shutil.copyfile(base_path() + '/resources/templates/uitleg.html', self.build_path + '/OEBPS/uitleg.html')
     
     
     # Style sheet to use (todo allow people to pass in their own)
     myStyle = """@page {margin-top: 0.8em; margin-bottom: 0.8em;}\n.titleimg {text-align:center;}"""
     open(self.build_path + "/OEBPS/css/main.css", "w").write(myStyle)
     open(self.build_path + "/mimetype", "w").write("application/epub+zip")
     
     containerXml= (
     '<?xml version="1.0" ?>\n'
     '<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">\n'
     '<rootfiles>\n'
     '<rootfile full-path="OEBPS/content.opf" media-type="application/oebps-package+xml" />\n'
     '</rootfiles>\n'
     '</container>\n' )
     open(self.build_path + "/META-INF/container.xml","w").write(containerXml)
示例#2
0
文件: epub.py 项目: cnf/geo2ebook
 def _create_page(self, cache):
     """docstring for _create_page"""
     html = Template(filename=base_path() + '/resources/templates/epub.html')
     output = html.render(**cache)
     # print 'Generating ' + os.path.basename(fileName)
     tmp_file = self.pages_path + '/' + cache['name'] + '.html'
     with open(tmp_file, 'w') as f:
         f.write('')
         f.write(output.encode('ascii', 'xmlcharrefreplace'))
     return cache['name']