Beispiel #1
0
def update_thumb_date(item,
                      collection,
                      cache=None,
                      interrupt_fn=None,
                      remove_old=True):
    '''
    sets the internal date of the cached thumbnail image to that of the image file
    if the thumbnail name the thumbnail name will be updated
    if no thumbnail is present it will be created
    interrupt_fn - callback that returns False if job should be interrupted
    remove_old - if the item name has changed, removes the old thumbnail
    affects mtime, thumb, thumburi members of item
    '''
    itemfile = collection.get_path(item)
    item.mtime = io.get_mtime(itemfile)
    if item.thumburi:
        oldthumburi = item.thumburi
        if not item.thumb:
            load_thumb(item, collection)
        uri = io.get_uri(itemfile)
        if cache == None:
            thumb_factory.save_thumbnail(item.thumb, uri, int(item.mtime))
            item.thumburi = thumb_factory.lookup(uri, int(item.mtime))
        else:
            if not os.path.exists(cache):
                os.makedirs(cache)
            item.thumburi = os.path.join(
                cache, muuid(item.uid + str(int(item.mtime)))) + '.png'
            item.thumb.save(item.thumburi, "png")
        if remove_old and oldthumburi != item.thumburi:
            io.remove_file(oldthumburi)
        return True
    return make_thumb(item, collection, interrupt_fn, cache=cache)
Beispiel #2
0
def update_thumb_date(item,collection,cache=None,interrupt_fn=None,remove_old=True):
    '''
    sets the internal date of the cached thumbnail image to that of the image file
    if the thumbnail name the thumbnail name will be updated
    if no thumbnail is present it will be created
    interrupt_fn - callback that returns False if job should be interrupted
    remove_old - if the item name has changed, removes the old thumbnail
    affects mtime, thumb, thumburi members of item
    '''
    itemfile=collection.get_path(item)
    item.mtime=io.get_mtime(itemfile)
    if item.thumburi:
        oldthumburi=item.thumburi
        if not item.thumb:
            load_thumb(item,collection)
        uri = io.get_uri(itemfile)
        if cache==None:
            thumb_factory.save_thumbnail(item.thumb,uri,int(item.mtime))
            item.thumburi=thumb_factory.lookup(uri,int(item.mtime))
        else:
            if not os.path.exists(cache):
                os.makedirs(cache)
            item.thumburi=os.path.join(cache,muuid(item.uid+str(int(item.mtime))))+'.png'
            item.thumb.save(item.thumburi,"png")
        if remove_old and oldthumburi!=item.thumburi:
            io.remove_file(oldthumburi)
        return True
    return make_thumb(item,collection,interrupt_fn,cache=cache)
Beispiel #3
0
def delete_thumb(item):
    '''
    remove the thumb from the item and delete the associated thumbnail image file in the cache
    '''
    if item.thumb:
        item.thumb=None
    if item.thumburi:
        try:
            io.remove_file(item.thumburi) ##TODO: What if item is in gnome cache? (This will probably work, but maybe not the best way to remove items from cache?) commented code below doesn't look right (deleting twice?)
        except:
            pass
##        thumburi=thumb_factory.lookup(uri,int(item.mtime))
##        os.remove(thumburi)
        item.thumburi=None
Beispiel #4
0
def delete_thumb(item):
    '''
    remove the thumb from the item and delete the associated thumbnail image file in the cache
    '''
    if item.thumb:
        item.thumb = None
    if item.thumburi:
        try:
            io.remove_file(
                item.thumburi
            )  ##TODO: What if item is in gnome cache? (This will probably work, but maybe not the best way to remove items from cache?) commented code below doesn't look right (deleting twice?)
        except:
            pass


##        thumburi=thumb_factory.lookup(uri,int(item.mtime))
##        os.remove(thumburi)
        item.thumburi = None