Merge lp:~robru/gwibber/account-protocol into lp:~barry/gwibber/py3

Proposed by Robert Bruce Park
Status: Merged
Merged at revision: 1417
Proposed branch: lp:~robru/gwibber/account-protocol
Merge into: lp:~barry/gwibber/py3
Diff against target: 94 lines (+20/-7)
3 files modified
gwibber/gwibber/main.py (+1/-2)
gwibber/gwibber/tests/test_account.py (+4/-3)
gwibber/gwibber/utils/account.py (+15/-2)
To merge this branch: bzr merge lp:~robru/gwibber/account-protocol
Reviewer Review Type Date Requested Status
Barry Warsaw Pending
Review via email: mp+123154@code.launchpad.net

Description of the change

This ended up being simpler than I'd anticipated ;-)

I ended up dropping the 'protocol' key from the Account dict because I didn't think it would actually be needed any longer. I mean, I thought it was only going to be needed for discovering the plugin anyway, but now that we're storing a reference to the plugin instance directly, it was mostly redundant.

Plus, we need to 'upgrade' the dict keys to instance attributes one by one as we slowly begin to understand them, I think, so this is a small first step in that direction.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'gwibber/gwibber/main.py'
2--- gwibber/gwibber/main.py 2012-08-30 23:20:49 +0000
3+++ gwibber/gwibber/main.py 2012-09-06 19:30:31 +0000
4@@ -28,7 +28,6 @@
5
6 from dbus.mainloop.glib import DBusGMainLoop
7 from gi.repository import Gio, GLib
8-from xdg import BaseDirectory
9
10 from gwibber.service.connection import ConnectionMonitor
11 from gwibber.service.messages import MessageManager
12@@ -45,7 +44,7 @@
13 log = None
14 services = []
15 DEFAULT_SQLITE_FILE = os.path.join(
16- BaseDirectory.xdg_config_home, 'gwibber', 'gwibber.sqlite')
17+ GLib.get_user_config_dir(), 'gwibber', 'gwibber.sqlite')
18
19
20 class DispatcherStub:
21
22=== modified file 'gwibber/gwibber/tests/test_account.py'
23--- gwibber/gwibber/tests/test_account.py 2012-09-04 20:51:19 +0000
24+++ gwibber/gwibber/tests/test_account.py 2012-09-06 19:30:31 +0000
25@@ -22,6 +22,7 @@
26 import unittest
27
28 from gwibber.utils.account import Account
29+from gwibber.protocols.flickr import Flickr
30
31 try:
32 # Python 3.3
33@@ -56,7 +57,7 @@
34 (True, 'key', 'value'),
35 ],
36 'id': 'fake_id',
37- 'get_provider_name.return_value': 'fake_provider',
38+ 'get_provider_name.return_value': 'flickr',
39 }),
40 'get_service.return_value': mock.Mock(**{
41 'get_name.return_value': 'fake_service',
42@@ -83,8 +84,8 @@
43 self.assertEqual(self.account['id'], 'fake_id/fake_service')
44
45 def test_account_service(self):
46- # The 'protocol' key of the account gets the service provider name.
47- self.assertEqual(self.account['protocol'], 'fake_provider')
48+ # The protocol attribute refers directly to the protocol used.
49+ self.assertIs(type(self.account.protocol), Flickr)
50
51 def test_on_account_changed(self):
52 # Account.on_account_changed() gets called during the Account
53
54=== modified file 'gwibber/gwibber/utils/account.py'
55--- gwibber/gwibber/utils/account.py 2012-09-06 16:24:33 +0000
56+++ gwibber/gwibber/utils/account.py 2012-09-06 19:30:31 +0000
57@@ -21,8 +21,16 @@
58
59 from threading import Lock
60
61+# TODO later on we'll get the global ProtocolManager instance
62+# from the Dispatcher when it exists, but for now we need to import it
63+# here
64+from gwibber.utils.protocol import ProtocolManager
65+manager = ProtocolManager()
66
67 class Account(dict):
68+ """A thin wrapper around libaccounts API."""
69+ protocol = None
70+
71 def __init__(self, account_service):
72 self.account_service = account_service
73 auth_data = account_service.get_auth_data()
74@@ -32,14 +40,19 @@
75 mechanism = auth_data.get_mechanism(),
76 parameters = auth_data.get_parameters(),
77 )
78+
79 account = account_service.get_account()
80 self.global_id = account.id
81 service_name = account_service.get_service().get_name()
82 self['id'] = '{}/{}'.format(self.global_id, service_name)
83- # The provider name in libaccounts should match the name of our plugin.
84- self['protocol'] = account.get_provider_name()
85+ # The provider in libaccounts should match the name of our protocol.
86+ protocol = manager.protocols.get(account.get_provider_name())
87+ if protocol is not None:
88+ self.protocol = protocol(self)
89+
90 account_service.connect('changed', self.on_account_changed, account)
91 self.on_account_changed(account_service, account)
92+
93 # This is used to prevent multiple simultaneous login attempts.
94 self.login_lock = Lock()
95

Subscribers

People subscribed via source and target branches