def __call__(self): while self.i < len(self.items): size = None item = self.items[i] if self.max_size: size = (self.max_size, self.max_size) path = imagemanip.get_jpeg_or_png_image_file( item, self.collection, size, False, True) #keep metadata, apply image edits if path is None: continue dest_path = os.path.join(self.dest_path, os.path.split(path)[1]) if os.path.exists(dest_path): #rename it pass if path != self.collection.get_path(item): io.move_file(path, dest_path) else: io.copy_file(path, dest_path) ##TODO: SEND AN UPDATE MESSAGE if not self.ishighestpriority(): return False ##FIXME: NEED TO CHECK END OF LOOP LOGIC gobject.idle_add(self.plugin.image_write_done) return True
def export_task(self, job, item, complete_cb, destination, max_size): size=None if not item.selected: return if max_size: size=(max_size,max_size) path = imagemanip.get_jpeg_or_png_image_file(item,self.collection,size,False,True) #keep metadata, apply image edits if path is None: return dest_path = os.path.join(destination,os.path.split(path)[1]) if os.path.exists(dest_path): #rename it pass if path != self.collection.get_path(item): io.move_file(path, dest_path) else: io.copy_file(path, dest_path)
def export_task(self, job, item, complete_cb, destination, max_size): size = None if not item.selected: return if max_size: size = (max_size, max_size) path = imagemanip.get_jpeg_or_png_image_file( item, self.collection, size, False, True) #keep metadata, apply image edits if path is None: return dest_path = os.path.join(destination, os.path.split(path)[1]) if os.path.exists(dest_path): #rename it pass if path != self.collection.get_path(item): io.move_file(path, dest_path) else: io.copy_file(path, dest_path)
def __call__(self): try: if io.equal(self.dest_path, self.src_path): ext = io.get_ext(self.dest_path) if ext: ext = '.' + ext h, dpath = tempfile.mkstemp(ext) else: dpath = self.dest_path self.item.image.save(dpath) except: gobject.idle_add(self.plugin.image_write_failed) return True if not metadata.copy_metadata(self.item.meta, self.src_path, dpath): gobject.idle_add(self.plugin.image_write_meta_failed) return True if dpath != self.dest_path: try: io.remove_file(self.dest_path) io.move_file(dpath, self.dest_path) except IOError: gobject.idle_add(self.plugin.image_write_meta_failed) gobject.idle_add(self.plugin.image_write_done) return True
def __call__(self): try: if io.equal(self.dest_path,self.src_path): ext = io.get_ext(self.dest_path) if ext: ext = '.'+ext h,dpath = tempfile.mkstemp(ext) else: dpath = self.dest_path self.item.image.save(dpath) except: gobject.idle_add(self.plugin.image_write_failed) return True if not metadata.copy_metadata(self.item.meta,self.src_path,dpath): gobject.idle_add(self.plugin.image_write_meta_failed) return True if dpath!=self.dest_path: try: io.remove_file(self.dest_path) io.move_file(dpath,self.dest_path) except IOError: gobject.idle_add(self.plugin.image_write_meta_failed) gobject.idle_add(self.plugin.image_write_done) return True
def __call__(self): while self.i < len(self.items): size=None item = self.items[i] if self.max_size: size=(self.max_size,self.max_size) path = imagemanip.get_jpeg_or_png_image_file(item,self.collection,size,False,True) #keep metadata, apply image edits if path is None: continue dest_path = os.path.join(self.dest_path,os.path.split(path)[1]) if os.path.exists(dest_path): #rename it pass if path != self.collection.get_path(item): io.move_file(path, dest_path) else: io.copy_file(path, dest_path) ##TODO: SEND AN UPDATE MESSAGE if not self.ishighestpriority(): return False ##FIXME: NEED TO CHECK END OF LOOP LOGIC gobject.idle_add(self.plugin.image_write_done) return True
def copy_item(self, src_collection, src_item, prefs): 'copy an item from another collection source' try: print 'copying item', src_item, prefs name = os.path.split(src_item.uid)[1] dest_dir = prefs['base_dest_dir'] src_filename = None if src_collection.local_filesystem: src_filename = src_collection.get_path(src_item) temp_filename = '' temp_dir = '' name_scheme = naming_schemes[prefs['name_scheme']] dest_name_template = name_scheme[1] dest_needs_meta = name_scheme[2] if dest_needs_meta and src_item.meta == None: temp_dir = tempfile.mkdtemp('', '.image-', dest_dir) temp_filename = os.path.join(temp_dir, name) try: if src_collection.local_filesystem: io.copy_file( src_filename, temp_filename ) ##todo: this may be a desirable alternative for local images if src_collection.use_sidecars and 'sidecar' in src_item.__dict__ and os.path.exists( src_collection.get_path(src_item.sidecar)): temp_sidecar = os.path.join( temp_dir, os.path.split(src_item.sidecar)[1]) io.copy_file( src_collection.get_path(src_item.sidecar), temp_sidecar) else: open(temp_filename, 'wb').write( src_collection.get_file_stream(src_item).read()) except IOError: print 'Error copying file', src_item import traceback, sys tb_text = traceback.format_exc(sys.exc_info()[2]) print tb_text ##todo: log an error ##todo: maybe better to re-raise the exception here return False src_filename = temp_filename try: imagemanip.load_metadata(src_item, self, src_filename) except: src_item.meta = {} dest_path, dest_name = name_item(src_item, dest_dir, dest_name_template) if not src_collection.local_filesystem: local_name = src_collection.get_file_name(src_item) if local_name: dest_name = local_name if not os.path.exists(dest_path): os.makedirs(dest_path) dest_filename = os.path.join(dest_path, dest_name) print 'copying to dest filename', dest_filename if os.path.exists(dest_filename): if prefs['action_if_exists'] == EXIST_SKIP: print 'SKIPPING', src_item ##TODO: LOGGING TO IMPORT LOG return False if prefs['action_if_exists'] == EXIST_RENAME: dest_filename = altname(dest_filename) try: if prefs['move_files'] or temp_filename: io.move_file( src_filename, dest_filename, overwrite=prefs['action_if_exists'] == EXIST_OVERWRITE) else: if src_collection.local_filesystem: io.copy_file(src_filename, dest_filename, overwrite=prefs['action_if_exists'] == EXIST_OVERWRITE) else: open(dest_filename, 'wb').write( src_collection.get_file_stream(src_item).read()) except IOError: ##todo: log an error ##todo: maybe better to re-raise the exception here print 'Error copying image', src_item import traceback, sys tb_text = traceback.format_exc(sys.exc_info()[2]) print tb_text return False try: if prefs['move_files'] and not temp_filename: src_collection.delete(src_item) if temp_filename and temp_filename != src_filename: io.remove_file(temp_filename) if temp_dir: shutil.rmtree(temp_dir) except IOError: ##todo: log an error ##todo: maybe better to re-raise the exception here print 'Error cleaning up after copying image', src_item import traceback, sys tb_text = traceback.format_exc(sys.exc_info()[2]) print tb_text item = baseobjects.Item(self.get_relpath(dest_filename)) item.mtime = io.get_mtime(dest_filename) item.selected = src_item.selected #copy metadata from the original #TODO: drop metadata not supported by local store? if src_item.meta is not None: item.init_meta(src_item.meta.copy(), self) if src_collection.local_filesystem: #for local filesystems lets copy the backup metadata to ensure that the use #will see there is unsaved data. could also just write the metadata first, but #this gives the user a bit more flexibility. if 'meta_backup' in dir(src_item): item.meta_backup = src_item.meta_backup else: #the item.meta might contain data that isn't in the original, so lets write #it to the image (since a localstore image should always represent what is in #the image) and then reload it to get anything else that wasn't in item.meta self.write_metadata( item) #potential risk of data loss by writing data here self.load_metadata( item, notify_plugins=False) ##TODO: Shoudln't we notify plugins? self.make_thumbnail(item) self.add( item ) ##todo: should we lock the image browser rendering updates for this call?? return True except: print 'Error copying src item' import traceback, sys tb_text = traceback.format_exc(sys.exc_info()[2]) print tb_text return False
def copy_item(self,src_collection,src_item,prefs): 'copy an item from another collection source' try: print 'copying item',src_item,prefs name=os.path.split(src_item.uid)[1] dest_dir=prefs['base_dest_dir'] src_filename=None if src_collection.local_filesystem: src_filename=src_collection.get_path(src_item) temp_filename='' temp_dir='' name_scheme=naming_schemes[prefs['name_scheme']] dest_name_template=name_scheme[1] dest_needs_meta=name_scheme[2] if dest_needs_meta and src_item.meta==None: temp_dir=tempfile.mkdtemp('','.image-',dest_dir) temp_filename=os.path.join(temp_dir,name) try: if src_collection.local_filesystem: io.copy_file(src_filename,temp_filename) ##todo: this may be a desirable alternative for local images if src_collection.use_sidecars and 'sidecar' in src_item.__dict__ and os.path.exists(src_collection.get_path(src_item.sidecar)): temp_sidecar=os.path.join(temp_dir,os.path.split(src_item.sidecar)[1]) io.copy_file(src_collection.get_path(src_item.sidecar),temp_sidecar) else: open(temp_filename,'wb').write(src_collection.get_file_stream(src_item).read()) except IOError: print 'Error copying file',src_item import traceback,sys tb_text=traceback.format_exc(sys.exc_info()[2]) print tb_text ##todo: log an error ##todo: maybe better to re-raise the exception here return False src_filename=temp_filename try: imagemanip.load_metadata(src_item,self,src_filename) except: src_item.meta={} dest_path,dest_name=name_item(src_item,dest_dir,dest_name_template) if not src_collection.local_filesystem: local_name=src_collection.get_file_name(src_item) if local_name: dest_name=local_name if not os.path.exists(dest_path): os.makedirs(dest_path) dest_filename=os.path.join(dest_path,dest_name) print 'copying to dest filename',dest_filename if os.path.exists(dest_filename): if prefs['action_if_exists']==EXIST_SKIP: print 'SKIPPING',src_item ##TODO: LOGGING TO IMPORT LOG return False if prefs['action_if_exists']==EXIST_RENAME: dest_filename=altname(dest_filename) try: if prefs['move_files'] or temp_filename: io.move_file(src_filename,dest_filename,overwrite=prefs['action_if_exists']==EXIST_OVERWRITE) else: if src_collection.local_filesystem: io.copy_file(src_filename,dest_filename,overwrite=prefs['action_if_exists']==EXIST_OVERWRITE) else: open(dest_filename,'wb').write(src_collection.get_file_stream(src_item).read()) except IOError: ##todo: log an error ##todo: maybe better to re-raise the exception here print 'Error copying image',src_item import traceback,sys tb_text=traceback.format_exc(sys.exc_info()[2]) print tb_text return False try: if prefs['move_files'] and not temp_filename: src_collection.delete(src_item) if temp_filename and temp_filename!=src_filename: io.remove_file(temp_filename) if temp_dir: shutil.rmtree(temp_dir) except IOError: ##todo: log an error ##todo: maybe better to re-raise the exception here print 'Error cleaning up after copying image',src_item import traceback,sys tb_text=traceback.format_exc(sys.exc_info()[2]) print tb_text item=baseobjects.Item(self.get_relpath(dest_filename)) item.mtime=io.get_mtime(dest_filename) item.selected=src_item.selected #copy metadata from the original #TODO: drop metadata not supported by local store? if src_item.meta is not None: item.init_meta(src_item.meta.copy(),self) if src_collection.local_filesystem: #for local filesystems lets copy the backup metadata to ensure that the use #will see there is unsaved data. could also just write the metadata first, but #this gives the user a bit more flexibility. if 'meta_backup' in dir(src_item): item.meta_backup=src_item.meta_backup else: #the item.meta might contain data that isn't in the original, so lets write #it to the image (since a localstore image should always represent what is in #the image) and then reload it to get anything else that wasn't in item.meta self.write_metadata(item) #potential risk of data loss by writing data here self.load_metadata(item,notify_plugins=False) ##TODO: Shoudln't we notify plugins? self.make_thumbnail(item) self.add(item) ##todo: should we lock the image browser rendering updates for this call?? return True except: print 'Error copying src item' import traceback,sys tb_text=traceback.format_exc(sys.exc_info()[2]) print tb_text return False