示例#1
0
    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
示例#2
0
    def __call__(self):
        jobs=self.worker.jobs
        worker=self.worker
        i=self.countpos
        collection=self.collection

        send_from = self.prefs['from']
        send_to = self.prefs['to']
        subject = self.prefs['subject']
        text = self.prefs['message']
        size = self.prefs['size']
        server = self.prefs['server']
        username = self.prefs['username']
        password = self.prefs['password']
        strip_metadata = self.prefs['strip_metadata']
        apply_edits = self.prefs['apply_edits']

        if self.items==None:
            self.items=self.collection.get_active_view().get_selected_items()
            self.count=len(self.items)
        while len(self.items)>0 and jobs.ishighestpriority(self) and not self.stop:
            item=self.items.pop()
            if self.browser:
                gobject.idle_add(self.browser.update_status,1.0*i/self.count,'Preparing Images - %i of %i'%(i,self.count))
            prefs=self.prefs
            im = imagemanip.get_jpeg_or_png_image_file(item,self.collection,size,strip_metadata,apply_edits)
            if im is not None:
                self.images.append(im)
            i+=1
        self.countpos=i
        if len(self.items)==0:
            if len(self.images)==0: ##nothing to do
                gobject.idle_add(self.browser.update_status,1.0,'Nothing to send')
                self.prefs['error'] = 'No images could be sent (check your selected images)'
                gobject.idle_add(self.plugin.email_failed,self.prefs)
                return True
            if self.browser:
                gobject.idle_add(self.browser.update_status,0.99,'Sending Email ...')
            ## Send email
            try:
                send_mail(send_from, send_to, subject, text, self.images, username, password, server)
                self.prefs['error'] = 'Email sent'
                gobject.idle_add(self.plugin.email_completed,self.prefs)
            except Exception as e:
                import traceback
                self.prefs['error'] = 'Email failed with error message %s\nDetails\n%s'%(e.message,traceback.format_exc())
                gobject.idle_add(self.plugin.email_failed,self.prefs)
                pass ##TODO: notify UI of error
            ## TODO: Clean up images - only remove the temporary copies (commented code below would delete all of the images - not what we want!!)
#            for im in images:
#                io.remove_file(im)
            gobject.idle_add(self.browser.update_status,1.0,'Email Send Done')
            return True
        return False
示例#3
0
文件: flickr.py 项目: eephyne/picty
    def t_upload_photo(self, item, album=None, preferences=None):
        try:

            filename = imagemanip.get_jpeg_or_png_image_file(
                item, preferences[MODEL_COL_SIZE], preferences[MODEL_COL_STRIP]
            )

            if not filename:
                return self.t_notify_photo_uploaded(item, False, "Invalid Image Type")

            title = preferences[MODEL_COL_FLICKR_TITLE]
            if not title:
                title = os.path.split(item.uid)[1]
            tags = preferences[MODEL_COL_FLICKR_TAGS]
            description = preferences[MODEL_COL_FLICKR_DESCRIPTION]
            privacy = preferences[MODEL_COL_FLICKR_PRIVACY]
            public = 1 if privacy == PRIVACY_PUBLIC else 0
            family = 1 if privacy in [PRIVACY_FRIENDS, PRIVACY_FRIENDS_AND_FAMILY] else 0
            friends = 1 if privacy in [PRIVACY_FAMILY, PRIVACY_FRIENDS_AND_FAMILY] else 0
            print "uploading", item.uid, "with privacy", public, family, friends

            def progress_cb(progress, done):
                print "progress notify", progress, done
                self.t_notify_upload_progress(item, progress)

            photo_id = self.flickr_client.upload(
                filename=filename,
                title=title,
                description=description,
                tags=tags,
                is_public=public,
                is_family=family,
                is_friend=friends,
                callback=progress_cb,
            )
            photo_id = photo_id.find("photoid").text

            if album[0]:
                photoset_id = album[1].attrib["id"]
                self.flickr_client.photosets_addPhoto(photoset_id=photoset_id, photo_id=photo_id)

            if filename != item.uid:
                print "WARNING: NOT REMOVING ITEM", item.uid
                ##os.remove(filename) ##TODO: Not safe to do this now that item.uid is stored as a relpath

            self.t_notify_photo_uploaded(item, True, "Successful upload")
        except:
            import traceback, sys

            tb_text = traceback.format_exc(sys.exc_info()[2])
            print "Error on upload", tb_text
            self.t_notify_photo_uploaded(item, False, "Upload Failed")
