Ejemplo n.º 1
0
    def postEntry (self, username, password, base_url, title,
                   entry, keywords, client, gconf_prefix):

        url = self._getURL(base_url, client, gconf_prefix)

        if (base_url == None):
            hig_alert.reportError("Could not post Blog entry", "No XML-RPC server URL to post blog entries to is set, or the value could not be retrieved from GConf. Your entry will remain in the blogger window.")
            return False

        blog_id  = client.get_string(gconf_prefix + "/blog_id")

        success = True

        #check for GNOME proxy configurations and use if required
        proxy_transport = proxy.GnomeProxyTransport(client)
        server = proxy_transport.get_server(url);

        content = {}
        content['title'] = title
        content['description'] = entry
	content['mt_keywords'] = keywords

        try:
            server.metaWeblog.newPost(blog_id, username, password, content, xmlrpclib.True)
        except xmlrpclib.Fault, e:
            hig_alert.handleBloggerAPIFault(e, "Could not post blog entry", username, blog_id, url)
            success = False
Ejemplo n.º 2
0
    def postEntry (self, username, password, base_url, title, entry, keywords, client, gconf_prefix):
        global appkey

        url = self._getURL(base_url, client, gconf_prefix)
        
        if (base_url == None):
            hig_alert.reportError(_("Could not post Blog entry"), _("No XML-RPC server URL to post blog entries to is set, or the value could not be retrieved from GConf. Your entry will remain in the blogger window."))
            return False

        blog_id  = client.get_string(gconf_prefix + "/blog_id")

        if (blog_id == None):
            blog_id = ""

        if (username == None):
            username = ""

        if (password == None):
            password = ""
            
        content = title + "\n" + entry
        success = True

        #check for GNOME proxy configurations and use if required
        proxy_transport = proxy.GnomeProxyTransport(client)
        server = proxy_transport.get_server(url); 

        try:
            server.blogger.newPost(appkey, blog_id, username, password,
                                   content, xmlrpclib.True)
        except xmlrpclib.Fault, e:
            hig_alert.handleBloggerAPIFault(e, _("Could not post blog entry"), username, blog_id, url)
            success = False
Ejemplo n.º 3
0
 def _postIsReasonable(self, text):
     # Popup a dialogue confirming even if its deemed
     # unreasonable
     if not text:
         hig_alert.reportError(_("Blog Entry is Blank"), _("No text was entered in the blog entry box. Please enter some text and try again"))
         return False
     else:
         return True
Ejemplo n.º 4
0
    def _onDragDataReceived(self, widget, drag_context, window_x, window_y,
                            selection_data, info, timestamp):

        if (info == 398):
            # 398 means text/uri-list
            assert(selection_data.format == 8)
            uri_list = selection_data.data
            uris = uri_list.split('\r\n')

            (buffer_x, buffer_y) = self.window_to_buffer_coords(gtk.TEXT_WINDOW_WIDGET,
                                                                window_x, window_y)

            dnd_iter = self.get_iter_at_location(buffer_x, buffer_y)
            
            for uri in uris:
                if (len(uri) <= 0):
                    continue

                loader = gtk.gdk.PixbufLoader()

                try:
                    myfile = gio.File(uri=uri)
                    file_info = myfile.query_info(gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE)
                    content_type = file_info.get_content_type()
                    file_contents, length, etag = myfile.load_contents()
                except gio.Error, e:
                    hig_alert.reportError(_("Could not load dragged in image"),
                                          _("Error loading %s was: %s") % (hig_alert.italic(uri), e))
                loader.write(file_contents)
                try:
                    loader.close()
                    pixbuf = loader.get_pixbuf()                    
                except gobject.GError, e:
                    pixbuf = None
                    hig_alert.reportError(_("Could not load dragged in image"),
                                          _("Error loading %s was: %s") % (hig_alert.italic(uri), e))
                    
                if (pixbuf):
                    # Create a new image tag
                    image_tag = self._getUniqueTag()
                    image_tag.opening_tag = ""
                    image_tag.closing_tag = ""
                    image_tag.file_contents = file_contents
                    paths = uri.split('/')
                    image_tag.name = paths[len(paths) - 1]
                    image_tag.mime_type = content_type

                    self.images.append(image_tag)
                    
                    # Insert the pixbuf, and then set the new image
                    # tag around it so that we can generate its HTML later
                    start_offset = dnd_iter.get_offset()

                    self.buffer.insert_pixbuf(dnd_iter, pixbuf)
                    
                    start = self.buffer.get_iter_at_offset(start_offset)
                    self.buffer.apply_tag(image_tag, start, dnd_iter)
