Merge lp:~gabor-karsay/awn-extras/various-fixes into lp:awn-extras

Proposed by Gabor Karsay
Status: Merged
Merged at revision: 1395
Proposed branch: lp:~gabor-karsay/awn-extras/various-fixes
Merge into: lp:awn-extras
Diff against target: 292 lines (+67/-29)
2 files modified
applets/maintained/mail/mail.py (+30/-24)
shared/python/awnlib.py (+37/-5)
To merge this branch: bzr merge lp:~gabor-karsay/awn-extras/various-fixes
Reviewer Review Type Date Requested Status
onox (community) Approve
Review via email: mp+35450@code.launchpad.net

Description of the change

onox, you have more experience in python, could you please have a look at this method before I add it to awnlib.py? Is it okay for you, e.g. description-wise? As you'll see, it tries to unlock the gnome keyring, with a little workaround though.

It fixes bug #581075, probably bug #549246. I don't know why, but it also fixes bug #610088 (the Gmail part).

btw, how do you decide which bugs are milestones?

To post a comment you must log in.
Revision history for this message
Alberto Aldegheri (albyrock87) wrote :

Forgive me but I don't understand one thing in unlock() method:

- line 43: if "info.get_is_locked()" is False, it jumps to line 59 and returns <<True>>
- line 57: if "info.get_is_locked()" is False, it returns <<False>>

Why?

Revision history for this message
Gabor Karsay (gabor-karsay) wrote :

You are right, that is a mistake. But in a test it works as it should, so I guess that the lock state is not updated and it uses the old one, updating soon.

1415. By Gabor Karsay

Fix logic mistake, thanks alberto

Revision history for this message
onox (onox) wrote :

Gabor, it seems the linked bug reports on this page are different from those in your description. Could you fix this? Please try to avoid reusing some branch for different things. (It's good, however, that you use branches, allows people to review the code :)) Furthermore, about those bugs you described, set them to "Confirmed" once you can reproduce them. Their status still seems to be "New". Use "In Progress" if you're working on them.

About the milestones: some people set bugs to milestone 0.4.2 if the bug occurs in a previous version and will be fixed in 0.4.2. Personally I use 0.4.2 whenever the fix ends up in 0.4.2, this including bugs that were introduced in between 0.4.0 and 0.4.2 (0.4.1 / trunk)

About the code: I haven't tested it (because I don't (want) / can't use the mail applet) so I don't know whether the changes are functional correct. One thing you could do, however, is change def unlock to:

if not info.get_is_locked():
    return True

# here the indented code

return not info.get_is_locked()

This way, the most important piece of code of the function is 1 indention less. One could argue it's a little big more readable.
Oh, and you could replace the url to "launchpad bug #432882"

Revision history for this message
onox (onox) wrote :

And make sure the code is PEP8 compliant.

On Tue, Sep 14, 2010 at 10:47 PM, onox <email address hidden> wrote:

> Gabor, it seems the linked bug reports on this page are different from
> those in your description. Could you fix this? Please try to avoid reusing
> some branch for different things. (It's good, however, that you use
> branches, allows people to review the code :)) Furthermore, about those bugs
> you described, set them to "Confirmed" once you can reproduce them. Their
> status still seems to be "New". Use "In Progress" if you're working on them.
>
> About the milestones: some people set bugs to milestone 0.4.2 if the bug
> occurs in a previous version and will be fixed in 0.4.2. Personally I use
> 0.4.2 whenever the fix ends up in 0.4.2, this including bugs that were
> introduced in between 0.4.0 and 0.4.2 (0.4.1 / trunk)
>
> About the code: I haven't tested it (because I don't (want) / can't use the
> mail applet) so I don't know whether the changes are functional correct. One
> thing you could do, however, is change def unlock to:
>
> if not info.get_is_locked():
> return True
>
> # here the indented code
>
> return not info.get_is_locked()
>
> This way, the most important piece of code of the function is 1 indention
> less. One could argue it's a little big more readable.
> Oh, and you could replace the url to "launchpad bug #432882"
> --
>
> https://code.launchpad.net/~gabor-karsay/awn-extras/various-fixes/+merge/35450
> You are requested to review the proposed merge of
> lp:~gabor-karsay/awn-extras/various-fixes into lp:awn-extras.
>

Revision history for this message
Alberto Aldegheri (albyrock87) wrote :
Revision history for this message
onox (onox) wrote :

http://wiki.awn-project.org/Applets:DevelopmentGuidelines#Python_PEP_8

