Пример #1
0
 def _update_object(self, uid, obj):
     if self._delete_object(uid):
         uid = self._create_object(obj)
         return uid
     else:
         raise Exceptions.SyncronizeError(
             "Error updating object (uid: %s)" % uid)
Пример #2
0
    def _upload_photo(self, uploadInfo):
        """
        Import a file into the f-spot catalog
        """
        # Check if remote is read only
        if self.photo_remote.IsReadOnly():
            raise Exceptions.SyncronizeError(
                _("F-Spot DBus interface is operating in read-only mode"))

        # create roll if necessary
        if not self.has_roll:
            self.prepare_roll()

        # start with enabled tags from gui, they exist in fspot for sure
        tags = list(self.enabledTags)

        # add tags from upload info
        for tag in uploadInfo.tags:
            self._create_tag(tag)
            tags.append(tag)

        # import the photo
        try:
            id = self.photo_remote.ImportPhoto(uploadInfo.url, True, tags)
            return Rid(uid=str(id))
        except:
            raise Exceptions.SynchronizeError('Import Failed')
Пример #3
0
 def _replace_photo(self, id, uploadInfo):
     """
     Updates a photo (binary and metadata)
     """
     try:
         fotoId = self.zapi.update_photo(id, uploadInfo)
     except Exception, e:
         raise Exceptions.SyncronizeError("Zoto Update Error.")
Пример #4
0
 def _upload_photo(self, uploadInfo):
     """
     Upload to album
     """
     try:
         fotoId = self.zapi.add_to_album(uploadInfo, self.albumId)
     except Exception, e:
         raise Exceptions.SyncronizeError("Zoto Upload Error.")
Пример #5
0
    def _update_note(self, uid, note):
        log.debug("Updating note uid: %s" % uid)
        if note.get_xml() != None:
            ok = self.remoteTomboy.SetNoteCompleteXml(uid, note.get_xml())
        else:
            ok = self.remoteTomboy.SetNoteContents(uid, note.get_contents())

        if not ok:
            raise Exceptions.SyncronizeError(
                "Error setting Tomboy note content (uri: %s)" % uid)
Пример #6
0
    def _upload_photo(self, uploadInfo):
        """
		Upload to album
		"""
        try:
            ret = self.salbum.uploadPhoto(uploadInfo.url, uploadInfo.mimeType,
                                          uploadInfo.name)
            return Rid(ret.id)
        except Exception, e:
            raise Exceptions.SyncronizeError("Shutterfly Upload Error.")
Пример #7
0
 def get(self, LUID):
     for title in self._notes:
         uid, timestamp, content = self._notes[title]
         if uid == LUID:
             n = Note.Note(
                 title=title,
                 #FIXME: Backpack doesnt have mtime, only creation time
                 modified=datetime.datetime.fromtimestamp(timestamp),
                 contents=content)
             n.set_UID(LUID)
             return n
     raise Exceptions.SyncronizeError("Could not find note %s" % LUID)
Пример #8
0
 def _upload_photo(self, uploadInfo):
     """
     Upload to album; and return image id here
     """
     try:
         rsp = self.fapi.photos.upload(uploadInfo.url,
                                       aid=self.albums.get(
                                           self.albumname, None))
         pid = str(rsp["pid"])
         return Rid(uid=pid)
     except pyfacebook.FacebookError, f:
         raise Exceptions.SyncronizeError("Facebook Upload Error %s" % f)
Пример #9
0
    def _create_object(self, note):
        obj = evolution.ecal.ECalComponent(
            evolution.ecal.CAL_COMPONENT_JOURNAL)
        obj.set_summary(note.title)
        if note.contents != None:
            obj.set_description(note.contents)
        uid = self.memos.add_object(obj)

        if uid != None:
            mtime = datetime.datetime.fromtimestamp(obj.get_modified())
            note = self._get_object(uid)
            return note.get_rid()
        else:
            raise Exceptions.SyncronizeError("Error creating memo")
Пример #10
0
 def put(self, data, overwrite, LUID=None):
     DataProvider.DataSink.put(self, data, overwrite, LUID)
     if self.slow:
         time.sleep(1)
     if self.count >= self.errorAfter:
         if self.errorFatal:
             raise Exceptions.SyncronizeFatalError(
                 "Error After:%s Count:%s" % (self.errorAfter, self.count))
         else:
             raise Exceptions.SyncronizeError("Error After:%s Count:%s" %
                                              (self.errorAfter, self.count))
     self.count += 1
     newData = TestDataType(data.get_UID())
     return newData.get_rid()
Пример #11
0
    def delete(self, LUID):
        """
        Delete a photo by ID
        """
        if not self.sphotos.has_key(LUID):
            log.warn("Photo does not exist")
            return

        try:
            self.zapi.delete_from_album(LUID, self.albumId)
            del self.sphotos[LUID]
        except xmlrpclib.Fault, e:
            raise Exceptions.SyncronizeError("Zoto Delete Error: " +
                                             e.faultString)
Пример #12
0
    def _create_object(self, event):
        # work around.. (avoid duplicate UIDs)
        if "UID" in [x.name for x in list(event.iCal.lines())]:
            event.iCal.remove(event.iCal.uid)

        obj = evolution.ecal.ECalComponent(evolution.ecal.CAL_COMPONENT_TODO,
                                           event.get_ical_string())
        if self.tasks.add_object(obj):
            mtime = datetime.datetime.fromtimestamp(obj.get_modified())
            return conduit.datatypes.Rid(uid=obj.get_uid(),
                                         mtime=mtime,
                                         hash=mtime)
        else:
            raise Exceptions.SyncronizeError("Error creating event")
