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
=== modified file 'accomplishments/daemon/api.py'
--- accomplishments/daemon/api.py 2012-06-12 20:23:01 +0000
+++ accomplishments/daemon/api.py 2012-06-25 22:36:20 +0000
@@ -65,6 +65,7 @@
6565
66LOCAL_USERNAME = getpass.getuser()66LOCAL_USERNAME = getpass.getuser()
67SCRIPT_DELAY = 90067SCRIPT_DELAY = 900
68ONLINETROPHIESHOST = "213.138.100.229:8000"
6869
69#flags used for scripts_state70#flags used for scripts_state
70NOT_RUNNING = 071NOT_RUNNING = 0
@@ -88,7 +89,7 @@
88 pprotocol = SubprocessReturnCodeProtocol()89 pprotocol = SubprocessReturnCodeProtocol()
89 reactor.spawnProcess(pprotocol, command[0], command, env=os.environ)90 reactor.spawnProcess(pprotocol, command[0], command, env=os.environ)
90 return pprotocol.returnCodeDeferred91 return pprotocol.returnCodeDeferred
91 92
92 @defer.inlineCallbacks93 @defer.inlineCallbacks
93 def verify_ubuntu_one_account(self):94 def verify_ubuntu_one_account(self):
94 # check if this machine has an Ubuntu One account95 # check if this machine has an Ubuntu One account
@@ -587,6 +588,33 @@
587588
588 self._write_config_file()589 self._write_config_file()
589590
591 def _get_active_share(self, shares):
592 matchingshares = []
593
594 for s in shares:
595 if s["other_username"] == self.matrix_username:
596 if s["subscribed"] == "True":
597 matchingshares.append( { "name" : s["name"], "share_id" : s["node_id"] } )
598
599 trophydir = self.get_config_value("config", "trophypath")
600
601 if len(matchingshares) > 1:
602 log.msg("Error Publishing Online: could not find unique active share")
603 else:
604 webviewfile = open(os.path.join(trophydir, "WEBVIEW"), 'w')
605 string = " "
606 webviewfile.write(string)
607 url = "http://" + ONLINETROPHIESHOST + "/user/addshare?share_name=" + matchingshares[0]["name"] + "&share_id=" + matchingshares[0]["share_id"]
608 self.service.publish_trophies_online_completed(url)
609
610 def publish_trophies_online(self):
611 l = self.sd.list_shared()
612 l.addCallback(self._get_active_share)
613
614 def unpublish_trophies_online(self):
615 trophydir = self.get_config_value("config", "trophypath")
616 os.remove(os.path.join(trophydir, "WEBVIEW"))
617
590 def get_all_extra_information(self):618 def get_all_extra_information(self):
591 """619 """
592 Return a dictionary of all information for the accomplishments620 Return a dictionary of all information for the accomplishments
@@ -1104,6 +1132,16 @@
1104 1132
1105 # ========= Misc functions ===========1133 # ========= Misc functions ===========
1106 1134
1135 def get_published_status(self):
1136 """Detect if we are currently publishing online or not. Returns
1137 True if we are or False if we are not. """
1138
1139 trophydir = self.get_config_value("config", "trophypath")
1140 print trophydir
1141 if os.path.exists(os.path.join(trophydir, "WEBVIEW")):
1142 return True
1143 else:
1144 return False
1107 1145
1108 def accomplish(self,accomID):1146 def accomplish(self,accomID):
1109 log.msg("Accomplishing: %s" % accomID)1147 log.msg("Accomplishing: %s" % accomID)
11101148
=== modified file 'accomplishments/daemon/dbusapi.py'
--- accomplishments/daemon/dbusapi.py 2012-06-07 23:41:03 +0000
+++ accomplishments/daemon/dbusapi.py 2012-06-25 22:36:20 +0000
@@ -207,6 +207,11 @@
207 in_signature="s", out_signature="b")207 in_signature="s", out_signature="b")
208 def get_acc_is_completed(self,accomID):208 def get_acc_is_completed(self,accomID):
209 return self.api.get_acc_is_completed(accomID)209 return self.api.get_acc_is_completed(accomID)
210
211 @dbus.service.method(dbus_interface='org.ubuntu.accomplishments',
212 in_signature="", out_signature="b")
213 def get_published_status(self):
214 return self.api.get_published_status()
210 215
211 @dbus.service.method(dbus_interface='org.ubuntu.accomplishments',216 @dbus.service.method(dbus_interface='org.ubuntu.accomplishments',
212 in_signature="s", out_signature="s")217 in_signature="s", out_signature="s")
@@ -302,6 +307,16 @@
302 in_signature="", out_signature="s")307 in_signature="", out_signature="s")
303 def get_API_version(self):308 def get_API_version(self):
304 return self.api.get_API_version()309 return self.api.get_API_version()
310
311 @dbus.service.method(dbus_interface='org.ubuntu.accomplishments',
312 in_signature="", out_signature="")
313 def publish_trophies_online(self):
314 return self.api.publish_trophies_online()
315
316 @dbus.service.method(dbus_interface='org.ubuntu.accomplishments',
317 in_signature="", out_signature="")
318 def unpublish_trophies_online(self):
319 return self.api.unpublish_trophies_online()
305 320
306 # XXX this looks like an unintentional duplicate of the "other"321 # XXX this looks like an unintentional duplicate of the "other"
307 # trophy_received... I've moved them here together so that someone in the322 # trophy_received... I've moved them here together so that someone in the
@@ -314,6 +329,10 @@
314 return trophy329 return trophy
315330
316 @dbus.service.signal(dbus_interface='org.ubuntu.accomplishments')331 @dbus.service.signal(dbus_interface='org.ubuntu.accomplishments')
332 def publish_trophies_online_completed(self, url):
333 return url
334
335 @dbus.service.signal(dbus_interface='org.ubuntu.accomplishments')
317 def scriptrunner_start(self):336 def scriptrunner_start(self):
318 pass337 pass
319338

Subscribers

People subscribed via source and target branches