On Tue, Sep 14, 2010 at 11:08 PM, Alberto
<<email address hidden><albyrock87%<email address hidden>>
> wrote:

> Onox: can this help? http://pypi.python.org/pypi/pep8
> --
>
> https://code.launchpad.net/~gabor-karsay/awn-extras/various-fixes/+merge/35450
> You are requested to review the proposed merge of
> lp:~gabor-karsay/awn-extras/various-fixes into lp:awn-extras.
>

Revision history for this message
onox (onox) wrote :

@Gabor: see launchpad bug #432957. Seems related to this branch also.

On Tue, Sep 14, 2010 at 11:28 PM, onox <email address hidden> wrote:

> http://wiki.awn-project.org/Applets:DevelopmentGuidelines#Python_PEP_8
>
> On Tue, Sep 14, 2010 at 11:08 PM, Alberto
> <<email address hidden> <albyrock87%<email address hidden>><
> albyrock87%<email address hidden> <albyrock87%<email address hidden>>>
> > wrote:
>
> > Onox: can this help? http://pypi.python.org/pypi/pep8
> > --
> >
> >
> https://code.launchpad.net/~gabor-karsay/awn-extras/various-fixes/+merge/35450
> > You are requested to review the proposed merge of
> > lp:~gabor-karsay/awn-extras/various-fixes into lp:awn-extras.
> >
>
> --
>
> https://code.launchpad.net/~gabor-karsay/awn-extras/various-fixes/+merge/35450
> You are requested to review the proposed merge of
> lp:~gabor-karsay/awn-extras/various-fixes into lp:awn-extras.
>

1416. By Gabor Karsay

Change as reviewed by onox, make awnlib.py PEP 8 compliant

1417. By Gabor Karsay

Make mail.py PEP 8 compliant

Revision history for this message
Gabor Karsay (gabor-karsay) wrote :

Thanks Alberto, thanks onox, applied all your suggestions. The code is tested and functional. I go ahead and commit it now.