Пример #13
0
    def delete(self, LUID):
        """
		Delete a photo by ID
		Deleting a photo invalidates album length and photo index values.
		We must reload the photos (or do something else...)
		"""
        if not self.sphotos.has_key(LUID):
            log.warn("Photo does not exist")
            return

        try:
            self.salbum.deletePhoto(self.sphotos[LUID])
        except Exception, e:
            raise Exceptions.SyncronizeError(
                "Shutterfly Delete Error - Try Again.")
Пример #14
0
    def put(self, photo, overwrite, LUID=None):
        """
        Accepts a vfs file. Must be made local.
        I also store a md5 of the photos uri to check for duplicates
        """
        DataProvider.DataSink.put(self, photo, overwrite, LUID)

        originalName = photo.get_filename()
        #Gets the local URI (/foo/bar). If this is a remote file then
        #it is first transferred to the local filesystem
        photoURI = photo.get_local_uri()
        mimeType = photo.get_mimetype()
        tags = photo.get_tags()
        caption = photo.get_caption()

        uploadInfo = UploadInfo(photoURI, mimeType, originalName, tags,
                                caption)

        if overwrite and LUID:
            rid = self._replace_photo(LUID, uploadInfo)
        else:
            if LUID and self._get_photo_info(LUID):
                remotePhoto = self.get(LUID)
                comp = photo.compare(remotePhoto, False)
                log.debug(
                    "Compared %s with %s. Result = %s" %
                    (photo.get_filename(), remotePhoto.get_filename(), comp))

                if LUID != None and comp == conduit.datatypes.COMPARISON_NEWER:
                    rid = self._replace_photo(LUID, uploadInfo)
                elif comp == conduit.datatypes.COMPARISON_EQUAL:
                    rid = remotePhoto.get_rid()
                else:
                    raise Exceptions.SynchronizeConflictError(
                        comp, photo, remotePhoto)
            else:
                log.debug(
                    "Uploading Photo URI = %s, Mimetype = %s, Original Name = %s"
                    % (photoURI, mimeType, originalName))
                rid = self._upload_photo(uploadInfo)

        if not rid:
            raise Exceptions.SyncronizeError("Error putting/updating photo")
        else:
            return rid
Пример #15
0
    def put(self, note, overwrite, LUID=None):
        DataProvider.DataSink.put(self, note, overwrite, LUID)

        #If all that went well then actually store some notes.
        uid = None
        try:
            if note.title in self._notes:
                log.debug("Updating Existing")
                uid, oldtimestamp, oldcontent = self._notes[note.title]
                self.ba.notes.update(self.pageID, uid, note.title,
                                     note.contents)
            else:
                log.debug("Creating New (title: %s)" % note.title)
                uid, title, timestamp, content = self.ba.notes.create(
                    self.pageID, note.title, note.contents)
                self._notes[title] = (uid, timestamp, content)
        except backpack.BackpackError, err:
            raise Exceptions.SyncronizeError("Could not sync note (%s)" % err)
Пример #16
0
 def refresh(self):
     DataProvider.DataSource.refresh(self)
     # sqlite3 is not thread safe, so we cannot preserve connections in this class
     con = sqlite3.connect(
         os.path.join(FFDIR, self.profilepath, "places.sqlite"))
     try:
         # table structure
         # moz_bookmarks: id|type|fk|parent|position|title|keyword_id|folder_type|dateAdded|lastModified
         # moz_places: id|url|title|rev_host|visit_count|hidden|typed|favicon_id|frecency
         cur = con.execute(
             "SELECT b.title,p.url FROM moz_bookmarks b, moz_places p WHERE b.fk=p.id;"
         )
     except:
         con.close()
         raise Exceptions.SyncronizeError(
             "Can't read Firefox 3 Bookmarks - Make sure Firefox is closed."
         )
     for (title, url) in cur.fetchall():
         bookmark = Bookmark.Bookmark(title, url)
         bookmark.set_UID(bookmark.get_hash())
         self._bookmarks.append(bookmark)
     con.close()
Пример #17
0
    def get(self, LUID):
        DataProvider.DataSource.get(self, LUID)
        if self.slow:
            time.sleep(1)

        index = int(LUID)
        if index >= self.errorAfter:
            if self.errorFatal:
                raise Exceptions.SyncronizeFatalError(
                    "Error After:%s Count:%s" % (self.errorAfter, index))
            else:
                raise Exceptions.SyncronizeError("Error After:%s Count:%s" %
                                                 (self.errorAfter, index))

        mtime = DEFAULT_MTIME
        if self.newMtime:
            mtime = datetime.datetime.now()

        hash = DEFAULT_HASH
        if self.newHash:
            hash = Utils.random_string()

        data = TestDataType(LUID, mtime, hash)
        return data
Пример #18
0
 def _create_object(self, contact):
     obj = evolution.ebook.EContact(vcard=contact.get_vcard_string())
     if self.book.add_contact(obj):
         return self._get_object(obj.get_uid()).get_rid()
     else:
         raise Exceptions.SyncronizeError("Error creating contact")