Ejemplo n.º 5
0
    def _onPostButtonClicked(self, button):
        global gconf_prefix, appkey

        images = self.blogEntry.getImages()

        try:
            for image in images:
                image.uri = blog.uploadImage(image, gconf_prefix)
                image.opening_tag = '<img src="%s"/>' % (image.uri)
        except blog.FeatureNotSupported, e:
            hig_alert.reportError(_("Couldn't upload images"), _("The blog protocol in use does not support uploading images"))
Ejemplo n.º 6
0
    def postEntry(self, username, password, base_url, title, entry, keywords, client, gconf_prefix):
        blog_id = client.get_string(gconf_prefix + "/blog_id")

        if blog_id == None:
            blog_id = ""

        if username == None:
            username = ""

        if password == None:
            password = ""

        url = self._getURL(base_url, client, gconf_prefix)

        # consider GNOME proxy configuration, but perhaps python's gdata lib does that?

        post = gdata.GDataEntry()
        post.title = atom.Title(title_type="xhtml", text=title)
        post.content = atom.Content(content_type="html", text=entry)

        if keywords is not None and keywords != "":
            scheme = "http://www.blogger.com/atom/ns#"
            for keyword in keywords.split(","):
                post.category.append(atom.Category(keyword, scheme))

        success = True

        error_name = _("Could not post entry.")
        try:
            blogger_service = self._login(username, password)
        except service.CaptchaRequired as message:
            hig_alert.reportError(error_name, _("A captcha was required for authentication."))  # TODO; propagate it
            success = False
        except service.BadAuthentication as message:
            hig_alert.reportError(error_name, _("Username or password was invalid."))
            success = False
        except service.Error as message:
            hig_alert.reportError(error_name, _("Failed to login: %s" % message))
            success = False
        except socket.gaierror as message:
            hig_alert.reportError(error_name, _("Socket error: %s.  Perhaps try again." % message))
            success = False

        if success == True:
            try:
                blogger_service.Post(post, "/feeds/%s/posts/default" % blog_id)
            except service.RequestError as message:
                hig_alert.reportError(error_name, _("Failed to post: %s" % message["body"]))

        return success
Ejemplo n.º 7
0
    def postEntry (self, username, password, url, title, entry, keywords, client, gconf_prefix):

        #check for GNOME proxy configurations and use if required
        proxy_transport = proxy.GnomeProxyTransport(client)
        server = proxy_transport.get_server(url);

        try:
          cookie = server.authenticate(username, password)
        except xmlrpclib.Fault, e:
          if (server.user.exists (username) == 0):
            hig_alert.reportError(_("Could not post Blog entry"), _("Your username is invalid. Please double-check the preferences."))
            return FALSE
          else:
            hig_alert.reportError(_("Could not post Blog entry"), _("Your username or password is invalid. Please double-check the preferences."))
            return FALSE
Ejemplo n.º 8
0
    def postEntry(self, username, password, url, title, entry, keywords, client, gconf_prefix):

        # check for GNOME proxy configurations and use if required
        proxy_transport = proxy.GnomeProxyTransport(client)
        server = proxy_transport.get_server(url)

        info = {"username": username, "password": password, "clientversion": ver}

        try:
            cookie = server.LJ.XMLRPC.login(info)
        except xmlrpclib.Fault, e:
            hig_alert.reportError(
                _("Could not post Blog entry"),
                _("Your username or password is invalid. Please double-check the preferences."),
            )
            return FALSE
