Merge lp:~mblayman/entertainer/clean-messages into lp:entertainer/future

Proposed by Matt Layman
Status: Merged
Approved by: Matt Layman
Approved revision: 416
Merged at revision: not available
Proposed branch: lp:~mblayman/entertainer/clean-messages
Merge into: lp:entertainer/future
Diff against target: None lines
To merge this branch: bzr merge lp:~mblayman/entertainer/clean-messages
Reviewer Review Type Date Requested Status
Paul Hummer Approve
Review via email: mp+12312@code.launchpad.net

Commit message

Removes some crufty backend connection messages that did nothing.

To post a comment you must log in.
Revision history for this message
Matt Layman (mblayman) wrote :

OOPS, sorry, I certainly meant to target this branch to future.

Dependent on working-sdist (which I guess is just future now).

This is just some work to clean out a bunch of junk in the backend and try to separate the client from the backend in a more clear manner.

I did a bunch of analysis of what we are/aren't using in terms of messages. This led to some nice cleanup and removal of some methods that simply weren't needed.

I know this may not seem like important work, but it means that there will be less pain when it comes time to completely remove elements of the backend that exist in the client code. Less contact points means less work in the future.

Revision history for this message
Paul Hummer (rockstar) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'entertainer-backend'
2--- entertainer-backend 2009-05-06 02:58:08 +0000
3+++ entertainer-backend 2009-09-08 02:02:58 +0000
4@@ -51,11 +51,7 @@
5 sys.exit(0)
6
7 if len(sys.argv) > 1 and sys.argv[1] == "--foreground":
8- try:
9- backend = BackendServer()
10- except KeyboardInterrupt:
11- backend.quitBackend()
12- sys.exit()
13+ backend = BackendServer()
14 else:
15 print "Entertainer backend starting..."
16 libc = ctypes.CDLL('libc.so.6')
17
18=== modified file 'entertainerlib/backend/backend_server.py'
19--- entertainerlib/backend/backend_server.py 2009-08-23 01:16:18 +0000
20+++ entertainerlib/backend/backend_server.py 2009-09-08 02:02:58 +0000
21@@ -98,7 +98,3 @@
22 self.message_bus.registerMessageHandler(self.media_manager, media_dict)
23 self.logger.debug("Media Manager intialized successfully")
24
25- def quitBackend(self):
26- '''Close the backend server'''
27- self.message_bus.unregisterAllMessageHandlers()
28-
29
30=== modified file 'entertainerlib/backend/core/message_bus.py'
31--- entertainerlib/backend/core/message_bus.py 2009-05-10 17:36:49 +0000
32+++ entertainerlib/backend/core/message_bus.py 2009-09-08 02:02:58 +0000
33@@ -23,12 +23,7 @@
34 When MessageHandler is registered to the MessageBus there is also another
35 parameter besides handler itself. Second parameter is a dictionary that
36 defines MessageTypes that registered handler wants to be notified of and
37- also priorities for those message types.
38-
39- Example of second parameter:
40- dict = {MessageType.FRONTEND_OPENED : MessagePriority.LOW ,
41- MessageType.FRONTEND_CLOSED : MessagePriority.NORMAL }
42- """
43+ also priorities for those message types."""
44
45 # This determines number of message types avaialble. In other words, this
46 # variable tells how many variables is defined in MessageType class.
47@@ -89,12 +84,6 @@
48 self.logger.debug("MessageHandler '" + str(message_handler) +
49 "' unregistered from the message bus.")
50
51- def unregisterAllMessageHandlers(self):
52- """
53- Unregisters all MessageHandler from this MessageBus.
54- """
55- self.message_handlers[:] = []
56-
57 def notifyMessage(self, message):
58 """
59 Emit a new Message to this MessageBus.
60
61=== modified file 'entertainerlib/backend/core/message_type_priority.py'
62--- entertainerlib/backend/core/message_type_priority.py 2009-08-23 01:16:18 +0000
63+++ entertainerlib/backend/core/message_type_priority.py 2009-09-08 00:53:03 +0000
64@@ -15,56 +15,27 @@
65 VERY_LOW = 40
66
67 class MessageType:
68- """
69- Determines all allowed Message types. MessageHandler should use these
70- to determine type. This simply makes code more readable.
71-
72- Example:
73- if message.get_type() == MessageType.FRONTEND_OPENED:
74- do_something_useful()
75- """
76-
77- # Indicates that Preferences UI has been used to update preferences.
78- NOT_USED_7 = 0
79+ """Determines all allowed Message types. MessageHandler should use these to
80+ determine type. This simply makes code more readable."""
81
82 # Indicates that Content Management UI has been used to update contents.
83- CONTENT_CONF_UPDATED = 1
84-
85- # Indicates that client has been opened.
86- FRONTEND_OPENED = 2
87-
88- # Indicates that client has been closed.
89- FRONTEND_CLOSED = 3
90+ CONTENT_CONF_UPDATED = 0
91
92 # Indicates that Feed cache has been updated.
93- FEED_DB_UPDATED = 4
94-
95- NOT_USED_5 = 5
96-
97- NOT_USED_1 = 6
98+ FEED_DB_UPDATED = 1
99
100 # Indicates that Feed cache should be updated.
101- UPDATE_FEEDS = 7
102-
103- NOT_USED_6 = 8
104-
105- #This should be left in otherwise message_bus.py breaks
106- #If another message type is needed please use this
107- DO_NOT_DELETE_USE_NEXT = 9
108-
109- NOT_USED_2 = 10
110- NOT_USED_3 = 11
111- NOT_USED_4 = 12
112+ UPDATE_FEEDS = 2
113
114 # Require to rebuild image cache
115- REBUILD_IMAGE_CACHE = 13
116+ REBUILD_IMAGE_CACHE = 3
117
118 # Require to rebuild music cache
119- REBUILD_MUSIC_CACHE = 14
120+ REBUILD_MUSIC_CACHE = 4
121
122 # Require to rebuild video cache
123- REBUILD_VIDEO_CACHE = 15
124+ REBUILD_VIDEO_CACHE = 5
125
126 # Require to rebuild feed cache
127- REBUILD_FEED_CACHE = 16
128+ REBUILD_FEED_CACHE = 6
129
130
131=== modified file 'entertainerlib/client/backend_connection.py'
132--- entertainerlib/client/backend_connection.py 2009-08-23 01:16:18 +0000
133+++ entertainerlib/client/backend_connection.py 2009-09-08 02:40:16 +0000
134@@ -7,46 +7,21 @@
135 from entertainerlib.backend.core.message_handler import MessageHandler
136
137 class BackendConnection(MessageHandler):
138- """
139- BackendConnection - Connection to the Entertainer backend. Instance from
140- this class is a gate to backend messagebus.
141- """
142+ """Connection to the Entertainer backend messagebus."""
143
144 def __init__(self):
145- """Initialize connection. Connects to backend."""
146- #messages = {
147- # MessageType.CONTENT_CONF_UPDATED : MessagePriority.NORMAL,
148- # MessageType.FEED_DB_UPDATED : MessagePriority.HIGH }
149- # XXX: rockstar - The messages above are the "real" messages, and I'm
150- # not sure why they are commented out. Anyone?
151 MessageHandler.__init__(self)
152 messages = {}
153 name = "Entertainer Frontend"
154 self.message_bus_proxy = MessageBusProxy(messages, self, name)
155 self.message_bus_proxy.connectToMessageBus()
156 self.message_bus_proxy.start()
157- self.message_bus_proxy.sendMessage(
158- Message(MessageType.FRONTEND_OPENED))
159
160 def close_connection(self):
161 """Close connection to backend"""
162- self.message_bus_proxy.sendMessage(
163- Message(MessageType.FRONTEND_CLOSED))
164 self.message_bus_proxy.disconnectFromMessageBus()
165
166 def request_feed_update(self):
167 """Request backend to fetch all feeds from the Internet."""
168 self.message_bus_proxy.sendMessage(Message(MessageType.UPDATE_FEEDS))
169
170- def request_weather_update(self):
171- """Request backend to update weather information from the Internet."""
172- self.message_bus_proxy.sendMessage(Message(MessageType.UPDATE_WEATHER))
173-
174- # Implements MessageHandler interface
175- def handleMessage(self, message):
176- """Handle received messages. (Implements MessageHandler interface)"""
177- if message.get_type() == MessageType.CONTENT_CONF_UPDATED:
178- pass
179- elif message.get_type() == MessageType.FEED_DB_UPDATED:
180- pass
181-
182
183=== modified file 'entertainerlib/client/client.py'
184--- entertainerlib/client/client.py 2009-08-16 21:53:22 +0000
185+++ entertainerlib/client/client.py 2009-09-08 02:40:16 +0000
186@@ -10,49 +10,35 @@
187 from twisted.internet.protocol import ClientCreator
188 from twisted.python.log import startLogging
189
190-
191 from entertainerlib.client.backend_connection import BackendConnection
192-from entertainerlib.gui.user_interface import UserInterface
193 from entertainerlib.client.medialibrary.feeds import FeedLibrary
194 from entertainerlib.client.medialibrary.music import MusicLibrary
195 from entertainerlib.client.medialibrary.images import ImageLibrary
196 from entertainerlib.client.medialibrary.videos import VideoLibrary
197 from entertainerlib.configuration import Configuration
198+from entertainerlib.gui.user_interface import UserInterface
199 from entertainerlib.gui.system_tray_icon import SystemTrayIcon
200-from entertainerlib.logger import Logger
201 from entertainerlib.network.local.client import EntertainerLocalClientProtocol
202
203
204 class Client:
205- '''
206- Entertainer client
207-
208- This is a client application of the Entertainer. Entertainer's client
209+ '''This is a client application of the Entertainer. Entertainer's client
210 hooks into the server, and then provides a user interface for the data the
211- server creates.
212- '''
213+ server creates.'''
214
215 def __init__(self):
216- '''
217- Create a new client.
218-
219- This initializes all client stuff like media librarys, remote
220- control receiver and GUI. After this we just wait user actions.
221- '''
222 config = Configuration()
223- self.logger = Logger().getLogger('client.Client')
224- self.backend_connection = self.initialize_backend_connection()
225+ self.backend_connection = BackendConnection()
226 feed_library = FeedLibrary(self.backend_connection)
227- music_library = MusicLibrary(self.backend_connection)
228- image_library = ImageLibrary(self.backend_connection)
229- video_library = VideoLibrary(self.backend_connection)
230+ music_library = MusicLibrary()
231+ image_library = ImageLibrary()
232+ video_library = VideoLibrary()
233 self.ui = UserInterface(
234 feed_library, image_library, music_library, video_library,
235 self.quit_client)
236
237 if config.tray_icon_enabled:
238- SystemTrayIcon(
239- self.quit_client, self.toggle_interface_visibility)
240+ SystemTrayIcon(self.quit_client, self.toggle_interface_visibility)
241
242 startLogging(sys.stdout)
243 client = EntertainerLocalClientProtocol
244@@ -61,7 +47,6 @@
245 config.network_options['host'],
246 config.network_options['port'])
247
248-
249 def start(self):
250 '''Start the necessary main loop.'''
251 self.ui.start_up()
252@@ -70,13 +55,6 @@
253 reactor.run()
254 gtk.gdk.threads_leave()
255
256- def initialize_backend_connection(self):
257- '''Connect to the backend server.'''
258- backend_connection = BackendConnection()
259- self.logger.debug('Connected to the Entertainer backend server.')
260-
261- return backend_connection
262-
263 def quit_client(self):
264 '''Clean up the connection to the backend then close the client.'''
265 self.backend_connection.close_connection()
266
267=== modified file 'entertainerlib/client/medialibrary/images.py'
268--- entertainerlib/client/medialibrary/images.py 2009-05-10 17:36:49 +0000
269+++ entertainerlib/client/medialibrary/images.py 2009-09-08 02:40:16 +0000
270@@ -7,22 +7,13 @@
271 from entertainerlib.configuration import Configuration
272
273 class ImageLibrary:
274- """
275- Image library.
276-
277- Entertainer's image cache.
278- """
279-
280- def __init__(self, backend_connection):
281- """
282- Initialize image library
283- @param backend_connection: BackendConnection object
284- """
285+ """Entertainer's image cache."""
286+
287+ def __init__(self):
288 self.config = Configuration()
289
290 if not os.path.exists(self.config.IMAGE_DB):
291 raise Exception("Image database doesn't exist!")
292- self.backend_connection = backend_connection
293
294 def get_all_images(self):
295 """
296
297=== modified file 'entertainerlib/client/medialibrary/music.py'
298--- entertainerlib/client/medialibrary/music.py 2009-07-29 03:09:34 +0000
299+++ entertainerlib/client/medialibrary/music.py 2009-09-08 02:40:16 +0000
300@@ -28,22 +28,13 @@
301 pass
302
303 class MusicLibrary:
304- """
305- Music library.
306-
307- Interface for Entertainer's music cache.
308- """
309-
310- def __init__(self, backend_connection):
311- """
312- Initialize library.
313- @param backend_connection: BackendConnection object
314- """
315+ """Interface for Entertainer's music cache."""
316+
317+ def __init__(self):
318 self.config = Configuration()
319
320 if not os.path.exists(self.config.MUSIC_DB):
321 raise Exception("Music database doesn't exist!")
322- self.backend_connection = backend_connection
323 self.db_connection = sqlite.connect(self.config.MUSIC_DB)
324 self.cursor = self.db_connection.cursor()
325
326
327=== modified file 'entertainerlib/client/medialibrary/videos.py'
328--- entertainerlib/client/medialibrary/videos.py 2009-08-16 21:48:15 +0000
329+++ entertainerlib/client/medialibrary/videos.py 2009-09-08 02:40:16 +0000
330@@ -10,22 +10,13 @@
331 from entertainerlib.client.medialibrary.playable import Playable
332
333 class VideoLibrary:
334- """
335- Video library.
336-
337- Interface for Entertainer's video cache.
338- """
339-
340- def __init__(self, backend_connection):
341- """
342- Initialize video library
343- @param backend_connection: BackendConnection object
344- """
345+ """Interface for Entertainer's video cache."""
346+
347+ def __init__(self):
348 self.config = Configuration()
349
350 if not os.path.exists(self.config.VIDEO_DB):
351 raise Exception("Video database doesn't exist!")
352- self.backend_connection = backend_connection
353
354 def get_movies(self):
355 """
356
357=== modified file 'entertainerlib/tests/mock.py'
358--- entertainerlib/tests/mock.py 2009-07-29 03:09:34 +0000
359+++ entertainerlib/tests/mock.py 2009-09-08 02:40:16 +0000
360@@ -6,11 +6,9 @@
361
362 import gobject
363
364-from entertainerlib.client.backend_connection import BackendConnection
365 from entertainerlib.client.medialibrary.feeds import Entry, Feed, FeedLibrary
366 from entertainerlib.client.medialibrary.images import Image, ImageLibrary
367-from entertainerlib.client.medialibrary.music import (Album, MusicLibrary,
368- Track)
369+from entertainerlib.client.medialibrary.music import Album, MusicLibrary, Track
370 from entertainerlib.client.medialibrary.videos import (Movie, TVEpisode,
371 TVSeries, VideoLibrary)
372
373@@ -42,17 +40,6 @@
374 return False
375
376
377-class MockBackendConnection(BackendConnection):
378- '''Mock entertainerlib.client.backend_connection.BackendConnection'''
379-
380- def __init__(self):
381- '''Override init to prevent BackenConnection from attempting to connect
382- to a message bus.'''
383-
384- def close_connection(self):
385- '''See `BackendConnection.close_connection`.'''
386-
387-
388 class MockClutterKeyboardEvent(object):
389 '''Mock clutter keyboard events'''
390
391@@ -128,7 +115,7 @@
392 class MockImageLibrary(ImageLibrary):
393 '''Mock entertainerlib.client.medialibrary.images.ImageLibrary'''
394
395- def __init__(self, backend_connection=None):
396+ def __init__(self):
397 '''Override the intial behavior.'''
398
399 def get_number_of_albums(self):
400@@ -213,7 +200,7 @@
401 class MockMusicLibrary(MusicLibrary):
402 '''Mock entertainerlib.client.medialibrary.music.MusicLibrary'''
403
404- def __init__(self, backend_connection=None):
405+ def __init__(self):
406 '''Override the intial behavior.'''
407
408 def get_albums_by_artist(self, artist=None):
409@@ -305,7 +292,7 @@
410 class MockVideoLibrary(VideoLibrary):
411 '''Mock entertainerlib.client.medialibrary.videos.VideoLibrary'''
412
413- def __init__(self, backend_connection=None):
414+ def __init__(self):
415 '''Override the intial behavior.'''
416
417 def get_number_of_movies(self):
418
419=== modified file 'entertainerlib/tests/test_frontendfeedlibrary.py'
420--- entertainerlib/tests/test_frontendfeedlibrary.py 2009-06-30 01:06:01 +0000
421+++ entertainerlib/tests/test_frontendfeedlibrary.py 2009-09-08 02:40:16 +0000
422@@ -5,7 +5,6 @@
423
424 from entertainerlib.client.medialibrary.feeds import FeedLibrary
425 from entertainerlib.tests import EntertainerTest
426-from entertainerlib.tests.mock import MockBackendConnection
427
428 class FrontendFeedLibraryTest(EntertainerTest):
429 """
430@@ -48,8 +47,7 @@
431 db_conn.commit()
432 db_conn.close()
433
434- self.backend_connection = MockBackendConnection()
435- self.library = FeedLibrary(self.backend_connection)
436+ self.library = FeedLibrary(None)
437
438 def tearDown(self):
439 EntertainerTest.tearDown(self)
440
441=== modified file 'entertainerlib/tests/test_music.py'
442--- entertainerlib/tests/test_music.py 2009-05-10 17:36:49 +0000
443+++ entertainerlib/tests/test_music.py 2009-09-08 02:40:16 +0000
444@@ -8,7 +8,6 @@
445 from entertainerlib.client.medialibrary.music import (
446 Album, AlbumHasNoTracks, MusicLibrary, Track, CompactDisc,
447 TrackRatingOutOfRange, TrackTypeError)
448-from entertainerlib.tests.mock import MockBackendConnection
449 from entertainerlib.client.medialibrary.playable import Playable
450 from entertainerlib.tests import EntertainerTest
451
452@@ -248,12 +247,7 @@
453
454 def setUp(self):
455 TestMusic.setUp(self)
456- self.backend_connection = MockBackendConnection()
457- self.musiclibrary = MusicLibrary(self.backend_connection)
458-
459- def tearDown(self):
460- self.backend_connection.close_connection()
461- TestMusic.tearDown(self)
462+ self.musiclibrary = MusicLibrary()
463
464 def testMusicLibraryConstructor(self):
465 """testMusicLibraryContructor - Ensures instantiation of MusicLibrary

Subscribers

People subscribed via source and target branches