Merge lp:~ken-vandine/gwibber-service-sohu/fix_logger into lp:gwibber-service-sohu

Proposed by Ken VanDine on 2012-03-19
Status: Needs review
Proposed branch: lp:~ken-vandine/gwibber-service-sohu/fix_logger
Merge into: lp:gwibber-service-sohu
Diff against target: 228 lines (+47/-35)
3 files modified
__init__.py (+10/-7)
gtk/sohu/__init__.py (+34/-25)
setup.py (+3/-3)
To merge this branch: bzr merge lp:~ken-vandine/gwibber-service-sohu/fix_logger
Reviewer Review Type Date Requested Status
An Yang 2012-03-19 Approve on 2012-03-23
Review via email: mp+98248@code.launchpad.net

Description of the change

* ported to logger module from gwibber 3.3.90
* ported accounts dialog to gtk3

To post a comment you must log in.
18. By Ken VanDine on 2012-03-19

install icons in the gwibber hicolor theme dir

19. By Ken VanDine on 2012-03-19

Ported to gtk3

An Yang (euroford) :
review: Approve
20. By Ken VanDine on 2012-04-18

remove import of gnomekeyring

21. By Ken VanDine on 2012-04-19

Don't crash on unicode characters in a username

22. By Ken VanDine on 2012-04-24

fixed missing import

Unmerged revisions

22. By Ken VanDine on 2012-04-24

fixed missing import

21. By Ken VanDine on 2012-04-19

Don't crash on unicode characters in a username

20. By Ken VanDine on 2012-04-18

remove import of gnomekeyring

19. By Ken VanDine on 2012-03-19

Ported to gtk3

18. By Ken VanDine on 2012-03-19

install icons in the gwibber hicolor theme dir

17. By Ken VanDine on 2012-03-19