Revision history for this message
onox (onox) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'applets/maintained/mail/mail.py'
2--- applets/maintained/mail/mail.py 2010-09-13 16:49:15 +0000
3+++ applets/maintained/mail/mail.py 2010-09-15 19:43:46 +0000
4@@ -83,7 +83,7 @@
5 """
6 Login. Try to login from saved key, if this does not exist or
7 force is True, show login dialog
8-
9+
10 """
11 self.awn.theme.icon("login")
12
13@@ -107,6 +107,9 @@
14
15 key = self.awn.keyring.from_token(token)
16
17+ if not self.awn.keyring.unlock():
18+ return self.login(True)
19+
20 self.perform_login(key)
21
22 def logout(self):
23@@ -116,9 +119,8 @@
24 self.awn.settings["login-token"] = 0
25
26 def perform_login(self, key):
27-# if key.token == 0:
28-# self.__dialog.login_form(True, "Both username and password must be specified.")
29-# return
30+ if key.token == 0:
31+ return
32
33 try:
34 self.mail = self.back(key) # Login
35@@ -210,11 +212,11 @@
36
37 """
38 states = {
39- "error" : "error",
40- "login" : "login",
41- "read" : "mail-read",
42- "unread": "mail-unread"
43- }
44+ "error": "error",
45+ "login": "login",
46+ "read": "mail-read",
47+ "unread": "mail-unread"}
48+
49 self.awn.theme.set_states(states)
50 theme = self.awn.settings["theme"] if self.awn.settings["theme"] != system_theme_name else None
51 self.awn.theme.theme(theme)
52@@ -280,7 +282,7 @@
53 def email_list(self):
54 """
55 Creates a dialog with mail subjects and 3-4 buttons
56-
57+
58 """
59 self.__remove_current()
60 self.__current_type = "email_list"
61@@ -301,7 +303,7 @@
62
63 # This'll be the "show web interface" button
64 b = gtk.Button()
65- b.set_relief(gtk.RELIEF_NONE) # Found it; that's a relief
66+ b.set_relief(gtk.RELIEF_NONE) # Found it; that's a relief
67 b.set_image(gtk.image_new_from_stock(gtk.STOCK_NETWORK,
68 gtk.ICON_SIZE_BUTTON))
69 b.set_tooltip_text(_("Open Web Mail"))
70@@ -405,7 +407,7 @@
71 def login_form(self, error=False, message=_("Wrong username or password")):
72 """
73 Creates a dialog the login form
74-
75+
76 """
77 self.__remove_current()
78 self.__current_type = "login_form"
79@@ -473,6 +475,7 @@
80 gtk.ICON_SIZE_BUTTON)
81 submit_button = gtk.Button(label=_("Log In"), use_underline=False)
82 submit_button.set_image(image_login)
83+
84 def onsubmit(widget):
85 self.__parent.perform_login(
86 t["callback"](t["widgets"], self.__parent.awn))
87@@ -506,7 +509,7 @@
88
89 def update(self):
90
91- if not self.key.attrs.has_key("username"):
92+ if not "username" in self.key.attrs:
93 raise RuntimeError(_("Could not log in: No username"))
94 return
95
96@@ -528,8 +531,8 @@
97 self.subjects.append(i.title)
98
99 def __cleanGmailSubject(self, n):
100- n = re.sub(r"^[^>]*\\>", "", n) # "sadf\>fdas" -> "fdas"
101- n = re.sub(r"\\[^>]*\\>$", "", n) # "asdf\afdsasdf\>" -> "asdf"
102+ n = re.sub(r"^[^>]*\\>", "", n) # "sadf\>fdas" -> "fdas"
103+ n = re.sub(r"\\[^>]*\\>$", "", n) # "asdf\afdsasdf\>" -> "asdf"
104 n = n.replace("&quot;", "\"")
105 n = n.replace("&amp;", "&")
106 n = n.replace("&nbsp;", "")
107@@ -543,7 +546,7 @@
108 def __cleanMsg(self, n):
109 n = re.sub("\n\s*\n", "\n", n)
110 n = re.sub("&[#x(0x)]?\w*;", " ", n)
111- n = re.sub("\<[^\<\>]*?\>", "", n) # "<h>asdf<a></h>" -> "asdf"
112+ n = re.sub("\<[^\<\>]*?\>", "", n) # "<h>asdf<a></h>" -> "asdf"
113
114 f = False
115 h = []
116@@ -569,8 +572,8 @@
117
118 def update(self):
119
120- if not self.key.attrs.has_key("username") or \
121- not self.key.attrs.has_key("domain"):
122+ if not "username" in self.key.attrs or \
123+ not "domain" in self.key.attrs:
124 raise RuntimeError(_("Could not log in: No username or domain"))
125 return
126
127@@ -593,8 +596,8 @@
128 self.subjects.append(i.title)
129
130 def __cleanGmailSubject(self, n):
131- n = re.sub(r"^[^>]*\\>", "", n) # "sadf\>fdas" -> "fdas"
132- n = re.sub(r"\\[^>]*\\>$", "", n) # "asdf\afdsasdf\>" -> "asdf"
133+ n = re.sub(r"^[^>]*\\>", "", n) # "sadf\>fdas" -> "fdas"
134+ n = re.sub(r"\\[^>]*\\>$", "", n) # "asdf\afdsasdf\>" -> "asdf"
135 n = n.replace("&quot;", "\"")
136 n = n.replace("&amp;", "&")
137 n = n.replace("&nbsp;", "")
138@@ -608,7 +611,7 @@
139 def __cleanMsg(self, n):
140 n = re.sub("\n\s*\n", "\n", n)
141 n = re.sub("&[#x(0x)]?\w*;", " ", n)
142- n = re.sub("\<[^\<\>]*?\>", "", n) # "<h>asdf<a></h>" -> "asdf"
143+ n = re.sub("\<[^\<\>]*?\>", "", n) # "<h>asdf<a></h>" -> "asdf"
144
145 f = False
146 h = []
147@@ -653,6 +656,7 @@
148 except:
149 pass
150 else:
151+
152 class UnixSpool:
153
154 title = _("Unix Spool")
155@@ -699,6 +703,7 @@
156 except:
157 pass
158 else:
159+
160 class POP:
161
162 title = "POP"
163@@ -715,7 +720,7 @@
164 raise RuntimeError(_("Could not log in: ") + str(message))
165
166 else:
167- if not key.attrs.has_key("username"):
168+ if not "username" in key.attrs:
169 raise RuntimeError(_("Could not log in: No username"))
170 self.server.user(key.attrs["username"])
171 try:
172@@ -787,6 +792,7 @@
173 except:
174 pass
175 else:
176+
177 class IMAP:
178
179 title = "IMAP"
180@@ -823,7 +829,7 @@
181 s = self.server.fetch(i, '(BODY[HEADER.FIELDS (SUBJECT)])')[1][0]
182
183 if s is not None:
184- self.subjects.append(s[1][9:].replace("\r\n", "\n").replace("\n", "")) # Don't ask
185+ self.subjects.append(s[1][9:].replace("\r\n", "\n").replace("\n", "")) # Don't ask
186 else:
187 mboxs = [re.search("(\W*) (\W*) (.*)", i).groups()[2] for i in self.server.list()[1]]
188 mboxs = [i for i in mboxs if i not in ("Sent", "Trash") and i[:6] != "[Gmail]"]
189@@ -843,7 +849,7 @@
190 s = self.server.fetch(i, '(BODY[HEADER.FIELDS (SUBJECT)])')[1][0]
191
192 if s is not None:
193- self.subjects.append(s[1][9:].replace("\r\n", "\n").replace("\n", "")) # Don't ask
194+ self.subjects.append(s[1][9:].replace("\r\n", "\n").replace("\n", "")) # Don't ask
195
196 @classmethod
197 def drawLoginWindow(cls, *groups):
198
199=== modified file 'shared/python/awnlib.py'
200--- shared/python/awnlib.py 2010-09-09 21:56:36 +0000
201+++ shared/python/awnlib.py 2010-09-15 19:43:46 +0000
202@@ -568,6 +568,7 @@
203
204 def set_error_icon_and_click_to_restart(self):
205 self.__parent.icon.theme("dialog-error")
206+
207 def crash_applet(widget=None, event=None):
208 gtk.main_quit()
209 self.__parent.connect("clicked", crash_applet)
210@@ -594,7 +595,7 @@
211 error_type = type(error).__name__
212 error = str(error)
213 if traceback is not None:
214- print "\n".join(["-"*80, traceback, "-"*80])
215+ print "\n".join(["-" * 80, traceback, "-" * 80])
216 summary = "%s in %s: %s" % (error_type, self.__parent.meta["name"], error)
217 if self.__parent.meta["version"] == __version__:
218 args["message"] = "Visit Launchpad and report the bug by following these steps:\n\n" \
219@@ -637,6 +638,7 @@
220 copy_summary_button.connect("clicked", clicked_cb, summary)
221
222 if callable(callback):
223+
224 def response_cb(widget, response):
225 if response < 0:
226 callback()
227@@ -782,7 +784,7 @@
228
229 """
230 self.__config_object = None
231-
232+
233 type_client = type(client)
234 if client is None:
235 self.__client = awn.config_get_default(awn.PANEL_ID_DEFAULT)
236@@ -932,6 +934,33 @@
237 k.token = token
238 return k
239
240+ def unlock(self):
241+ """Unlock keyring.
242+
243+ @return: True if keyring is unlocked, False if locked.
244+
245+ """
246+
247+ info = gnomekeyring.get_info_sync(None)
248+ if not info.get_is_locked():
249+ return True
250+
251+ # The straight way would be:
252+ # gnomekeyring.unlock_sync(None, None)
253+ # But this results in a type error, see launchpad bugs #432882.
254+ # We set a dummy key instead and delete it immediately,
255+ # this triggers a user dialog to unlock the keyring.
256+ try:
257+ tmp = gnomekeyring.item_create_sync(None, \
258+ gnomekeyring.ITEM_GENERIC_SECRET, "awn-extras dummy", \
259+ {"dummy_attr": "none"}, "dummy_pwd", True)
260+ except gnomekeyring.CancelledError:
261+ return False
262+ gnomekeyring.item_delete_sync(None, tmp)
263+
264+ info = gnomekeyring.get_info_sync(None)
265+ return not info.get_is_locked()
266+
267 class Key(object):
268
269 def __init__(self, token=0):
270@@ -966,8 +995,11 @@
271 else: # Generic included
272 type = gnomekeyring.ITEM_GENERIC_SECRET
273
274- self.token = gnomekeyring.item_create_sync(None, type, name, \
275- attrs, pwd, True)
276+ try:
277+ self.token = gnomekeyring.item_create_sync(None, type, name, \
278+ attrs, pwd, True)
279+ except gnomekeyring.CancelledError:
280+ self.token = 0
281
282 def delete(self):
283 """Delete the current key. Will also reset the token. Note that
284@@ -1220,7 +1252,7 @@
285 self.__notification.set_timeout(timeout * 1000)
286
287 def show(self):
288- self.__notification.show()
289+ self.__notification.show()
290
291
292 class Meta:

Subscribers

People subscribed via source and target branches