Merge lp:~rafalcieslak256/ubuntu-accomplishments-daemon/local-accoms into lp:ubuntu-accomplishments-daemon

Proposed by Rafał Cieślak
Status: Merged
Merged at revision: 38
Proposed branch: lp:~rafalcieslak256/ubuntu-accomplishments-daemon/local-accoms
Merge into: lp:ubuntu-accomplishments-daemon
Diff against target: 139 lines (+56/-12)
2 files modified
accomplishments/daemon/api.py (+54/-10)
po/accomplishments-daemon.pot (+2/-2)
To merge this branch: bzr merge lp:~rafalcieslak256/ubuntu-accomplishments-daemon/local-accoms
Reviewer Review Type Date Requested Status
Jono Bacon Pending
Review via email: mp+104767@code.launchpad.net

Description of the change

This enables support for local accomplishments.
This is implemented by replacing all pieces of code that rely on .asc file presence with code that checks also if the accomplishment needs-signing.

To post a comment you must log in.
40. By Rafał Cieślak

fixed re-waiting for sig file if last recieved was not valid

Revision history for this message
Rafał Cieślak (rafalcieslak256) wrote :

Right. The issue of scripts not re-running when .asc was received was indeed not introduced in trunk, but since that was a simple thing (see 40th commit to my branch, thing was that run_scripts and wait_for_a_sig_file were called only it the received .asc file was valid), I fixed that here, so now you should experience no problems testing this MP.

Well, almost.

There is another bug, which is present in trunk too, but is triggered somehow randomly, so at first I had an impression that it is introduced by my branch, but it's not.

The problem is that when validate_trophy checks if .asc file is correct JUST after it has been received, it fails because of missing .asc file. Yup, os.path.exists(...) returns 0 for the just-received asc file. I'll report a bug on this.
So in result you may not see some of your global accomplishments, but this branch should now work as intended.

Revision history for this message
Jono Bacon (jonobacon) wrote :

