Esempio n. 1
0
    def gen_content_opf(self):
        '''
        generate the content opf files
        '''
        file_list = []
        for root, dires, files in walk(self.ops_dir):
            for fname in files:
                fpath = relpath(pjoin(root, fname),
                                self.ops_dir).replace('\\', '/')
                f_id = self.file_id(fname)
                t_name, file_extension = splitext(fname)
                f_media_type = self.media_type_of(file_extension)
                file_list.append(
                    opf_manifest_item_tpl.format(fpath, f_id, f_media_type))

        spine_toc = []
        if self.toc_entries and len(self.toc_entries) > 0:
            for toc in self.toc_entries:
                idhref = toc.split('#')[0]
                spine_toc.append(opf_spine_toc_item_tpl.format(idhref))

        opf_content = opf_format_tpl.format(self.uuid_urn, self.date, 'tony',
                                            ''.join(file_list),
                                            ''.join(spine_toc))
        File.write(opf_content, self.content_opf_path)
Esempio n. 2
0
    def gen_toc(self):
        '''
        generate the toc.ncx files
        '''
        if not exists(self.catlog_file):
            print 'Not found catlog file'
            return
        entries = []  #store catlog entry
        self.toc_entries = []
        with open(self.catlog_file) as f:
            lines = f.readlines()
            order = 0
            for line in lines:
                order = order + 1
                catlog = line.split(':')
                if len(catlog) == 2:
                    title = catlog[-1].strip().replace(' ', ' ')
                    self.toc_entries.append(catlog[0].strip())
                    entries.append(
                        toc_nav_item_tpl.format(order, title,
                                                catlog[0].strip()))

        if len(entries) > 1:
            content = toc_format_tpl.format(self.uuid_urn, self.title,
                                            ''.join(entries))
            File.write(content, self.toc_path)
Esempio n. 3
0
 def gen_extra_files(self):
     '''
     generate the extra files of epub format
     e.g:
        mimetype
        META-INF
        container.xml
     '''
     File.write('application/epub+zip', self.mimetype_path)
     File.write(container_xml_tpl, self.container_dot_xml)
Esempio n. 4
0
 def gen_extra_files(self):
     '''
     generate the extra files of epub format
     e.g:
        mimetype
        META-INF
        container.xml
     '''
     File.write('application/epub+zip',self.mimetype_path)
     File.write(container_xml_tpl, self.container_dot_xml)
Esempio n. 5
0
 def gen_content_opf(self):
     '''
     generate the content opf files
     '''
     file_list = []
     for root, dires, files in walk(self.ops_dir):
         for fname in files:
             fpath = relpath(pjoin(root,fname), self.ops_dir).replace('\\','/')
             f_id = self.file_id(fname)
             t_name, file_extension = splitext(fname)
             f_media_type = self.media_type_of(file_extension)
             file_list.append(opf_manifest_item_tpl.format(fpath,f_id, f_media_type))
     
     spine_toc = []
     if self.toc_entries and len(self.toc_entries)>0:
         for toc in self.toc_entries:
             idhref = toc.split('#')[0]
             spine_toc.append(opf_spine_toc_item_tpl.format(idhref))
 
     opf_content = opf_format_tpl.format(self.uuid_urn, self.date, 'tony', ''.join(file_list),
                                         ''.join(spine_toc))
     File.write(opf_content, self.content_opf_path)
Esempio n. 6
0
 def gen_toc(self):
     '''
     generate the toc.ncx files
     '''
     if not exists(self.catlog_file):
         print 'Not found catlog file'
         return
     entries = [] #store catlog entry
     self.toc_entries = []
     with open(self.catlog_file) as f:
         lines = f.readlines()
         order = 0
         for line in lines:
             order = order + 1
             catlog = line.split(':')
             if len(catlog) == 2:
                 title = catlog[-1].strip().replace(' ',' ')
                 self.toc_entries.append(catlog[0].strip())
                 entries.append(
                     toc_nav_item_tpl.format(order,title, catlog[0].strip()))
     
     if len(entries) > 1:
         content = toc_format_tpl.format(self.uuid_urn, self.title, ''.join(entries))
         File.write(content, self.toc_path)