Show
Ignore:
Timestamp:
01/22/09 09:00:37 (19 months ago)
Author:
Ga?tan de Menten <ged@…>
Children:
102:91c56813903c, 103:6153a53efa40
Branch:
default
Message:

- enable compression in the resulting OO document
- preserve file permissions of files inside the OO document

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • relatorio/templates/opendocument.py

    r99 r100  
    2323import re 
    2424import md5 
     25import time 
    2526import urllib 
    2627import zipfile 
     
    401402        # find the position in the row of the cells holding the 
    402403        # <for> and </for> instructions 
    403         #XXX: count cells only instead of * ? 
     404        # We use "*" so as to count both normal cells and covered/hidden cells 
    404405        position_xpath_expr = 'count(preceding-sibling::*)' 
    405406        opening_pos = \ 
     
    621622            files.setdefault(stream_for, []).append((kind, data, pos)) 
    622623 
     624        now = time.localtime()[:6] 
    623625        for f_info in self.inzip.infolist(): 
    624626            if f_info.filename.startswith('ObjectReplacements'): 
     
    626628            elif f_info.filename in files: 
    627629                stream = files[f_info.filename] 
    628                 self.outzip.writestr(f_info.filename, 
    629                                      output_encode(self.xml_serializer(stream))) 
     630                # create a new file descriptor, copying some attributes from 
     631                # the original file 
     632                new_info = zipfile.ZipInfo(f_info.filename, now) 
     633                for attr in ('compress_type', 'flag_bits', 'create_system'): 
     634                    setattr(new_info, attr, getattr(f_info, attr)) 
     635                serialized_stream = output_encode(self.xml_serializer(stream)) 
     636                self.outzip.writestr(new_info, serialized_stream) 
    630637            else: 
    631638                self.outzip.writestr(f_info, self.inzip.read(f_info.filename))