Ejemplo n.º 9
0
    def getBlogList(self, username, password, base_url, client, gconf_prefix):
        # TODO: consider GNOME proxy configurations, as in bloggerAPI.py
        error_name = _("Could not get list of blogs.")

        try:
            blogger_service = self._login(username, password)
        except service.CaptchaRequired as message:
            hig_alert.reportError(
                error_name, _("A CAPTCHA was required for authentication.")
            )  # TODO: propagadate captcha
            return None
        except service.BadAuthentication as message:
            hig_alert.reportError(error_name, _("Username or password was invalid."))
            return None
        except service.Error as message:
            hig_alert.reportError(error_name, _("Failed to login: %s" % message))
            return None
        except socket.gaierror as message:
            hig_alert.reportError(error_name, _("Socket error: %s.  Perhaps try again." % message))
            return None

        blog_list = blogger_service.Get("/feeds/default/blogs")
        # is there anyway to sort these by recently used?

        if (blog_list.entry == None) or (len(blog_list.entry) == 0):
            # No blogs found
            hig_alert.reportError(
                _("No Blogs Found"),
                _("No errors were reported, but no blogs were found at %s for %s\n" % (url, username)),
            )

        string_value_pairs = []

        for blog in blog_list.entry:
            blog_title = blog.title.text
            blog_id = blog.id.text.split("-")[-1]
            string_value_pairs.append((blog_title, blog_id))

        return string_value_pairs
Ejemplo n.º 10
0
        #check for GNOME proxy configurations and use if required
        proxy_transport = proxy.GnomeProxyTransport(client)
        server = proxy_transport.get_server(url); 

        try:
            bloglist = server.blogger.getUsersBlogs(appkey, username, password)
        except xmlrpclib.Fault, e:
            hig_alert.handleBloggerAPIFault(e, _("Could not get list of blogs"), username, None, url)
            return
        except xmlrpclib.ProtocolError, e:            
            hig_alert.reportError(_("Could not get list of blogs"), _('URL \'%s\' does not seem to be a valid bloggerAPI XML-RPC server. Web server reported: %s.') % (url, hig_alert.italic(e.errmsg)))
            return

        if ((bloglist == None) or (len(bloglist) == 0)):
            # No blogs found!
            hig_alert.reportError("No Blogs Found", "No errors were reported, but no blogs were found at %s for username %s\n" % ( url, username))
            return

        string_value_pairs = []

        for blog in bloglist:
            string_value_pairs.append((blog["blogName"], blog["blogid"]))

        return string_value_pairs



    def postEntry (self, username, password, base_url, title, entry, keywords, client, gconf_prefix):
        global appkey

        url = self._getURL(base_url, client, gconf_prefix)
Ejemplo n.º 11
0
            "lineendings": "unix",
            "year": curtime[0],
            "mon": curtime[1],
            "day": curtime[2],
            "hour": curtime[3],
            "min": curtime[4],
            "props": {"opt_preformatted": 1},
        }

        try:
            server.LJ.XMLRPC.postevent(info)

        except xmlrpclib.Fault, e:
            hig_alert.handleBloggerAPIFault(e, _("Could not post blog entry"), username, username, url)
            success = FALSE
        except xmlrpclib.ProtocolError, e:
            hig_alert.reportError(
                _("Could not post Blog entry"),
                _("URL '%s' does not seem to be a valid LiveJournal XML-RPC server. Web server reported: %s.")
                % (url, hig_alert.italic(e.errmsg)),
            )
            success = FALSE

        print("Success is....")
        print(success)

        return success


