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
=== modified file 'applets/maintained/mail/mail.py'
--- applets/maintained/mail/mail.py 2010-09-13 16:49:15 +0000
+++ applets/maintained/mail/mail.py 2010-09-15 19:43:46 +0000
@@ -83,7 +83,7 @@
83 """83 """
84 Login. Try to login from saved key, if this does not exist or84 Login. Try to login from saved key, if this does not exist or
85 force is True, show login dialog85 force is True, show login dialog
86 86
87 """87 """
88 self.awn.theme.icon("login")88 self.awn.theme.icon("login")
8989
@@ -107,6 +107,9 @@
107107
108 key = self.awn.keyring.from_token(token)108 key = self.awn.keyring.from_token(token)
109109
110 if not self.awn.keyring.unlock():
111 return self.login(True)
112
110 self.perform_login(key)113 self.perform_login(key)
111114
112 def logout(self):115 def logout(self):
@@ -116,9 +119,8 @@
116 self.awn.settings["login-token"] = 0119 self.awn.settings["login-token"] = 0
117120
118 def perform_login(self, key):121 def perform_login(self, key):
119# if key.token == 0:122 if key.token == 0:
120# self.__dialog.login_form(True, "Both username and password must be specified.")123 return
121# return
122124
123 try:125 try:
124 self.mail = self.back(key) # Login126 self.mail = self.back(key) # Login
@@ -210,11 +212,11 @@
210212
211 """213 """
212 states = {214 states = {
213 "error" : "error",215 "error": "error",
214 "login" : "login",216 "login": "login",
215 "read" : "mail-read",217 "read": "mail-read",
216 "unread": "mail-unread"218 "unread": "mail-unread"}
217 }219
218 self.awn.theme.set_states(states)220 self.awn.theme.set_states(states)
219 theme = self.awn.settings["theme"] if self.awn.settings["theme"] != system_theme_name else None221 theme = self.awn.settings["theme"] if self.awn.settings["theme"] != system_theme_name else None
220 self.awn.theme.theme(theme)222 self.awn.theme.theme(theme)
@@ -280,7 +282,7 @@
280 def email_list(self):282 def email_list(self):
281 """283 """
282 Creates a dialog with mail subjects and 3-4 buttons284 Creates a dialog with mail subjects and 3-4 buttons
283 285
284 """286 """
285 self.__remove_current()287 self.__remove_current()
286 self.__current_type = "email_list"288 self.__current_type = "email_list"
@@ -301,7 +303,7 @@
301303
302 # This'll be the "show web interface" button304 # This'll be the "show web interface" button
303 b = gtk.Button()305 b = gtk.Button()
304 b.set_relief(gtk.RELIEF_NONE) # Found it; that's a relief306 b.set_relief(gtk.RELIEF_NONE) # Found it; that's a relief
305 b.set_image(gtk.image_new_from_stock(gtk.STOCK_NETWORK,307 b.set_image(gtk.image_new_from_stock(gtk.STOCK_NETWORK,
306 gtk.ICON_SIZE_BUTTON))308 gtk.ICON_SIZE_BUTTON))
307 b.set_tooltip_text(_("Open Web Mail"))309 b.set_tooltip_text(_("Open Web Mail"))
@@ -405,7 +407,7 @@
405 def login_form(self, error=False, message=_("Wrong username or password")):407 def login_form(self, error=False, message=_("Wrong username or password")):
406 """408 """
407 Creates a dialog the login form409 Creates a dialog the login form
408 410
409 """411 """
410 self.__remove_current()412 self.__remove_current()
411 self.__current_type = "login_form"413 self.__current_type = "login_form"
@@ -473,6 +475,7 @@
473 gtk.ICON_SIZE_BUTTON)475 gtk.ICON_SIZE_BUTTON)
474 submit_button = gtk.Button(label=_("Log In"), use_underline=False)476 submit_button = gtk.Button(label=_("Log In"), use_underline=False)
475 submit_button.set_image(image_login)477 submit_button.set_image(image_login)
478
476 def onsubmit(widget):479 def onsubmit(widget):
477 self.__parent.perform_login(480 self.__parent.perform_login(
478 t["callback"](t["widgets"], self.__parent.awn))481 t["callback"](t["widgets"], self.__parent.awn))
@@ -506,7 +509,7 @@
506509
507 def update(self):510 def update(self):
508511
509 if not self.key.attrs.has_key("username"):512 if not "username" in self.key.attrs:
510 raise RuntimeError(_("Could not log in: No username"))513 raise RuntimeError(_("Could not log in: No username"))
511 return514 return
512515
@@ -528,8 +531,8 @@
528 self.subjects.append(i.title)531 self.subjects.append(i.title)
529532
530 def __cleanGmailSubject(self, n):533 def __cleanGmailSubject(self, n):
531 n = re.sub(r"^[^>]*\\>", "", n) # "sadf\>fdas" -> "fdas"534 n = re.sub(r"^[^>]*\\>", "", n) # "sadf\>fdas" -> "fdas"
532 n = re.sub(r"\\[^>]*\\>$", "", n) # "asdf\afdsasdf\>" -> "asdf"535 n = re.sub(r"\\[^>]*\\>$", "", n) # "asdf\afdsasdf\>" -> "asdf"
533 n = n.replace("&quot;", "\"")536 n = n.replace("&quot;", "\"")
534 n = n.replace("&amp;", "&")537 n = n.replace("&amp;", "&")
535 n = n.replace("&nbsp;", "")538 n = n.replace("&nbsp;", "")
@@ -543,7 +546,7 @@
543 def __cleanMsg(self, n):546 def __cleanMsg(self, n):
544 n = re.sub("\n\s*\n", "\n", n)547 n = re.sub("\n\s*\n", "\n", n)
545 n = re.sub("&[#x(0x)]?\w*;", " ", n)548 n = re.sub("&[#x(0x)]?\w*;", " ", n)
546 n = re.sub("\<[^\<\>]*?\>", "", n) # "<h>asdf<a></h>" -> "asdf"549 n = re.sub("\<[^\<\>]*?\>", "", n) # "<h>asdf<a></h>" -> "asdf"
547550
548 f = False551 f = False
549 h = []552 h = []
@@ -569,8 +572,8 @@
569572
570 def update(self):573 def update(self):
571574
572 if not self.key.attrs.has_key("username") or \575 if not "username" in self.key.attrs or \
573 not self.key.attrs.has_key("domain"):576 not "domain" in self.key.attrs:
574 raise RuntimeError(_("Could not log in: No username or domain"))577 raise RuntimeError(_("Could not log in: No username or domain"))
575 return578 return
576579
@@ -593,8 +596,8 @@
593 self.subjects.append(i.title)596 self.subjects.append(i.title)
594597
595 def __cleanGmailSubject(self, n):598 def __cleanGmailSubject(self, n):
596 n = re.sub(r"^[^>]*\\>", "", n) # "sadf\>fdas" -> "fdas"599 n = re.sub(r"^[^>]*\\>", "", n) # "sadf\>fdas" -> "fdas"
597 n = re.sub(r"\\[^>]*\\>$", "", n) # "asdf\afdsasdf\>" -> "asdf"600 n = re.sub(r"\\[^>]*\\>$", "", n) # "asdf\afdsasdf\>" -> "asdf"
598 n = n.replace("&quot;", "\"")601 n = n.replace("&quot;", "\"")
599 n = n.replace("&amp;", "&")602 n = n.replace("&amp;", "&")
600 n = n.replace("&nbsp;", "")603 n = n.replace("&nbsp;", "")
@@ -608,7 +611,7 @@
608 def __cleanMsg(self, n):611 def __cleanMsg(self, n):
609 n = re.sub("\n\s*\n", "\n", n)612 n = re.sub("\n\s*\n", "\n", n)
610 n = re.sub("&[#x(0x)]?\w*;", " ", n)613 n = re.sub("&[#x(0x)]?\w*;", " ", n)
611 n = re.sub("\<[^\<\>]*?\>", "", n) # "<h>asdf<a></h>" -> "asdf"614 n = re.sub("\<[^\<\>]*?\>", "", n) # "<h>asdf<a></h>" -> "asdf"
612615
613 f = False616 f = False
614 h = []617 h = []
@@ -653,6 +656,7 @@
653 except:656 except:
654 pass657 pass
655 else:658 else:
659
656 class UnixSpool:660 class UnixSpool:
657661
658 title = _("Unix Spool")662 title = _("Unix Spool")
@@ -699,6 +703,7 @@
699 except:703 except:
700 pass704 pass
701 else:705 else:
706
702 class POP:707 class POP:
703708
704 title = "POP"709 title = "POP"
@@ -715,7 +720,7 @@
715 raise RuntimeError(_("Could not log in: ") + str(message))720 raise RuntimeError(_("Could not log in: ") + str(message))
716721
717 else:722 else:
718 if not key.attrs.has_key("username"):723 if not "username" in key.attrs:
719 raise RuntimeError(_("Could not log in: No username"))724 raise RuntimeError(_("Could not log in: No username"))
720 self.server.user(key.attrs["username"])725 self.server.user(key.attrs["username"])
721 try:726 try:
@@ -787,6 +792,7 @@
787 except:792 except:
788 pass793 pass
789 else:794 else:
795
790 class IMAP:796 class IMAP:
791797
792 title = "IMAP"798 title = "IMAP"
@@ -823,7 +829,7 @@
823 s = self.server.fetch(i, '(BODY[HEADER.FIELDS (SUBJECT)])')[1][0]829 s = self.server.fetch(i, '(BODY[HEADER.FIELDS (SUBJECT)])')[1][0]
824830
825 if s is not None:831 if s is not None:
826 self.subjects.append(s[1][9:].replace("\r\n", "\n").replace("\n", "")) # Don't ask832 self.subjects.append(s[1][9:].replace("\r\n", "\n").replace("\n", "")) # Don't ask
827 else:833 else:
828 mboxs = [re.search("(\W*) (\W*) (.*)", i).groups()[2] for i in self.server.list()[1]]834 mboxs = [re.search("(\W*) (\W*) (.*)", i).groups()[2] for i in self.server.list()[1]]
829 mboxs = [i for i in mboxs if i not in ("Sent", "Trash") and i[:6] != "[Gmail]"]835 mboxs = [i for i in mboxs if i not in ("Sent", "Trash") and i[:6] != "[Gmail]"]
@@ -843,7 +849,7 @@
843 s = self.server.fetch(i, '(BODY[HEADER.FIELDS (SUBJECT)])')[1][0]849 s = self.server.fetch(i, '(BODY[HEADER.FIELDS (SUBJECT)])')[1][0]
844850
845 if s is not None:851 if s is not None:
846 self.subjects.append(s[1][9:].replace("\r\n", "\n").replace("\n", "")) # Don't ask852 self.subjects.append(s[1][9:].replace("\r\n", "\n").replace("\n", "")) # Don't ask
847853
848 @classmethod854 @classmethod
849 def drawLoginWindow(cls, *groups):855 def drawLoginWindow(cls, *groups):
850856
=== modified file 'shared/python/awnlib.py'
--- shared/python/awnlib.py 2010-09-09 21:56:36 +0000
+++ shared/python/awnlib.py 2010-09-15 19:43:46 +0000
@@ -568,6 +568,7 @@
568568
569 def set_error_icon_and_click_to_restart(self):569 def set_error_icon_and_click_to_restart(self):
570 self.__parent.icon.theme("dialog-error")570 self.__parent.icon.theme("dialog-error")
571
571 def crash_applet(widget=None, event=None):572 def crash_applet(widget=None, event=None):
572 gtk.main_quit()573 gtk.main_quit()
573 self.__parent.connect("clicked", crash_applet)574 self.__parent.connect("clicked", crash_applet)
@@ -594,7 +595,7 @@
594 error_type = type(error).__name__595 error_type = type(error).__name__
595 error = str(error)596 error = str(error)
596 if traceback is not None:597 if traceback is not None:
597 print "\n".join(["-"*80, traceback, "-"*80])598 print "\n".join(["-" * 80, traceback, "-" * 80])
598 summary = "%s in %s: %s" % (error_type, self.__parent.meta["name"], error)599 summary = "%s in %s: %s" % (error_type, self.__parent.meta["name"], error)
599 if self.__parent.meta["version"] == __version__:600 if self.__parent.meta["version"] == __version__:
600 args["message"] = "Visit Launchpad and report the bug by following these steps:\n\n" \601 args["message"] = "Visit Launchpad and report the bug by following these steps:\n\n" \
@@ -637,6 +638,7 @@
637 copy_summary_button.connect("clicked", clicked_cb, summary)638 copy_summary_button.connect("clicked", clicked_cb, summary)
638639
639 if callable(callback):640 if callable(callback):
641
640 def response_cb(widget, response):642 def response_cb(widget, response):
641 if response < 0:643 if response < 0:
642 callback()644 callback()
@@ -782,7 +784,7 @@
782784
783 """785 """
784 self.__config_object = None786 self.__config_object = None
785 787
786 type_client = type(client)788 type_client = type(client)
787 if client is None:789 if client is None:
788 self.__client = awn.config_get_default(awn.PANEL_ID_DEFAULT)790 self.__client = awn.config_get_default(awn.PANEL_ID_DEFAULT)
@@ -932,6 +934,33 @@
932 k.token = token934 k.token = token
933 return k935 return k
934936
937 def unlock(self):
938 """Unlock keyring.
939
940 @return: True if keyring is unlocked, False if locked.
941
942 """
943
944 info = gnomekeyring.get_info_sync(None)
945 if not info.get_is_locked():
946 return True
947
948 # The straight way would be:
949 # gnomekeyring.unlock_sync(None, None)
950 # But this results in a type error, see launchpad bugs #432882.
951 # We set a dummy key instead and delete it immediately,
952 # this triggers a user dialog to unlock the keyring.
953 try:
954 tmp = gnomekeyring.item_create_sync(None, \
955 gnomekeyring.ITEM_GENERIC_SECRET, "awn-extras dummy", \
956 {"dummy_attr": "none"}, "dummy_pwd", True)
957 except gnomekeyring.CancelledError:
958 return False
959 gnomekeyring.item_delete_sync(None, tmp)
960
961 info = gnomekeyring.get_info_sync(None)
962 return not info.get_is_locked()
963
935 class Key(object):964 class Key(object):
936965
937 def __init__(self, token=0):966 def __init__(self, token=0):
@@ -966,8 +995,11 @@
966 else: # Generic included995 else: # Generic included
967 type = gnomekeyring.ITEM_GENERIC_SECRET996 type = gnomekeyring.ITEM_GENERIC_SECRET
968997
969 self.token = gnomekeyring.item_create_sync(None, type, name, \998 try:
970 attrs, pwd, True)999 self.token = gnomekeyring.item_create_sync(None, type, name, \
1000 attrs, pwd, True)
1001 except gnomekeyring.CancelledError:
1002 self.token = 0
9711003
972 def delete(self):1004 def delete(self):
973 """Delete the current key. Will also reset the token. Note that1005 """Delete the current key. Will also reset the token. Note that
@@ -1220,7 +1252,7 @@
1220 self.__notification.set_timeout(timeout * 1000)1252 self.__notification.set_timeout(timeout * 1000)
12211253
1222 def show(self):1254 def show(self):
1223 self.__notification.show() 1255 self.__notification.show()
12241256
12251257
1226class Meta:1258class Meta:

Subscribers

People subscribed via source and target branches