Merge lp:~apachelogger/ubuntuone-client/kwallet-support into lp:ubuntuone-client

Proposed by Harald Sitter on 2010-07-28
Status: Rejected
Rejected by: Guillermo Gonzalez on 2010-08-06
Proposed branch: lp:~apachelogger/ubuntuone-client/kwallet-support
Merge into: lp:ubuntuone-client
Diff against target: 71 lines (+46/-1)
1 file modified
ubuntuone/syncdaemon/main.py (+46/-1)
To merge this branch: bzr merge lp:~apachelogger/ubuntuone-client/kwallet-support
Reviewer Review Type Date Requested Status
Guillermo Gonzalez Disapprove on 2010-08-06
Rodrigo Moya (community) Disapprove on 2010-08-06
Tim Cole (community) 2010-07-28 Approve on 2010-08-02
Review via email: mp+31138@code.launchpad.net

Description of the change

Enable syncdaemon to get tokens from kwallet if present and accessible (falls back to gnome-keyring if that is also present).

Covered cases:
KDE with ubuntuone-kde: kwallet -> success -> hooray
KDE without ubuntuone-kde: kwallet -> fail -> try gnomekeyring -> success -> hooray
GNOME: gnomekeyring -> success -> hooray

(ubuntuone-kde is not supported at this time so this case ought not to be covered, OTOH it might be neat to support it nether the less ... if you wish to do so, we can arange that with cilling the external process call and just try to import kwallet regardless of the environment.

To post a comment you must log in.
Tim Cole (tcole) :
review: Approve
Rodrigo Moya (rodrigo-moya) wrote :

We are removing the use of the gnome keyring since we are moving to use ubuntu-sso, which returns the credentials via DBus, so you'd better add kwallet support there, not here

review: Disapprove
Guillermo Gonzalez (verterok) wrote :

Hi,

Thanks a lot for putting this together!

Sadly, I must vote Disapprove.

The main reason is that ubuntu-sso will support returning the tokens via dbus, so the gnomekeyring dependency in syncdaemon will be removed as soon ubuntu-sso is ready.

review: Disapprove

Unmerged revisions

602. By Harald Sitter on 2010-07-28

actually ubuntuone-kde uses "ubuntuone" as folder since the realm can be either one.ubuntu.com or ubuntuone.com

601. By Harald Sitter on 2010-07-28

Add as non-intrusive kwallet support as possible to the syncdaemon

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntuone/syncdaemon/main.py'
2--- ubuntuone/syncdaemon/main.py 2010-07-16 12:46:42 +0000
3+++ ubuntuone/syncdaemon/main.py 2010-07-28 09:47:43 +0000
4@@ -4,6 +4,7 @@
5 # John Lenton <john.lenton@canonical.com>
6 #
7 # Copyright 2009 Canonical Ltd.
8+# Copyright 2010 Harald Sitter <apachelogger@ubuntu.com>
9 #
10 # This program is free software: you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License version 3, as published
12@@ -19,7 +20,6 @@
13 """ SyncDaemon Main"""
14 import dbus
15 from dbus.mainloop.glib import DBusGMainLoop
16-import gnomekeyring
17 import logging
18 import os
19 import sys
20@@ -305,6 +305,51 @@
21
22 If no token is available in the keyring, `NoAccessToken` is raised.
23 """
24+ import subprocess
25+ try:
26+ # kcheckrunning returns 0 iff KDE is running
27+ k = subprocess.Popen(["kcheckrunning"]).wait()
28+ except OSError:
29+ # kcheckrunning not found -> no KDE session
30+ k = 1
31+
32+ if k == 0:
33+ try:
34+ from PyKDE4.kdeui import KWallet
35+ from PyQt4.QtCore import QCoreApplication
36+
37+ # KWallet uses a QEventLoop. This only works if a QApp is present.
38+ # We only can have one instance - ever!
39+ if QCoreApplication.instance() == None:
40+ a = QCoreApplication([""])
41+ a.setApplicationName("Ubuntu One Sync Daemon")
42+
43+ wallet = KWallet.Wallet.openWallet(KWallet.Wallet.LocalWallet(), 0, KWallet.Wallet.Synchronous)
44+ if wallet.isOpen():
45+ if wallet.setFolder("ubuntuone"):
46+ fail, token = wallet.readPassword(self.consumer.key)
47+ if not fail and not token.isEmpty(): # For some reason fail is not really fail?
48+ return oauth.OAuthToken.from_string(str(token))
49+ else:
50+ raise NoAccessToken("No access token found.")
51+ else:
52+ raise NoAccessToken("Could not access token folder.")
53+ else:
54+ raise NoAccessToken("Could not access wallet.")
55+ # If PyKDE is missing or KWallet did not contain a token, try to use gnomekeyring:
56+ except ImportError as error:
57+ try:
58+ import gnomekeyring
59+ except ImportError:
60+ raise error
61+ except NoAccessToken as error:
62+ try:
63+ import gnomekeyring
64+ except ImportError:
65+ raise error
66+ else: # If KDE is available we fall back to gnomekeyring in appropriate excepts.
67+ import gnomekeyring
68+
69 try:
70 items = gnomekeyring.find_items_sync(
71 gnomekeyring.ITEM_GENERIC_SECRET,

Subscribers

People subscribed via source and target branches