blog = Blog()
Ejemplo n.º 12
0
    def _updateBlogType(self, blog_type):
        client = gconf.client_get_default()

        lookup = True

        print 'blog type: ' + blog_type

        if blog_type == "custom":
            url = None
            url_ending = ""
            protocol = None
            url_description = _("XML-RPC URL:")
        elif blog_type == "custom-mt":
            url = None
            url_ending = "/mt-xmlrpc.cgi"
            protocol = "MetaWeblog"
            url_description = _("Base Blog URL:")
        elif blog_type == "custom-pybloxsom":
            url = None
            url_ending = "/RPC"
            protocol = "bloggerAPI"
            url_description = _("Base Blog URL:")
        elif blog_type == "custom-wordpress":
            url = None
            url_ending = "/xmlrpc.php"
            protocol = "MetaWeblog"
            url_description = _("Base Blog URL:")
        elif blog_type == "blogs.gnome.org":
            url = "http://blogs.gnome.org/xmlrpc/"
            url_ending = ""
            protocol = "MetaWeblog"
            url_description = _("XML-RPC URL:")
        elif blog_type == "blogger.com":
            url = "http://code.blogger.com/"
            url_ending = ""
            protocol = "atomBloggerAPI"
            url_description = _("ATOM-based")
        elif blog_type == "advogato.org":
            url = "http://www.advogato.org/XMLRPC"
            url_ending = ""
            protocol = "advogato"
            url_description = _("XML-RPC URL:")
            lookup = False
        elif (blog_type == "livejournal.com"):
            url = "http://www.livejournal.com/interface/xmlrpc"
            url_ending = ""
            protocol = "livejournal"
            url_description = _("XML-RPC URL:")
            lookup = False
        else:
            url = None
            url_ending = ""
            protocol = None
            url_description = None
            lookup = False
            hig_alert.reportError(_("Unknown blog type"), _("The detected blog type is not among the list of supported blogs"))

        if url != None:
            self.urlEntry.set_sensitive(False)
            self.urlLabel.set_sensitive(False)
            client.set_string(gconf_prefix + "/xmlrpc_url", url)
        else:
            self.urlEntry.set_sensitive(True)
            self.urlLabel.set_sensitive(True)

        if protocol != None:
            self.blogProtocolMenu.set_sensitive(False)
            self.blogProtocolLabel.set_sensitive(False)
            print 'Setting: ' + gconf_prefix + '/blog_protocol' + ' to ' + protocol
            client.set_string(gconf_prefix + "/blog_protocol", protocol)
        else:
            self.blogProtocolMenu.set_sensitive(True)
            self.blogProtocolLabel.set_sensitive(True)

        if url_description:
            self.urlLabel.set_text(url_description)

        client.set_string(gconf_prefix + "/url_ending", url_ending)

        self.lookupButton.set_sensitive(lookup)
        self.blogMenu.set_sensitive(lookup)
        self.blogLabel.set_sensitive(lookup)
Ejemplo n.º 13
0
        server = proxy_transport.get_server(url);

        try:
          cookie = server.authenticate(username, password)
        except xmlrpclib.Fault, e:
          if (server.user.exists (username) == 0):
            hig_alert.reportError(_("Could not post Blog entry"), _("Your username is invalid. Please double-check the preferences."))
            return FALSE
          else:
            hig_alert.reportError(_("Could not post Blog entry"), _("Your username or password is invalid. Please double-check the preferences."))
            return FALSE

        success = TRUE

        try:
          server.diary.set(cookie, -1, entry)

        except xmlrpclib.Fault, e:
          hig_alert.handleBloggerAPIFault(e, _("Could not post blog entry"), username, blog_id, url)
          success = FALSE
        except xmlrpclib.ProtocolError, e:
          hig_alert.reportError(_("Could not post Blog entry"), _('URL \'%s\' does not seem to be a valid bloggerAPI XML-RPC server. Web server reported: %s.') % (url, hig_alert.italic(e.errmsg)))
          success = FALSE

        print ("Success is....")
        print (success)

        return success

blog = Blog()