Awesome work, Rafal! Merging in now. :-)

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-04-28 21:57:30 +0000
3+++ accomplishments/daemon/api.py 2012-05-04 18:22:17 +0000
4@@ -102,6 +102,8 @@
5 os.path.split(path)[1])[0])[0]
6
7 valid = self.parent.validate_trophy(path)
8+ if not valid:
9+ log.msg("WARNING: invalid .asc signature recieved from the server!")
10
11 if valid == True:
12 item = os.path.split(path)[1][:-11]
13@@ -127,8 +129,8 @@
14 # check to see if there are any unlocked accomplishments
15 self.parent.show_unlocked_accomplishments(app, item)
16
17- self.parent.run_scripts(0)
18- self.wait_until_a_sig_file_arrives()
19+ self.parent.run_scripts(0)
20+ self.wait_until_a_sig_file_arrives()
21
22 # XXX let's rewrite this to use deferreds explicitly
23 @defer.inlineCallbacks
24@@ -813,10 +815,27 @@
25 if "depends" in data:
26 for dependency in data["depends"].split(","):
27 dapp, dname = dependency.split("/")
28+ #XXX: Below application's default language should be used
29+ # instead of "en", but this will work well in most cases,
30+ # and implementing this properli will be much much easier
31+ # in the new API.
32+ dpath = os.path.join(self.accomplishments_path, dapp, "en",
33+ "%s.accomplishment" % dname)
34+ dcp = ConfigParser.RawConfigParser()
35+ dcp.read(dpath)
36+ dacc_data = dict(dcp._sections["accomplishment"])
37 dtrophy_file = os.path.join(
38 self.trophies_path, dapp,
39- "%s.trophy.asc" % dname)
40- if not os.path.exists(dtrophy_file):
41+ "%s.trophy" % dname)
42+ dtrophysigned = dtrophy_file + ".asc"
43+ if(dacc_data.has_key("needs-signing") and (dacc_data["needs-signing"] == True or dacc_data["needs-signing"] == "True" or dacc_data["needs-signing"] == "true")):
44+ # the dependent accom needs to be signed
45+ dvalid = self.validate_trophy(dtrophysigned)
46+ else:
47+ # this dependency trophy does not require signature
48+ dvalid = os.path.exists(dtrophy_file)
49+
50+ if not dvalid:
51 raise exceptions.AccomplishmentLocked()
52
53 cp = ConfigParser.RawConfigParser()
54@@ -839,15 +858,30 @@
55 fp.close()
56
57 if data.has_key("needs-signing") == False or data["needs-signing"] is False:
58- #self.service.trophy_received()
59+ self.service.trophy_received("foo")
60+ iconpath = os.path.join(
61+ self.accomplishments_path,
62+ data["application"],
63+ "trophyimages",
64+ data["icon"])
65+
66 if self.show_notifications is True and pynotify and (
67 pynotify.is_initted() or pynotify.init("icon-summary-body")):
68 # XXX: need to fix loading the right icon
69 trophy_icon_path = "file://%s" % os.path.realpath(
70 os.path.join(media_dir, "unlocked.png"))
71 n = pynotify.Notification(_("You have accomplished something!"),
72- data["title"], trophy_icon_path)
73+ data["title"], iconpath)
74 n.show()
75+
76+ self.show_unlocked_accomplishments(app,accomplishment_name)
77+ # Because something new has been accomplished and it does not
78+ # require to wait for .asc file, scripts have to be re-run to check
79+ # if something that has been just unlocked hasn't been already
80+ # achieved. Because this function is usually called from
81+ # scriptrunner, the following will schedule scripts for re-running.
82+ self.run_scripts(0)
83+
84 else:
85 # if the trophy needs signing we wait for wait_until_a_sig_file_arrives
86 # to display the notification
87@@ -1090,9 +1124,19 @@
88 self.trophies_path, app, "%s.trophy" % name)
89
90 trophysigned = str(trophy_file) + ".asc"
91-
92- # validate all files that have been signed
93- if self.validate_trophy(trophysigned) == True:
94+
95+ acc_file_cfg = ConfigParser.RawConfigParser()
96+ acc_file_cfg.read(accomplishment_file)
97+ acc_data = dict(acc_file_cfg._sections["accomplishment"])
98+ if(acc_data.has_key("needs-signing") and (acc_data["needs-signing"] == True or acc_data["needs-signing"] == "True" or acc_data["needs-signing"] == "true")):
99+ # this trophy needs to be signed in order to be validated
100+ valid = self.validate_trophy(trophysigned)
101+ else:
102+ # this trophy does not require signature
103+ valid = os.path.exists(trophy_file)
104+
105+
106+ if valid:
107 data["accomplished"] = True
108 data["locked"] = False
109 data.update(self._load_trophy_file(trophy_file))
110@@ -1100,7 +1144,7 @@
111 else:
112 if os.path.exists(trophysigned):
113 os.remove(trophysigned)
114- os.remove(trophy_file)
115+ # os.remove(trophy_file)
116 data["accomplished"] = False
117 data["iconpath"] = os.path.join(icondir, (
118 iconname + "-opportunity" + iconext))
119
120=== modified file 'po/accomplishments-daemon.pot'
121--- po/accomplishments-daemon.pot 2012-04-28 21:57:30 +0000
122+++ po/accomplishments-daemon.pot 2012-05-04 18:22:17 +0000
123@@ -8,7 +8,7 @@
124 msgstr ""
125 "Project-Id-Version: PACKAGE VERSION\n"
126 "Report-Msgid-Bugs-To: \n"
127-"POT-Creation-Date: 2012-04-28 14:56-0700\n"
128+"POT-Creation-Date: 2012-05-02 21:23+0200\n"
129 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
130 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
131 "Language-Team: LANGUAGE <LL@li.org>\n"
132@@ -25,7 +25,7 @@
133 msgid "Clear your trophies collection"
134 msgstr ""
135
136-#: ../accomplishments/daemon/api.py:124 ../accomplishments/daemon/api.py:848
137+#: ../accomplishments/daemon/api.py:124 ../accomplishments/daemon/api.py:871
138 msgid "You have accomplished something!"
139 msgstr ""
140

Subscribers

People subscribed via source and target branches