Merge lp:~robru/friends/avatar-cache into lp:friends

Proposed by Robert Bruce Park
Status: Merged
Approved by: Ken VanDine
Approved revision: 208
Merged at revision: 208
Proposed branch: lp:~robru/friends/avatar-cache
Merge into: lp:friends
Diff against target: 554 lines (+56/-137)
15 files modified
friends/protocols/facebook.py (+4/-6)
friends/protocols/flickr.py (+4/-7)
friends/protocols/foursquare.py (+1/-3)
friends/protocols/twitter.py (+1/-3)
friends/service/dispatcher.py (+0/-9)
friends/service/mock_service.py (+0/-4)
friends/tests/test_avatars.py (+0/-29)
friends/tests/test_facebook.py (+5/-10)
friends/tests/test_flickr.py (+2/-6)
friends/tests/test_foursquare.py (+3/-4)
friends/tests/test_notify.py (+19/-0)
friends/tests/test_twitter.py (+10/-15)
friends/utils/avatar.py (+4/-24)
friends/utils/notify.py (+3/-1)
service/src/service.vala (+0/-16)
To merge this branch: bzr merge lp:~robru/friends/avatar-cache
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Ken VanDine Approve
Review via email: mp+170206@code.launchpad.net

Commit message

Move avatar cache under /tmp

Description of the change

Stop caching avatar URLs locally; change icon_uri model schema to contain the original URL rather than the local cache. Delete all avatar cache expiry logic. Move the avatar cache under /tmp so that the system will clear it at each boot.

How to test this change:

1. build a package from this branch and install it.
2. delete ~/.local/share/resources/com.canonical.Friends.Streams
3. start friends-app
4. ensure that friends-app scrolls very smoothly through the list of tweets
5. watch out for notifications, ensure that the avatar icon appears in them. (maybe set com.canonical.friends.notifications to 'all' so that you're more likely to see a notification when you do a refresh).

Oh, and of course, run 'make check' ;-)

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:208
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~robru/friends/avatar-cache/+merge/170206/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/friends-ci/46/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/friends-saucy-amd64-ci/3

Click here to trigger a rebuild:
http://s-jenkins:8080/job/friends-ci/46/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Ken VanDine (ken-vandine) wrote :

