Merge lp:~jonobacon/ubuntu-accomplishments-daemon/publishonline into lp:ubuntu-accomplishments-daemon

Proposed by Jono Bacon
Status: Merged
Merged at revision: 82
Proposed branch: lp:~jonobacon/ubuntu-accomplishments-daemon/publishonline
Merge into: lp:ubuntu-accomplishments-daemon
Diff against target: 114 lines (+58/-1)
2 files modified
accomplishments/daemon/api.py (+39/-1)
accomplishments/daemon/dbusapi.py (+19/-0)
To merge this branch: bzr merge lp:~jonobacon/ubuntu-accomplishments-daemon/publishonline
Reviewer Review Type Date Requested Status
Ubuntu Accomplishments Daemon Developers Pending
Review via email: mp+111788@code.launchpad.net

Description of the change

This branch adds support to the desktop client for a user to publish their trophies to the web application that will be landing as part of the 0.3 release. Please note, you will also need to have lp:~jonobacon/ubuntu-accomplishments-viewer/publishonline to use this.

This is how it works:

 * The user loads Edit -> Preferences and can click a Publish button to share their trophies online. If they are currently publishing they instead see a Stop Publishing button.

Publishing involves the following:

 * We scan the list of shared directories for ones that are shared with the validation server.
 * For the share that is active, we create a WEBVIEW file in the trophy dir (this is used by the web app to show publishing.
 * We also generate a URL with the share name and share id for the user to set up their online trophy cabinet.

This feature should now be complete to land in trunk.

To post a comment you must log in.
84. By Jono Bacon

 * Fixed this branch to use DBUS signals to handle this more elegantly.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'accomplishments/daemon/api.py'
2--- accomplishments/daemon/api.py 2012-06-12 20:23:01 +0000
3+++ accomplishments/daemon/api.py 2012-06-25 22:36:20 +0000
4@@ -65,6 +65,7 @@
5
6 LOCAL_USERNAME = getpass.getuser()
7 SCRIPT_DELAY = 900
8+ONLINETROPHIESHOST = "213.138.100.229:8000"
9
10 #flags used for scripts_state
11 NOT_RUNNING = 0
12@@ -88,7 +89,7 @@
13 pprotocol = SubprocessReturnCodeProtocol()
14 reactor.spawnProcess(pprotocol, command[0], command, env=os.environ)
15 return pprotocol.returnCodeDeferred
16-
17+
18 @defer.inlineCallbacks
19 def verify_ubuntu_one_account(self):
20 # check if this machine has an Ubuntu One account
21@@ -587,6 +588,33 @@
22
23 self._write_config_file()
24
25+ def _get_active_share(self, shares):
26+ matchingshares = []
27+
28+ for s in shares:
29+ if s["other_username"] == self.matrix_username:
30+ if s["subscribed"] == "True":
31+ matchingshares.append( { "name" : s["name"], "share_id" : s["node_id"] } )
32+
33+ trophydir = self.get_config_value("config", "trophypath")
34+
35+ if len(matchingshares) > 1:
36+ log.msg("Error Publishing Online: could not find unique active share")
37+ else:
38+ webviewfile = open(os.path.join(trophydir, "WEBVIEW"), 'w')
39+ string = " "
40+ webviewfile.write(string)
41+ url = "http://" + ONLINETROPHIESHOST + "/user/addshare?share_name=" + matchingshares[0]["name"] + "&share_id=" + matchingshares[0]["share_id"]
42+ self.service.publish_trophies_online_completed(url)
43+
44+ def publish_trophies_online(self):
45+ l = self.sd.list_shared()
46+ l.addCallback(self._get_active_share)
47+
48+ def unpublish_trophies_online(self):
49+ trophydir = self.get_config_value("config", "trophypath")
50+ os.remove(os.path.join(trophydir, "WEBVIEW"))
51+
52 def get_all_extra_information(self):
53 """
54 Return a dictionary of all information for the accomplishments
55@@ -1104,6 +1132,16 @@
56
57 # ========= Misc functions ===========
58
59+ def get_published_status(self):
60+ """Detect if we are currently publishing online or not. Returns
61+ True if we are or False if we are not. """
62+
63+ trophydir = self.get_config_value("config", "trophypath")
64+ print trophydir
65+ if os.path.exists(os.path.join(trophydir, "WEBVIEW")):
66+ return True
67+ else:
68+ return False
69
70 def accomplish(self,accomID):
71 log.msg("Accomplishing: %s" % accomID)
72
73=== modified file 'accomplishments/daemon/dbusapi.py'
74--- accomplishments/daemon/dbusapi.py 2012-06-07 23:41:03 +0000
75+++ accomplishments/daemon/dbusapi.py 2012-06-25 22:36:20 +0000
76@@ -207,6 +207,11 @@
77 in_signature="s", out_signature="b")
78 def get_acc_is_completed(self,accomID):
79 return self.api.get_acc_is_completed(accomID)
80+
81+ @dbus.service.method(dbus_interface='org.ubuntu.accomplishments',
82+ in_signature="", out_signature="b")
83+ def get_published_status(self):
84+ return self.api.get_published_status()
85
86 @dbus.service.method(dbus_interface='org.ubuntu.accomplishments',
87 in_signature="s", out_signature="s")
88@@ -302,6 +307,16 @@
89 in_signature="", out_signature="s")
90 def get_API_version(self):
91 return self.api.get_API_version()
92+
93+ @dbus.service.method(dbus_interface='org.ubuntu.accomplishments',
94+ in_signature="", out_signature="")
95+ def publish_trophies_online(self):
96+ return self.api.publish_trophies_online()
97+
98+ @dbus.service.method(dbus_interface='org.ubuntu.accomplishments',
99+ in_signature="", out_signature="")
100+ def unpublish_trophies_online(self):
101+ return self.api.unpublish_trophies_online()
102
103 # XXX this looks like an unintentional duplicate of the "other"
104 # trophy_received... I've moved them here together so that someone in the
105@@ -314,6 +329,10 @@
106 return trophy
107
108 @dbus.service.signal(dbus_interface='org.ubuntu.accomplishments')
109+ def publish_trophies_online_completed(self, url):
110+ return url
111+
112+ @dbus.service.signal(dbus_interface='org.ubuntu.accomplishments')
113 def scriptrunner_start(self):
114 pass
115

Subscribers

People subscribed via source and target branches