Ejemplo n.º 1
0
    def getBlob(self, identifier, try_diskcache=True, try_vault=True):
        '''get a blob (unidentified media data)
        @raise KeyError: if reading the data of the identifier went wrong 
        '''
        filelike=None
        
        if try_diskcache:
            filelike = self.doc_diskcache.get(identifier)
        
        if not filelike and try_vault and identifier:
            try:
                filelike = self.vault.get(identifier)
            except KeyError as exceptobj:
                raise 
            
            if hasattr(filelike, "name"):
                inputfilename = filelike.name
            else:
                inputfilename = tempfilecopy(filelike) 
            
            try:
                osdescriptor, decryptedfilename = tempfile.mkstemp(); os.close(osdescriptor)
                decrypt_verify(inputfilename, decryptedfilename, settings.STORAGE_DECRYPT["gpghome"],
                    settings.STORAGE_DECRYPT ["owner"])
            except IOError as exceptobj:
                raise KeyError, "could not decrypt blob with identifier %s, exception was %r" % (identifier, exceptobj)
    
            try:
                with open(decryptedfilename, "rb") as decryptedfilelike:
                    self.doc_diskcache.create_or_update(identifier, decryptedfilelike)
            except IOError as exceptobj:
                raise KeyError, "could not put decrypted blob with identifier %s into diskcache, exception was %r" %(identifier, exceptobj)

            filelike = self.doc_diskcache.get(identifier)
        return filelike
Ejemplo n.º 2
0
def render_pages(identifier, filelike, private_workdir):
    tiles = settings.MS_SHARED ["tiles"]
    resolutions = settings.MS_SHARED ["resolutions"]
    aspect_ratio = settings.MS_SHARED ["aspect_ratio"]
    dpi = settings.MS_SHARED ["dpi"]
    depth = settings.MS_SHARED ["depth"]   
    
    copied_file = False   
    if hasattr(filelike,"name"):
        tmp_sourcefilename = filelike.name
    elif hasattr(filelike, "read"):
        tmp_sourcefilename = tempfilecopy(filelike)
        copied_file = True
    
    try:   
        for t in tiles:
            for w in resolutions:
                for page, data in pdf2pngs(identifier, tmp_sourcefilename, private_workdir, w, t, t, aspect_ratio, dpi, depth):
                    yield page, data
    finally:
        if copied_file:
            if os.path.exists(tmp_sourcefilename):
                os.remove(tmp_sourcefilename)