Looks great and works well, thanks!

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'friends/protocols/facebook.py'
2--- friends/protocols/facebook.py 2013-06-17 21:01:36 +0000
3+++ friends/protocols/facebook.py 2013-06-18 22:10:33 +0000
4@@ -24,7 +24,6 @@
5 import time
6 import logging
7
8-from friends.utils.avatar import Avatar
9 from friends.utils.base import Base, feature
10 from friends.utils.cache import JsonCache
11 from friends.utils.http import Downloader, Uploader
12@@ -99,8 +98,8 @@
13 args['sender_id'] = sender_id = from_record.get('id', '')
14 args['url'] = STORY_PERMALINK.format(
15 id=sender_id, post_id=post_id)
16- args['icon_uri'] = Avatar.get_image(
17- API_BASE.format(id=sender_id) + '/picture?width=840&height=840')
18+ args['icon_uri'] = (API_BASE.format(id=sender_id) +
19+ '/picture?width=840&height=840')
20 args['sender_nick'] = from_record.get('name', '')
21 args['from_me'] = (sender_id == self._account.user_id)
22
23@@ -322,9 +321,8 @@
24 sender_nick=self._account.user_name,
25 timestamp=iso8601utc(int(time.time())),
26 url=destination_url,
27- icon_uri=Avatar.get_image(
28- API_BASE.format(id=self._account.user_id) +
29- '/picture?type=large'))
30+ icon_uri=(API_BASE.format(id=self._account.user_id) +
31+ '/picture?type=large'))
32 return destination_url
33 else:
34 raise FriendsError(str(response))
35
36=== modified file 'friends/protocols/flickr.py'
37--- friends/protocols/flickr.py 2013-03-25 23:37:08 +0000
38+++ friends/protocols/flickr.py 2013-06-18 22:10:33 +0000
39@@ -25,7 +25,6 @@
40 import time
41 import logging
42
43-from friends.utils.avatar import Avatar
44 from friends.utils.base import Base, feature
45 from friends.utils.http import Downloader, Uploader
46 from friends.utils.time import iso8601utc, parsetime
47@@ -93,13 +92,11 @@
48 iconfarm = person.get('iconfarm')
49 iconserver = person.get('iconserver')
50 if None in (iconfarm, iconserver):
51- return Avatar.get_image(
52- 'http://www.flickr.com/images/buddyicon.gif')
53- avatar = BUDDY_ICON_URL.format(
54+ return 'http://www.flickr.com/images/buddyicon.gif'
55+ return BUDDY_ICON_URL.format(
56 farm=iconfarm,
57 server=iconserver,
58 nsid=nsid)
59- return Avatar.get_image(avatar)
60
61 # http://www.flickr.com/services/api/flickr.photos.getContactsPhotos.html
62 @feature
63@@ -135,8 +132,8 @@
64 url = ''
65 from_me = (ownername == username)
66 if None not in (icon_farm, icon_server, owner):
67- icon_uri = Avatar.get_image(BUDDY_ICON_URL.format(
68- farm=icon_farm, server=icon_server, nsid=owner))
69+ icon_uri = BUDDY_ICON_URL.format(
70+ farm=icon_farm, server=icon_server, nsid=owner)
71 url = IMAGE_PAGE_URL.format(owner=owner, photo=photo_id)
72
73 # Calculate the ISO 8601 UTC time string.
74
75=== modified file 'friends/protocols/foursquare.py'
76--- friends/protocols/foursquare.py 2013-03-12 04:04:07 +0000
77+++ friends/protocols/foursquare.py 2013-06-18 22:10:33 +0000
78@@ -22,7 +22,6 @@
79
80 import logging
81
82-from friends.utils.avatar import Avatar
83 from friends.utils.base import Base, feature
84 from friends.utils.http import Downloader
85 from friends.utils.time import iso8601utc
86@@ -81,7 +80,6 @@
87 for checkin in checkins:
88 user = checkin.get('user', {})
89 avatar = user.get('photo', {})
90- avatar_url = '{prefix}100x100{suffix}'.format(**avatar)
91 checkin_id = checkin.get('id', '')
92 tz_offset = checkin.get('timeZoneOffset', 0)
93 epoch = checkin.get('createdAt', 0)
94@@ -95,7 +93,7 @@
95 timestamp=iso8601utc(epoch, tz_offset),
96 message=checkin.get('shout', ''),
97 likes=checkin.get('likes', {}).get('count', 0),
98- icon_uri=Avatar.get_image(avatar_url),
99+ icon_uri='{prefix}100x100{suffix}'.format(**avatar),
100 url=venue.get('canonicalUrl', ''),
101 location=venue.get('name', ''),
102 latitude=location.get('lat', 0.0),
103
104=== modified file 'friends/protocols/twitter.py'
105--- friends/protocols/twitter.py 2013-04-17 06:13:49 +0000
106+++ friends/protocols/twitter.py 2013-06-18 22:10:33 +0000
107@@ -27,7 +27,6 @@
108
109 from urllib.parse import quote
110
111-from friends.utils.avatar import Avatar
112 from friends.utils.base import Base, feature
113 from friends.utils.cache import JsonCache
114 from friends.utils.http import BaseRateLimiter, Downloader
115@@ -142,8 +141,7 @@
116 sender_id=str(user.get('id', '')),
117 sender_nick=screen_name,
118 from_me=(screen_name == self._account.user_name),
119- icon_uri=Avatar.get_image(
120- avatar_url.replace('_normal.', '.')),
121+ icon_uri=avatar_url.replace('_normal.', '.'),
122 liked=tweet.get('favorited', False),
123 url=permalink,
124 )
125
126=== modified file 'friends/service/dispatcher.py'
127--- friends/service/dispatcher.py 2013-04-02 21:54:24 +0000
128+++ friends/service/dispatcher.py 2013-06-18 22:10:33 +0000
129@@ -30,7 +30,6 @@
130 from gi.repository import GLib
131 from contextlib import ContextDecorator
132
133-from friends.utils.avatar import Avatar
134 from friends.utils.account import find_accounts
135 from friends.utils.manager import protocol_manager
136 from friends.utils.menus import MenuManager
137@@ -347,11 +346,3 @@
138 if not self.settings.get_boolean('shorten-urls'):
139 return message
140 return Short(service_name).sub(message)
141-
142- @exit_after_idle
143- @dbus.service.method(DBUS_INTERFACE)
144- def ExpireAvatars(self):
145- pass
146- # Disabled because we don't currently have a way of re-fetching
147- # expired avatars if they're needed again later.
148- # Avatar.expire_old_avatars()
149
150=== modified file 'friends/service/mock_service.py'
151--- friends/service/mock_service.py 2013-03-13 04:36:33 +0000
152+++ friends/service/mock_service.py 2013-06-18 22:10:33 +0000
153@@ -95,7 +95,3 @@
154 @dbus.service.method(DBUS_INTERFACE, in_signature='s', out_signature='s')
155 def URLShorten(self, url):
156 return str(len(url))
157-
158- @dbus.service.method(DBUS_INTERFACE)
159- def ExpireAvatars(self):
160- pass
161
162=== modified file 'friends/tests/test_avatars.py'
163--- friends/tests/test_avatars.py 2013-02-28 19:10:20 +0000
164+++ friends/tests/test_avatars.py 2013-06-18 22:10:33 +0000
165@@ -130,32 +130,3 @@
166 # This is the PNG file format magic number, living in the first 8
167 # bytes of the file.
168 self.assertEqual(raw.read(8), bytes.fromhex('89504E470D0A1A0A'))
169-
170- def test_cache_expiration(self):
171- # Cache files which are more than 4 weeks old get expired.
172- #
173- # Start by copying two copies of ubuntu.png to the temporary cache
174- # dir. Fiddle with their mtimes. so that one is just younger than 4
175- # weeks old and one is just older than 4 weeks old. Run the cache
176- # eviction method and ensure that the young one is retained while the
177- # old one is removed.
178- with mock.patch('friends.utils.avatar.CACHE_DIR',
179- self._avatar_cache) as cache_dir:
180- os.makedirs(cache_dir)
181- src = resource_filename('friends.tests.data', 'ubuntu.png')
182- aaa = os.path.join(cache_dir, 'aaa')
183- shutil.copyfile(src, aaa)
184- bbb = os.path.join(cache_dir, 'bbb')
185- shutil.copyfile(src, bbb)
186- # Leave the atime unchanged.
187- four_weeks_ago = date.today() - timedelta(weeks=4)
188- young = four_weeks_ago + timedelta(days=1)
189- old = four_weeks_ago - timedelta(days=1)
190- # aaa will be young enough to keep (i.e. 4 weeks less one day ago)
191- os.utime(aaa,
192- (os.stat(aaa).st_atime, time.mktime(young.timetuple())))
193- # bbb will be too old to keep (i.e. 4 weeks plus one day ago)
194- os.utime(bbb,
195- (os.stat(bbb).st_atime, time.mktime(old.timetuple())))
196- Avatar.expire_old_avatars()
197- self.assertEqual(os.listdir(cache_dir), ['aaa'])
198
199=== modified file 'friends/tests/test_facebook.py'
200--- friends/tests/test_facebook.py 2013-06-11 19:58:29 +0000
201+++ friends/tests/test_facebook.py 2013-06-18 22:10:33 +0000
202@@ -129,8 +129,7 @@
203 'Writing code that supports geotagging data from facebook. ' +
204 'If y\'all could make some geotagged facebook posts for me ' +
205 'to test with, that\'d be super.',
206- GLib.get_user_cache_dir() +
207- '/friends/avatars/5c4e74c64b1a09343558afc1046c2b1d176a2ba2',
208+ 'https://graph.facebook.com/56789/picture?width=840&height=840',
209 'https://www.facebook.com/56789/posts/postid1',
210 1,
211 False,
212@@ -155,8 +154,7 @@
213 False,
214 '2013-03-12T23:29:45Z',
215 'don\'t know how',
216- GLib.get_user_cache_dir() +
217- '/friends/avatars/9b9379ccc7948e4804dff7914bfa4c6de3974df5',
218+ 'https://graph.facebook.com/234/picture?width=840&height=840',
219 'https://www.facebook.com/234/posts/commentid2',
220 0,
221 False,
222@@ -186,8 +184,7 @@
223 'Texas. Monday, March 11th, 4:00pm to 7:00 pm. Also here ' +
224 'Hannah Hart (My Drunk Kitchen) and Angry Video Game Nerd ' +
225 'producer, Sean Keegan. Stanley is in the lobby.',
226- GLib.get_user_cache_dir() +
227- '/friends/avatars/5b2d70e788df790b9c8db4c6a138fc4a1f433ec9',
228+ 'https://graph.facebook.com/161247843901324/picture?width=840&height=840',
229 'https://www.facebook.com/161247843901324/posts/629147610444676',
230 84,
231 False,
232@@ -213,8 +210,7 @@
233 False,
234 '2013-03-15T19:57:14Z',
235 'Guy Frenchie did some things with some stuff.',
236- GLib.get_user_cache_dir() +
237- '/friends/avatars/3f5e276af0c43f6411d931b829123825ede1968e',
238+ 'https://graph.facebook.com/1244414/picture?width=840&height=840',
239 'https://www.facebook.com/1244414/posts/100085049977',
240 3,
241 False,
242@@ -370,8 +366,7 @@
243 timestamp='2012-11-06T13:49:08Z',
244 sender_id=None,
245 from_me=True,
246- icon_uri=GLib.get_user_cache_dir() +
247- '/friends/avatars/d49d72a384d50adf7c736ba27ca55bfa9fa5782d',
248+ icon_uri='https://graph.facebook.com/None/picture?type=large',
249 message='This is Ubuntu!',
250 message_id='234125',
251 sender=None)
252
253=== modified file 'friends/tests/test_flickr.py'
254--- friends/tests/test_flickr.py 2013-03-25 23:37:08 +0000
255+++ friends/tests/test_flickr.py 2013-06-18 22:10:33 +0000
256@@ -22,8 +22,6 @@
257
258 import unittest
259
260-from gi.repository import GLib
261-
262 from friends.errors import AuthorizationError, FriendsError
263 from friends.protocols.flickr import Flickr
264 from friends.tests.mocks import FakeAccount, FakeSoupMessage, LogMock
265@@ -176,8 +174,7 @@
266 True,
267 '2013-03-12T19:51:42Z',
268 'Chocolate chai #yegcoffee',
269- GLib.get_user_cache_dir() +
270- '/friends/avatars/7b30ff0140dd9b80f2b1782a2802c3ce785fa0ce',
271+ 'http://farm1.static.flickr.com/93/buddyicons/47303164@N00.jpg',
272 'http://www.flickr.com/photos/47303164@N00/8552892154',
273 0,
274 False,
275@@ -204,8 +201,7 @@
276 True,
277 '2013-03-12T13:54:10Z',
278 'St. Michael - The Archangel',
279- GLib.get_user_cache_dir() +
280- '/friends/avatars/cae2939354a33fea5f008df91bb8e25920be5dc3',
281+ 'http://farm3.static.flickr.com/2047/buddyicons/27204141@N05.jpg',
282 'http://www.flickr.com/photos/27204141@N05/8550829193',
283 0,
284 False,
285
286=== modified file 'friends/tests/test_foursquare.py'
287--- friends/tests/test_foursquare.py 2013-03-21 21:49:26 +0000
288+++ friends/tests/test_foursquare.py 2013-06-18 22:10:33 +0000
289@@ -83,8 +83,6 @@
290 FakeSoupMessage('friends.tests.data', 'foursquare-full.dat'))
291 @mock.patch('friends.protocols.foursquare.FourSquare._login',
292 return_value=True)
293- @mock.patch('friends.protocols.foursquare.Avatar.get_image',
294- return_value='~/.cache/friends/avatar/hash')
295 def test_receive(self, *mocks):
296 self.account.access_token = 'tokeny goodness'
297 self.assertEqual(0, TestModel.get_n_rows())
298@@ -94,8 +92,9 @@
299 'foursquare', 88, '50574c9ce4b0a9a6e84433a0',
300 'messages', 'Jimbob Smith', '', '', True, '2012-09-17T19:15:24Z',
301 "Working on friends's foursquare plugin.",
302- '~/.cache/friends/avatar/hash', '', 0, False, '', '', '',
303- '', '', '', 'Pop Soda\'s Coffee House & Gallery',
304+ 'https://irs0.4sqi.net/img/user/100x100/5IEW3VIX55BBEXAO.jpg',
305+ '', 0, False, '', '', '', '', '', '',
306+ 'Pop Soda\'s Coffee House & Gallery',
307 49.88873164336725, -97.158043384552,
308 ]
309 self.assertEqual(list(TestModel.get_row(0)), expected)
310
311=== modified file 'friends/tests/test_notify.py'
312--- friends/tests/test_notify.py 2013-04-16 17:55:01 +0000
313+++ friends/tests/test_notify.py 2013-06-18 22:10:33 +0000
314@@ -40,6 +40,25 @@
315
316 @mock.patch('friends.utils.base.Model', TestModel)
317 @mock.patch('friends.utils.base._seen_ids', {})
318+ @mock.patch('friends.utils.notify.Avatar')
319+ @mock.patch('friends.utils.notify.GdkPixbuf')
320+ @mock.patch('friends.utils.notify.Notify')
321+ def test_publish_avatar_cache(self, notify, gdkpixbuf, avatar):
322+ Base._do_notify = lambda protocol, stream: True
323+ base = Base(FakeAccount())
324+ base._publish(
325+ message='http://example.com!',
326+ message_id='1234',
327+ sender='Benjamin',
328+ timestamp=RIGHT_NOW,
329+ icon_uri='http://example.com/bob.jpg',
330+ )
331+ avatar.get_image.assert_called_once_with('http://example.com/bob.jpg')
332+ gdkpixbuf.Pixbuf.new_from_file_at_size.assert_called_once_with(
333+ avatar.get_image(), 48, 48)
334+
335+ @mock.patch('friends.utils.base.Model', TestModel)
336+ @mock.patch('friends.utils.base._seen_ids', {})
337 @mock.patch('friends.utils.base.notify')
338 def test_publish_no_html(self, notify):
339 Base._do_notify = lambda protocol, stream: True
340
341=== modified file 'friends/tests/test_twitter.py'
342--- friends/tests/test_twitter.py 2013-04-17 06:13:49 +0000
343+++ friends/tests/test_twitter.py 2013-06-18 22:10:33 +0000
344@@ -26,7 +26,6 @@
345 import unittest
346 import shutil
347
348-from gi.repository import GLib
349 from urllib.error import HTTPError
350
351 from friends.protocols.twitter import RateLimiter, Twitter
352@@ -138,8 +137,7 @@
353 ['twitter', 88, '240558470661799936',
354 'messages', 'OAuth Dancer', '119476949', 'oauth_dancer', False,
355 '2012-08-28T21:16:23Z', 'just another test',
356- GLib.get_user_cache_dir() +
357- '/friends/avatars/ded4ba3c00583ee511f399d0b2537731ca14c39d',
358+ 'https://si0.twimg.com/profile_images/730275945/oauth-dancer.jpg',
359 'https://twitter.com/oauth_dancer/status/240558470661799936',
360 0, False, '', '', '', '', '', '', '', 0.0, 0.0,
361 ],
362@@ -149,8 +147,8 @@
363 'with twitter" class at @cal with @othman '
364 '<a href="http://blogs.ischool.berkeley.edu/i290-abdt-s12/">'
365 'http://blogs.ischool.berkeley.edu/i290-abdt-s12/</a>',
366- GLib.get_user_cache_dir() +
367- '/friends/avatars/0219effc03a3049a622476e6e001a4014f33dc31',
368+ 'https://si0.twimg.com/profile_images/1270234259/'
369+ 'raffi-headshot-casual.png',
370 'https://twitter.com/raffi/status/240556426106372096',
371 0, False, '', '', '', '', '', '', '', 0.0, 0.0,
372 ],
373@@ -158,8 +156,8 @@
374 'messages', 'Taylor Singletary', '819797', 'episod', False,
375 '2012-08-28T19:59:34Z',
376 'You\'d be right more often if you thought you were wrong.',
377- GLib.get_user_cache_dir() +
378- '/friends/avatars/0c829cb2934ad76489be21ee5e103735d9b7b034',
379+ 'https://si0.twimg.com/profile_images/2546730059/'
380+ 'f6a8zq58mg1hn0ha8vie.jpeg',
381 'https://twitter.com/episod/status/240539141056638977',
382 0, False, '', '', '', '', '', '', '', 0.0, 0.0,
383 ],
384@@ -209,8 +207,7 @@
385 'twitter', 88, '240558470661799936',
386 'messages', 'OAuth Dancer', '119476949', 'oauth_dancer', True,
387 '2012-08-28T21:16:23Z', 'just another test',
388- GLib.get_user_cache_dir() +
389- '/friends/avatars/ded4ba3c00583ee511f399d0b2537731ca14c39d',
390+ 'https://si0.twimg.com/profile_images/730275945/oauth-dancer.jpg',
391 'https://twitter.com/oauth_dancer/status/240558470661799936',
392 0, False, '', '', '', '', '', '', '', 0.0, 0.0,
393 ]
394@@ -295,9 +292,7 @@
395 'direct_messages/sent.json?count=50')
396 ])
397
398- @mock.patch('friends.protocols.twitter.Avatar.get_image',
399- return_value='~/.cache/friends/avatars/hash')
400- def test_private_avatars(self, image_mock):
401+ def test_private_avatars(self):
402 get_url = self.protocol._get_url = mock.Mock(
403 return_value=[
404 dict(
405@@ -317,7 +312,7 @@
406 publish.assert_called_with(
407 liked=False, sender='Bob', stream='private',
408 url='https://twitter.com/some_guy/status/1452456',
409- icon_uri='~/.cache/friends/avatars/hash',
410+ icon_uri='https://example.com/bob.jpg',
411 sender_nick='some_guy', sender_id='', from_me=False,
412 timestamp='2012-11-04T17:14:52Z', message='Does my avatar show up?',
413 message_id='1452456')
414@@ -474,8 +469,8 @@
415 '2013-04-16T17:58:26Z', 'RT @tarek_ziade: Just found a "Notification '
416 'of Inspection" card in the bottom of my bag. looks like they were '
417 'curious about those raspbe ...',
418- GLib.get_user_cache_dir() +
419- '/friends/avatars/1444c8a86dbbe7a6f5f89a8135e770824d7b22bc',
420+ 'https://si0.twimg.com/profile_images/2631306428/'
421+ '2a509db8a05b4310394b832d34a137a4.png',
422 'https://twitter.com/therealrobru/status/324220250889543682',
423 0, False, '', '', '', '', '', '', '', 0.0, 0.0,
424 ]
425
426=== modified file 'friends/utils/avatar.py'
427--- friends/utils/avatar.py 2013-04-03 21:22:57 +0000
428+++ friends/utils/avatar.py 2013-06-18 22:10:33 +0000
429@@ -23,17 +23,15 @@
430 import os
431 import logging
432
433-from datetime import date, timedelta
434 from gi.repository import Gio, GLib, GdkPixbuf
435+from tempfile import gettempdir
436 from hashlib import sha1
437
438 from friends.utils.http import Downloader
439 from friends.errors import ignored
440
441
442-CACHE_DIR = os.path.realpath(os.path.join(
443- GLib.get_user_cache_dir(), 'friends', 'avatars'))
444-AGE_LIMIT = date.today() - timedelta(weeks=4)
445+CACHE_DIR = os.path.join(gettempdir(), 'friends-avatars')
446
447
448 with ignored(FileExistsError):
449@@ -54,14 +52,11 @@
450 return url
451 local_path = Avatar.get_path(url)
452 size = 0
453- mtime = date.fromtimestamp(0)
454
455 with ignored(FileNotFoundError):
456- stat = os.stat(local_path)
457- size = stat.st_size
458- mtime = date.fromtimestamp(stat.st_mtime)
459+ size = os.stat(local_path).st_size
460
461- if size == 0 or mtime < AGE_LIMIT:
462+ if size == 0:
463 log.debug('Getting: {}'.format(url))
464 image_data = Downloader(url).get_bytes()
465
466@@ -79,18 +74,3 @@
467 except GLib.GError:
468 log.error('Failed to scale image: {}'.format(url))
469 return local_path
470-
471- @staticmethod
472- def expire_old_avatars():
473- """Evict old files from the cache."""
474- log.debug('Checking if anything needs to expire.')
475- for filename in os.listdir(CACHE_DIR):
476- path = os.path.join(CACHE_DIR, filename)
477- mtime = date.fromtimestamp(os.stat(path).st_mtime)
478- if mtime < AGE_LIMIT:
479- # The file's last modification time is earlier than the oldest
480- # time we'll allow in the cache. However, due to race
481- # conditions, ignore it if the file has already been removed.
482- with ignored(FileNotFoundError):
483- log.debug('Expiring: {}'.format(path))
484- os.remove(path)
485
486=== modified file 'friends/utils/notify.py'
487--- friends/utils/notify.py 2013-04-17 06:13:49 +0000
488+++ friends/utils/notify.py 2013-06-18 22:10:33 +0000
489@@ -27,6 +27,7 @@
490
491 from gi.repository import GObject, GdkPixbuf
492
493+from friends.utils.avatar import Avatar
494 from friends.errors import ignored
495
496
497@@ -45,7 +46,7 @@
498
499 with ignored(GObject.GError):
500 pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
501- icon_uri, 48, 48)
502+ Avatar.get_image(icon_uri), 48, 48)
503
504 if pixbuf is not None:
505 notification.set_icon_from_pixbuf(pixbuf)
506@@ -58,6 +59,7 @@
507 # not much we can do about that.
508 notification.show()
509
510+
511 # Optional dependency on Notify library.
512 try:
513 from gi.repository import Notify
514
515=== modified file 'service/src/service.vala'
516--- service/src/service.vala 2013-04-17 18:23:44 +0000
517+++ service/src/service.vala 2013-06-18 22:10:33 +0000
518@@ -21,7 +21,6 @@
519 [DBus (name = "com.canonical.Friends.Dispatcher")]
520 private interface Dispatcher : GLib.Object {
521 public abstract void Refresh () throws GLib.IOError;
522- public abstract void ExpireAvatars () throws GLib.IOError;
523 public abstract async void Do (
524 string action,
525 string account_id,
526@@ -184,7 +183,6 @@
527 try {
528 dispatcher = Bus.get_proxy.end(res);
529 Timeout.add_seconds (120, fetch_contacts);
530- Timeout.add_seconds (300, expire_avatars);
531 var ret = on_refresh ();
532 } catch (IOError e) {
533 warning (e.message);
534@@ -218,20 +216,6 @@
535 }
536 return false;
537 }
538-
539- bool expire_avatars ()
540- {
541- debug ("Expiring old avatars...");
542- // By default, this happens 5 minutes after startup, and then
543- // every 7 days thereafter.
544- Timeout.add_seconds (604800, expire_avatars);
545- try {
546- dispatcher.ExpireAvatars ();
547- } catch (IOError e) {
548- warning ("Failed to expire avatars - %s", e.message);
549- }
550- return false;
551- }
552 }
553
554 void on_bus_aquired (DBusConnection conn) {

Subscribers

People subscribed via source and target branches