Merge lp:~mfisch/ubuntu-accomplishments-daemon/ubuntu-accomplishments-daemon-small-fixes into lp:ubuntu-accomplishments-daemon

Proposed by Matt Fischer
Status: Merged
Merged at revision: 113
Proposed branch: lp:~mfisch/ubuntu-accomplishments-daemon/ubuntu-accomplishments-daemon-small-fixes
Merge into: lp:ubuntu-accomplishments-daemon
Diff against target: 108 lines (+25/-18)
3 files modified
accomplishments/daemon/api.py (+17/-17)
accomplishments/daemon/tests/accomps/second.accomplishment (+1/-1)
accomplishments/daemon/tests/tests.py (+7/-0)
To merge this branch: bzr merge lp:~mfisch/ubuntu-accomplishments-daemon/ubuntu-accomplishments-daemon-small-fixes
Reviewer Review Type Date Requested Status
Ubuntu Accomplishments Daemon Developers Pending
Review via email: mp+115822@code.launchpad.net

Description of the change

Fixes two small bugs:

if icon has no "." in the name, you get an exception - 10240512
get_block_ubuntuone_notification_bubbles() parses config on it's own, should use config.get_boolean() - 1024052

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 'accomplishments/daemon/api.py'
2--- accomplishments/daemon/api.py 2012-07-19 18:30:37 +0000
3+++ accomplishments/daemon/api.py 2012-07-19 19:55:25 +0000
4@@ -1182,24 +1182,26 @@
5 return None
6 else:
7 return res
8-
9+
10 def get_acc_icon(self,accomID):
11 return self.accDB[accomID]['icon']
12-
13+
14 def get_acc_icon_path(self,accomID):
15 imagesdir = os.path.join(self.dir_cache,'trophyimages')
16 imagesdir = os.path.join(imagesdir,self.get_acc_collection(accomID))
17 iconfile = self.get_acc_icon(accomID)
18- # XXX - this will fail if the icon passed in does not have a .
19- # in the file name - LP: 1024012
20- iconfilename, iconfileext = iconfile.split(".")
21+ iconfilename, iconfileext = os.path.splitext(iconfile)
22+
23+ # safely handle files without extensions
24+ if not iconfileext:
25+ iconfileext = ""
26 if not self.get_acc_is_unlocked(accomID):
27 iconfilename = iconfilename + '-locked'
28 elif not self.get_acc_is_completed(accomID):
29 iconfilename = iconfilename + '-opportunity'
30- iconfile = iconfilename + "." + iconfileext
31+ iconfile = iconfilename + iconfileext
32 return os.path.join(imagesdir,iconfile)
33-
34+
35 def get_acc_needs_info(self,accomID):
36 if not 'needs-information' in self.accDB[accomID]:
37 return []
38@@ -1554,10 +1556,10 @@
39 elif value == False:
40 if config.has_section("notifications"):
41 config.set('notifications', 'show_all_notifications', "True")
42-
43+
44 with open(cfile, 'wb') as configfile:
45 config.write(configfile)
46-
47+
48 def get_block_ubuntuone_notification_bubbles(self):
49 u1configdir = os.path.join(
50 xdg.BaseDirectory.xdg_config_home, "ubuntuone")
51@@ -1568,15 +1570,13 @@
52 config = ConfigParser.ConfigParser()
53 config.read(cfile)
54
55- if(config.read(cfile)):
56+ if (config.read(cfile)):
57 if config.has_section("notifications"):
58- val = config.get('notifications', 'show_all_notifications')
59- if val == "false" or val == "False":
60- return True
61- else:
62- return False
63- else:
64- return False
65+ val = config.getboolean('notifications',
66+ 'show_all_notifications')
67+ return val
68+
69+ return False
70
71 def _coll_from_accomID(self,accomID):
72 return accomID.split("/")[0]
73
74=== modified file 'accomplishments/daemon/tests/accomps/second.accomplishment'
75--- accomplishments/daemon/tests/accomps/second.accomplishment 2012-07-13 23:00:12 +0000
76+++ accomplishments/daemon/tests/accomps/second.accomplishment 2012-07-19 19:55:25 +0000
77@@ -1,6 +1,6 @@
78 [accomplishment]
79 title=My Second Accomplishment
80-icon=second.jpg
81+icon=second
82 description=An example accomplishment for the test suite, with dependency
83 depends=testaccomp/first
84 needs-signing=True
85
86=== modified file 'accomplishments/daemon/tests/tests.py'
87--- accomplishments/daemon/tests/tests.py 2012-07-19 16:35:51 +0000
88+++ accomplishments/daemon/tests/tests.py 2012-07-19 19:55:25 +0000
89@@ -449,12 +449,19 @@
90 # also tests get_acc_icon_path
91 def test_get_acc_icon(self):
92 self.util_copy_accomp(self.accomp_dir, "first")
93+ self.util_copy_accomp(self.accomp_dir, "second")
94 a = api.Accomplishments(None, None, True)
95 self.assertEquals(a.get_acc_icon('%s/first' % self.ACCOMP_SET),
96 'first.jpg')
97 icon_path = a.get_acc_icon_path('%s/first' % self.ACCOMP_SET)
98 self.assertTrue(icon_path.endswith("first-opportunity.jpg"))
99
100+ # LP 1024052 - make sure this works without a . in the filename
101+ self.assertEquals(a.get_acc_icon('%s/second' % self.ACCOMP_SET),
102+ 'second')
103+ icon_path = a.get_acc_icon_path('%s/second' % self.ACCOMP_SET)
104+ self.assertTrue(icon_path.endswith("second-locked"))
105+
106 def test_build_viewer_database(self):
107 self.util_remove_all_accomps(self.accomp_dir)
108 self.util_copy_accomp(self.accomp_dir, "first")

Subscribers

People subscribed via source and target branches