示例#4
0
    def t_upload_photo(self, item, album=None, preferences=None):
        try:
            if album[0] == '':
                album_url = '/data/feed/api/user/%s/albumid/%s' % (
                    self.gd_c.email, 'default')
            else:
                album_url = '/data/feed/api/user/%s/albumid/%s' % (
                    self.gd_c.email, album[1].gphoto_id.text)  ##
            self.t_notify_upload_progress(item, 50)

            filename = imagemanip.get_jpeg_or_png_image_file(
                item, preferences[MODEL_COL_SIZE],
                preferences[MODEL_COL_STRIP])

            if not filename:
                return self.t_notify_photo_uploaded(item, False,
                                                    'Invalid Image Type')

            photo = gdata.photos.PhotoEntry()
            #photo.summary = 'uploaded with picty'

            import atom
            photo.title = atom.Title()
            if preferences[MODEL_COL_PICASA_TITLE]:
                title = preferences[MODEL_COL_PICASA_TITLE]
            else:
                title = os.path.split(item.uid)[1]
            photo.title.text = title
            photo.media = gdata.media.Group()
            keywords = metadata.tag_bind(
                metadata.tag_split(preferences[MODEL_COL_PICASA_TAGS]), ',')
            if keywords:
                photo.media.keywords = gdata.media.Keywords(text=keywords)
            description = preferences[MODEL_COL_PICASA_DESCRIPTION]
            if description:
                photo.media.description = gdata.media.Description(
                    text=description)
            #photo.media.credit = gdata.media.Credit(text=preferences[MODEL_COL_PICASA_AUTHOR])
            photo = self.gd_c.InsertPhoto(album_url, photo, filename,
                                          io.get_mime_type(filename))
            if filename != item.uid:
                print 'WARNING: NOT REMOVING ITEM', item.uid
                ##os.remove(filename) ##TODO: Not safe to do this now that item.uid is stored as a relpath

            self.t_notify_photo_uploaded(item, True, 'Successful upload')
        except:
            import traceback, sys
            tb_text = traceback.format_exc(sys.exc_info()[2])
            print 'Error on upload', tb_text
            self.t_notify_photo_uploaded(item, False, 'Upload Failed')
示例#5
0
 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)
示例#6
0
 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)
示例#7
0
    def t_upload_photo(self,item,album=None,preferences=None):
        try:
            if album[0]=='':
                album_url = '/data/feed/api/user/%s/albumid/%s' % (self.gd_c.email, 'default')
            else:
                album_url = '/data/feed/api/user/%s/albumid/%s' % (self.gd_c.email, album[1].gphoto_id.text) ##
            self.t_notify_upload_progress(item,50)

            filename=imagemanip.get_jpeg_or_png_image_file(item,preferences[MODEL_COL_SIZE],preferences[MODEL_COL_STRIP])

            if not filename:
                return self.t_notify_photo_uploaded(item,False,'Invalid Image Type')

            photo = gdata.photos.PhotoEntry()
            #photo.summary = 'uploaded with picty'

            import atom
            photo.title=atom.Title()
            if preferences[MODEL_COL_PICASA_TITLE]:
                title=preferences[MODEL_COL_PICASA_TITLE]
            else:
                title=os.path.split(item.uid)[1]
            photo.title.text = title
            photo.media = gdata.media.Group()
            keywords=metadata.tag_bind(metadata.tag_split(preferences[MODEL_COL_PICASA_TAGS]),',')
            if keywords:
                photo.media.keywords = gdata.media.Keywords(text=keywords)
            description=preferences[MODEL_COL_PICASA_DESCRIPTION]
            if description:
                photo.media.description = gdata.media.Description(text=description)
            #photo.media.credit = gdata.media.Credit(text=preferences[MODEL_COL_PICASA_AUTHOR])
            photo=self.gd_c.InsertPhoto(album_url, photo, filename, io.get_mime_type(filename))
            if filename!=item.uid:
                print 'WARNING: NOT REMOVING ITEM',item.uid
                ##os.remove(filename) ##TODO: Not safe to do this now that item.uid is stored as a relpath

            self.t_notify_photo_uploaded(item,True,'Successful upload')
        except:
            import traceback, sys
            tb_text=traceback.format_exc(sys.exc_info()[2])
            print 'Error on upload',tb_text
            self.t_notify_photo_uploaded(item,False,'Upload Failed')
示例#8
0
    def t_upload_photo(self,item,album=None,preferences=None):
        try:

            filename=imagemanip.get_jpeg_or_png_image_file(item,preferences[MODEL_COL_SIZE],preferences[MODEL_COL_STRIP])

            if not filename:
                return self.t_notify_photo_uploaded(item,False,'Invalid Image Type')


            title=preferences[MODEL_COL_FLICKR_TITLE]
            if not title:
                title=os.path.split(item.uid)[1]
            tags=preferences[MODEL_COL_FLICKR_TAGS]
            description=preferences[MODEL_COL_FLICKR_DESCRIPTION]
            privacy=preferences[MODEL_COL_FLICKR_PRIVACY]
            public=1 if privacy==PRIVACY_PUBLIC else 0
            family=1 if privacy in [PRIVACY_FRIENDS,PRIVACY_FRIENDS_AND_FAMILY] else 0
            friends=1 if privacy in [PRIVACY_FAMILY,PRIVACY_FRIENDS_AND_FAMILY] else 0
            print 'uploading',item.uid,'with privacy',public,family,friends

            def progress_cb(progress,done):
                print 'progress notify',progress,done
                self.t_notify_upload_progress(item,progress)
            photo_id=self.flickr_client.upload(filename=filename,title=title,description=description,tags=tags,
                is_public=public,is_family=family,is_friend=friends,callback=progress_cb)
            photo_id=photo_id.find('photoid').text

            if album[0]:
                photoset_id=album[1].attrib['id']
                self.flickr_client.photosets_addPhoto(photoset_id=photoset_id,photo_id=photo_id)

            if filename!=item.uid:
                print 'WARNING: NOT REMOVING ITEM',item.uid
                ##os.remove(filename) ##TODO: Not safe to do this now that item.uid is stored as a relpath

            self.t_notify_photo_uploaded(item,True,'Successful upload')
        except:
            import traceback, sys
            tb_text=traceback.format_exc(sys.exc_info()[2])
            print 'Error on upload',tb_text
            self.t_notify_photo_uploaded(item,False,'Upload Failed')
示例#9
0
    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