ported to logger module from gwibber 3.3.90

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '__init__.py'
2--- __init__.py 2011-04-29 10:54:30 +0000
3+++ __init__.py 2012-04-24 18:35:29 +0000
4@@ -1,12 +1,15 @@
5 from gwibber.microblog import network, util
6 from htmlentitydefs import name2codepoint
7 import re
8-import gnomekeyring
9 from oauth import oauth
10-from gwibber.microblog.util import log, resources
11+from gwibber.microblog.util import resources
12+
13 from gettext import lgettext as _
14 import sohu.utils
15-log.logger.name = "Sohu"
16+
17+import logging
18+logger = logging.getLogger("Sohu")
19+logger.debug("Initializing.")
20
21 PROTOCOL_INFO = {
22 "name": "Sohu",
23@@ -107,7 +110,7 @@
24 m["images"] = images
25 m["type"] = "photo"
26 except:
27- log.logger.error("%s failure - %s", PROTOCOL_INFO["name"], data)
28+ logger.error("%s failure - %s", PROTOCOL_INFO["name"], data)
29 return {}
30
31 return m
32@@ -219,7 +222,7 @@
33 if isinstance(data, dict) and data.get("errors", 0):
34 if "authenticate" in data["errors"][0]["message"]:
35 logstr = """%s: %s - %s""" % (PROTOCOL_INFO["name"], _("Authentication failed"), error["message"])
36- log.logger.error("%s", logstr)
37+ logger.error("%s", logstr)
38 return [{"error": {"type": "auth", "account": self.account, "message": data["errors"][0]["message"]}}]
39 else:
40 for error in data["errors"]:
41@@ -228,11 +231,11 @@
42 elif isinstance(data, dict) and data.get("error", 0):
43 if "Incorrect signature" in data["error"]:
44 logstr = """%s: %s - %s""" % (PROTOCOL_INFO["name"], _("Request failed"), data["error"])
45- log.logger.error("%s", logstr)
46+ logger.error("%s", logstr)
47 return [{"error": {"type": "auth", "account": self.account, "message": data["error"]}}]
48 elif isinstance(data, str):
49 logstr = """%s: %s - %s""" % (PROTOCOL_INFO["name"], _("Request failed"), data)
50- log.logger.error("%s", logstr)
51+ logger.error("%s", logstr)
52 return [{"error": {"type": "request", "account": self.account, "message": data}}]
53
54 if parse == "list":
55
56=== modified file 'gtk/sohu/__init__.py'
57--- gtk/sohu/__init__.py 2011-04-15 06:31:07 +0000
58+++ gtk/sohu/__init__.py 2012-04-24 18:35:29 +0000
59@@ -1,9 +1,11 @@
60-import gtk, pango, webkit, gnomekeyring
61+from gi.repository import Gdk, Gtk, WebKit, Pango
62+from gi.repository.Gtk import Builder
63+
64 import urllib, urllib2, json, urlparse, uuid
65 from oauth import oauth
66
67-from gtk import Builder
68 from gwibber.microblog.util import resources
69+from gwibber.microblog.util.keyring import get_from_keyring
70 import gettext
71 from gettext import gettext as _
72 if hasattr(gettext, 'bind_textdomain_codeset'):
73@@ -11,33 +13,33 @@
74 gettext.textdomain('gwibber-service-sohu')
75 import sohu.utils
76
77-gtk.gdk.threads_init()
78+Gdk.threads_init()
79
80 sigmeth = oauth.OAuthSignatureMethod_HMAC_SHA1()
81
82-class AccountWidget(gtk.VBox):
83+class AccountWidget(Gtk.VBox):
84 """AccountWidget: A widget that provides a user interface for configuring sohu accounts in Gwibber
85 """
86
87 def __init__(self, account=None, dialog=None):
88 """Creates the account pane for configuring Sohu accounts"""
89- gtk.VBox.__init__( self, False, 20 )
90- self.ui = gtk.Builder()
91+ Gtk.VBox.__init__( self, False, 20 )
92+ self.ui = Gtk.Builder()
93 self.ui.set_translation_domain ("gwibber")
94 self.ui.add_from_file (resources.get_ui_asset("gwibber-accounts-sohu.ui"))
95 self.ui.connect_signals(self)
96 self.vbox_settings = self.ui.get_object("vbox_settings")
97- self.pack_start(self.vbox_settings, False, False)
98+ self.pack_start(self.vbox_settings, False, False, 0)
99 self.show_all()
100
101 self.account = account or {}
102 self.dialog = dialog
103- has_secret_key = True
104+ self.window = dialog.dialog
105+ has_access_token = False
106+
107+ has_secret_key = False
108 if self.account.has_key("id"):
109- try:
110- value = gnomekeyring.find_items_sync(gnomekeyring.ITEM_GENERIC_SECRET, {"id": str("%s/%s" % (self.account["id"], "secret_token"))})[0].secret
111- except gnomekeyring.NoMatchError:
112- has_secret_key = False
113+ has_secret_key = get_from_keyring(self.account['id'], 'secret_token') is not None
114
115 try:
116 if self.account.has_key("access_token") and self.account.has_key("secret_token") and self.account.has_key("username") and has_secret_key and not self.dialog.condition:
117@@ -57,8 +59,9 @@
118 def on_sohu_auth_clicked(self, widget, data=None):
119 self.winsize = self.window.get_size()
120
121- web = webkit.WebView()
122+ web = WebKit.WebView()
123 web.get_settings().set_property("enable-plugins", False)
124+ web.get_settings().set_property("enable-developer-extras", False)
125 web.load_html_string(_("<p>Please wait...</p>"), "file:///")
126
127 self.consumer = oauth.OAuthConsumer(*sohu.utils.get_sohu_keys())
128@@ -79,15 +82,17 @@
129 web.set_size_request(550, 400)
130 web.connect("title-changed", self.on_sohu_auth_title_change)
131
132- self.scroll = gtk.ScrolledWindow()
133+ self.scroll = Gtk.ScrolledWindow()
134 self.scroll.add(web)
135+ self.scroll.set_size_request(550, 400)
136
137 self.pack_start(self.scroll, True, True, 0)
138 self.show_all()
139+ self.dialog.infobar.hide()
140
141 self.ui.get_object("vbox1").hide()
142 self.ui.get_object("vbox_advanced").hide()
143- self.dialog.infobar.set_message_type(gtk.MESSAGE_INFO)
144+ self.dialog.infobar.set_message_type(Gtk.MessageType.INFO)
145
146 def on_sohu_auth_title_change(self, web=None, title=None, data=None):
147 saved = False
148@@ -99,12 +104,12 @@
149 self.dialog.infobar_content_area.show()
150 self.dialog.infobar.show()
151
152- message_label = gtk.Label(_("Verifying"))
153+ message_label = Gtk.Label(_("Verifying"))
154 message_label.set_use_markup(True)
155- message_label.set_ellipsize(pango.ELLIPSIZE_END)
156+ message_label.set_ellipsize(Pango.EllipsizeMode.END)
157 self.dialog.infobar_content_area.add(message_label)
158 self.dialog.infobar.show_all()
159- self.scroll.hide()
160+ self.scroll.destroy()
161 url = web.get_main_frame().get_uri()
162 data = urlparse.parse_qs(url.split("?", 1)[1])
163
164@@ -137,7 +142,7 @@
165
166 account_data = json.loads(urllib2.urlopen(apireq.to_url()).read())
167
168- self.account["username"] = account_data["screen_name"]
169+ self.account["username"] = account_data["screen_name"].encode("utf-8")
170 self.account["user_id"] = account_data["id"]
171
172 if isinstance(account_data, dict):
173@@ -145,16 +150,16 @@
174 saved = self.dialog.on_edit_account_save()
175 else:
176 print "Failed"
177- self.dialog.infobar.set_message_type(gtk.MESSAGE_ERROR)
178+ self.dialog.infobar.set_message_type(Gtk.MessageType.ERROR)
179 message_label.set_text(_("Authorization failed. Please try again."))
180 else:
181 print "Failed"
182- self.dialog.infobar.set_message_type(gtk.MESSAGE_ERROR)
183+ self.dialog.infobar.set_message_type(Gtk.MessageType.ERROR)
184 message_label.set_text(_("Authorization failed. Please try again."))
185
186 if saved:
187 message_label.set_text(_("Successful"))
188- self.dialog.infobar.set_message_type(gtk.MESSAGE_INFO)
189+ self.dialog.infobar.set_message_type(Gtk.MessageType.INFO)
190 #self.dialog.infobar.hide()
191
192 self.ui.get_object("hbox_sohu_auth").hide()
193@@ -168,11 +173,15 @@
194 self.window.resize(*self.winsize)
195
196 if title.get_title() == "Failure":
197- web.hide()
198- self.dialog.infobar.set_message_type(gtk.MESSAGE_ERROR)
199- message_label.set_text(_("Authorization failed. Please try again."))
200+ self.dialog.infobar.set_message_type(Gtk.MessageType.ERROR)
201+ message_label = Gtk.Label (_("Authorization failed. Please try again."))
202+ message_label.set_use_markup(True)
203+ message_label.set_ellipsize(Pango.EllipsizeMode.END)
204+ self.dialog.infobar_content_area.add(message_label)
205 self.dialog.infobar.show_all()
206
207 self.ui.get_object("vbox1").show()
208 self.ui.get_object("vbox_advanced").show()
209+ self.scroll.destroy()
210 self.window.resize(*self.winsize)
211+ self.dialog.select_account ()
212
213=== modified file 'setup.py'
214--- setup.py 2011-06-06 19:00:34 +0000
215+++ setup.py 2012-04-24 18:35:29 +0000
216@@ -16,9 +16,9 @@
217 ('share/gwibber/plugins/sohu/gtk', glob("gtk/*.*")),
218 ('share/gwibber/plugins/sohu/gtk/sohu', glob("gtk/sohu/*.*")),
219 ('share/gwibber/plugins/sohu/ui', glob("ui/*.*")),
220- ('share/gwibber/plugins/sohu/ui/icons/16x16', glob("ui/icons/16x16/*.*")),
221- ('share/gwibber/plugins/sohu/ui/icons/22x22', glob("ui/icons/22x22/*.*")),
222- ('share/gwibber/plugins/sohu/ui/icons/scalable', glob("ui/icons/scalable/*.*")),
223+ ('share/gwibber/ui/icons/hicolor/16x16/apps', glob("ui/icons/16x16/*.*")),
224+ ('share/gwibber/ui/icons/hicolor/22x22/apps', glob("ui/icons/22x22/*.*")),
225+ ('share/gwibber/ui/icons/hicolor/scalable/apps', glob("ui/icons/scalable/*.*")),
226 ('share/gwibber/plugins/sohu/data', glob("data/*.*")),
227 ],
228 cmdclass = { "build" : build_extra.build_extra,

Subscribers

People subscribed via source and target branches

to all changes: