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)
def save_metadata(item, collection, cache=None, sidecar_on_failure=True): ''' save the writable key values in item.meta to the image (translating picty native keys in the `meta` attribute of item to IPTC/XMP/Exif standard keys as necessary) ''' fname = collection.get_path(item) if 'sidecar' in item.__dict__: if os.path.exists(collection.get_path(item.sidecar)): result = metadata.save_sidecar(item, collection.get_path(item.sidecar)) else: del item.sidecar result = metadata.save_metadata(item, fname) else: result = metadata.save_metadata(item, fname) if result: item.mtime = io.get_mtime( fname ) ##todo: this and the next line should be a method of the image class update_thumb_date(item, collection, cache) return True else: if sidecar_on_failure and 'sidecar' not in item.__dict__: item.sidecar = item.uid + '.xmp' metadata.create_sidecar(item, collection.get_path(item), collection.get_path(item.sidecar)) return metadata.save_sidecar(item, collection.get_path(item.sidecar)) return False
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)
def save_metadata_key(item, collection, key, value, cache=None): ''' sets the metadata key to value and saves the change in the image ''' fname = collection.get_path(item) if metadata.save_metadata_key(fname, key, value): item.mtime = io.get_mtime(fname) update_thumb_date(item, collection, cache) return True return False
def save_metadata_key(item,collection,key,value,cache=None): ''' sets the metadata key to value and saves the change in the image ''' fname=collection.get_path(item) if metadata.save_metadata_key(fname,key,value): item.mtime=io.get_mtime(fname) update_thumb_date(item,collection,cache) return True return False
def save_metadata(item,collection,cache=None,sidecar_on_failure=True): ''' save the writable key values in item.meta to the image (translating picty native keys in the `meta` attribute of item to IPTC/XMP/Exif standard keys as necessary) ''' fname=collection.get_path(item) if 'sidecar' in item.__dict__: if os.path.exists(collection.get_path(item.sidecar)): result = metadata.save_sidecar(item,collection.get_path(item.sidecar)) else: del item.sidecar result = metadata.save_metadata(item,fname) else: result = metadata.save_metadata(item,fname) if result: item.mtime=io.get_mtime(fname) ##todo: this and the next line should be a method of the image class update_thumb_date(item,collection,cache) return True else: if sidecar_on_failure and 'sidecar' not in item.__dict__: item.sidecar=item.uid + '.xmp' metadata.create_sidecar(item,collection.get_path(item),collection.get_path(item.sidecar)) return metadata.save_sidecar(item,collection.get_path(item.sidecar)) return False