Beispiel #1
0
def apply_trailing_byte_sequences(index_table, records, text_record_lengths):
    entries = tuple(Entry(r['index'], r['offset'], r['length'], r['depth'],
        r.get('parent', None), r.get('first_child', None), r.get('last_child',
            None), r['label'], None, None, None, None) for r in index_table)

    indexing_data = collect_indexing_data(entries, text_record_lengths)
    try:
        rmap = calculate_all_tbs(indexing_data)
    except NegativeStrandIndex:
        rmap = calculate_all_tbs(indexing_data, tbs_type=5)

    for i, tbs_bytes in rmap.iteritems():
        records[i] += encode_trailing_data(tbs_bytes)

    return True
Beispiel #2
0
def apply_trailing_byte_sequences(index_table, records, text_record_lengths):
    entries = tuple(Entry(r['index'], r['offset'], r['length'], r['depth'],
        r.get('parent', None), r.get('first_child', None), r.get('last_child',
            None), r['label'], None, None, None, None) for r in index_table)

    indexing_data = collect_indexing_data(entries, text_record_lengths)
    try:
        rmap = calculate_all_tbs(indexing_data)
    except NegativeStrandIndex:
        rmap = calculate_all_tbs(indexing_data, tbs_type=5)

    for i, tbs_bytes in rmap.iteritems():
        records[i] += encode_trailing_data(tbs_bytes)

    return True
Beispiel #3
0
 def generate_index(self):
     self.primary_index_record_idx = None
     if self.oeb.toc.count() < 1:
         self.log.warn('No TOC, MOBI index not generated')
         return
     try:
         self.indexer = Indexer(
             self.serializer, self.last_text_record_idx,
             len(self.records[self.last_text_record_idx]),
             self.masthead_offset, self.is_periodical, self.opts, self.oeb)
     except:
         self.log.exception('Failed to generate MOBI index:')
     else:
         self.primary_index_record_idx = len(self.records)
         for i in xrange(self.last_text_record_idx + 1):
             if i == 0: continue
             tbs = self.indexer.get_trailing_byte_sequence(i)
             self.records[i] += encode_trailing_data(tbs)
         self.records.extend(self.indexer.records)
Beispiel #4
0
 def generate_index(self):
     self.primary_index_record_idx = None
     if self.oeb.toc.count() < 1:
         self.log.warn('No TOC, MOBI index not generated')
         return
     try:
         self.indexer = Indexer(self.serializer, self.last_text_record_idx,
                 len(self.records[self.last_text_record_idx]),
                 self.masthead_offset, self.is_periodical,
                 self.opts, self.oeb)
     except:
         self.log.exception('Failed to generate MOBI index:')
     else:
         self.primary_index_record_idx = len(self.records)
         for i in xrange(self.last_text_record_idx + 1):
             if i == 0: continue
             tbs = self.indexer.get_trailing_byte_sequence(i)
             self.records[i] += encode_trailing_data(tbs)
         self.records.extend(self.indexer.records)
Beispiel #5
0
    def write_uncrossable_breaks(self):  # {{{
        '''
        Write information about uncrossable breaks (non linear items in
        the spine.
        '''
        if not WRITE_UNCROSSABLE_BREAKS:
            return

        breaks = self.serializer.breaks

        for i in range(1, self.last_text_record_idx+1):
            offset = i * RECORD_SIZE
            pbreak = 0
            running = offset

            buf = io.BytesIO()

            while breaks and (breaks[0] - offset) < RECORD_SIZE:
                pbreak = (breaks.pop(0) - running) >> 3
                encoded = encint(pbreak)
                buf.write(encoded)
                running += pbreak << 3
            encoded = encode_trailing_data(buf.getvalue())
            self.records[i] += encoded
Beispiel #6
0
    def write_uncrossable_breaks(self): # {{{
        '''
        Write information about uncrossable breaks (non linear items in
        the spine.
        '''
        if not WRITE_UNCROSSABLE_BREAKS:
            return

        breaks = self.serializer.breaks

        for i in xrange(1, self.last_text_record_idx+1):
            offset = i * RECORD_SIZE
            pbreak = 0
            running = offset

            buf = StringIO()

            while breaks and (breaks[0] - offset) < RECORD_SIZE:
                pbreak = (breaks.pop(0) - running) >> 3
                encoded = encint(pbreak)
                buf.write(encoded)
                running += pbreak << 3
            encoded = encode_trailing_data(buf.getvalue())
            self.records[i] += encoded