Merge lp://qastaging/~sil/desktopcouch/pair-with-u1 into lp://qastaging/desktopcouch

Proposed by Stuart Langridge
Status: Merged
Approved by: Elliot Murphy
Approved revision: 47
Merged at revision: not available
Proposed branch: lp://qastaging/~sil/desktopcouch/pair-with-u1
Merge into: lp://qastaging/desktopcouch
Diff against target: None lines
To merge this branch: bzr merge lp://qastaging/~sil/desktopcouch/pair-with-u1
Reviewer Review Type Date Requested Status
Elliot Murphy (community) Approve
Chad Miller (community) Approve
Review via email: mp+10612@code.qastaging.launchpad.net

Commit message

Add selectable "Ubuntu One" option in pairing application if you already have the Ubuntu One OAuth keys.

To post a comment you must log in.
Revision history for this message
Stuart Langridge (sil) wrote :

Add selectable "Ubuntu One" option in pairing application if you already have the Ubuntu One OAuth keys.

46. By Stuart Langridge

be a little more robust with parsing

47. By Stuart Langridge

Properly throw an error if writing to desktopcouch fails

Revision history for this message
Chad Miller (cmiller) wrote :

Very nice!

review: Approve
Revision history for this message
Elliot Murphy (statik) :
review: Approve
Revision history for this message
Chad Miller (cmiller) wrote :

On 08/24/2009 03:19 PM, Chad Miller wrote:
> Review: Approve
> Very nice!

Er, should that be "record_id = d.put(r)" or "= put_record(r)" ? - chad

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/desktopcouch-pair'
2--- bin/desktopcouch-pair 2009-07-27 18:16:52 +0000
3+++ bin/desktopcouch-pair 2009-08-24 18:24:06 +0000
4@@ -67,6 +67,7 @@
5
6 discovery_tool_version = "1"
7
8+CLOUD_SERVICES = {}
9
10 def generate_secret(length=7):
11 """Create a secret that is easy to write and read. We hate ambiguity and
12@@ -443,8 +444,30 @@
13 already-listening tool instance. This sets up a "Bob" in the
14 module's story."""
15
16- # positions: host id, description, pair host, pair port
17- listening_hosts = gtk.TreeStore(str, str, str, int)
18+ # positions: host id, description, pair host, pair port, is_cloud
19+ listening_hosts = gtk.TreeStore(str, str, str, int, bool)
20+
21+ # If there is an Ubuntu One key in the keyring, add Ubuntu One
22+ # as an item to be paired with
23+ import gnomekeyring
24+ try:
25+ matches = gnomekeyring.find_items_sync(
26+ gnomekeyring.ITEM_GENERIC_SECRET,
27+ {'ubuntuone-realm': "https://ubuntuone.com",
28+ 'oauth-consumer-key': "ubuntuone"})
29+ except gnomekeyring.NoMatchError:
30+ matches = None
31+ if matches:
32+ # parse "a=b&c=d" to {"a":"b","c":"d"}
33+ oauth_data = dict([x.split("=") for x in matches[0].secret.split("&")])
34+ oauth_data.update({
35+ "database_name_prefix": "u1accountname/",
36+ "consumer_key": "ubuntuone",
37+ "consumer_secret": "",
38+ })
39+ listening_hosts.append(None, ["Ubuntu One", "The Ubuntu One cloud service",
40+ "ubuntuone.com", 5984, True])
41+ CLOUD_SERVICES["Ubuntu One"] = oauth_data
42
43 self.inviting = None # pylint: disable-msg=W0201
44
45@@ -473,6 +496,12 @@
46 service = model.get_value(iter, 0)
47 hostname = model.get_value(iter, 2)
48 port = model.get_value(iter, 3)
49+ is_cloud = model.get_value(iter, 4)
50+
51+ if is_cloud:
52+ # Pairing with a cloud service, which doesn't do key exchange
53+ pair_with_cloud_service(service, hostname, port)
54+ return
55
56 self.logging.info("connecting to %s:%s tcp to invite",
57 hostname, port)
58@@ -497,7 +526,7 @@
59 """When a zeroconf service appears, this adds it to the
60 listing of choices."""
61
62- listening_hosts.append(None, [name, description, host, port])
63+ listening_hosts.append(None, [name, description, host, port, False, None])
64
65 def remove_service_from_list(name):
66 """When a zeroconf service disappears, this finds it in the
67@@ -632,6 +661,48 @@
68 lambda *args: pick_or_listen.window.destroy())
69 success_note.show()
70
71+def pair_with_cloud_service(name, hostname, port):
72+ """Write a paired server record for the selected cloud service."""
73+ from desktopcouch.records.server import CouchDatabase
74+ from desktopcouch.records.record import Record
75+ import uuid
76+
77+ # Create a paired server record
78+ service_data = CLOUD_SERVICES[name]
79+ data = {
80+ "record_type": "http://www.freedesktop.org/wiki/Specifications/desktopcouch/paired_server",
81+ "pairing_identifier": str(uuid.uuid4()),
82+ "server": "%s:%s" % (hostname, port),
83+ "oauth": {
84+ "consumer_key": service_data["consumer_key"],
85+ "consumer_secret": service_data["consumer_secret"],
86+ "token": service_data["oauth_token"],
87+ "token_secret": service_data["oauth_token_secret"],
88+ },
89+ "database_name_prefix": service_data["database_name_prefix"],
90+ "pull_from_server": True
91+ }
92+ try:
93+ d = CouchDatabase("management", create=True)
94+ r = Record(data)
95+ record_id = d.put(r)
96+ except:
97+ print "couch fail"
98+
99+ success_note = gtk.Dialog(title=_("Paired with %s") % name,
100+ parent=pick_or_listen.window,
101+ flags=gtk.DIALOG_DESTROY_WITH_PARENT,
102+ buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,))
103+ text = gtk.Label(
104+ _("Successfully paired with %s") % name)
105+ text.show()
106+ content_box = success_note.get_content_area()
107+ content_box.pack_start(text, True, True, 20)
108+ success_note.connect("close",
109+ lambda *args: pick_or_listen.window.destroy())
110+ success_note.connect("response",
111+ lambda *args: pick_or_listen.window.destroy())
112+ success_note.show()
113
114 def main(args):
115 """Start execution."""

Subscribers

People subscribed via source and target branches