Merge lp:~rockstar/entertainer/client-gtkreactor into lp:entertainer

Proposed by Paul Hummer
Status: Rejected
Rejected by: Paul Hummer
Proposed branch: lp:~rockstar/entertainer/client-gtkreactor
Merge into: lp:entertainer
Diff against target: None lines
To merge this branch: bzr merge lp:~rockstar/entertainer/client-gtkreactor
Reviewer Review Type Date Requested Status
Entertainer Release Team Pending
Review via email: mp+6369@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Paul Hummer (rockstar) wrote :

First of all, this branch is dependent on the package-structure-apocalypse
branch that is currently in review. Please see the review diff, as it's
actually based off what will merge after the dependent branch lands.

This branch does two very small but very important things. The first is that
it creates a server_registry dict that will allow for many types of servers
(like the DLNA system). The selection of which server to use is a config
setting (currently not settable in the UI, since there's only one type right
now). Also, the server's host and port are part of the config as well.

The second, and more significant change is that the Entertainer client now uses
the twisted reactor as its main event loop. It requires some twisted magic to
install some special gtk stuff. So now the client has the ability to make a
connection to the new server, and with the reactor, you'll never know the
difference. In fact, Entertainer still works the exact same as it did before.
Now THAT's magic. :)

Now the real blocker is the indexer stuff, and so that means I need to get
testresources working with Entertainer's tests to provide Configuration object
for all tests.

It's coming together, which is quite encouraging.

--
Paul Hummer
http://theironlion.net
1024/862FF08F C921 E962 58F8 5547 6723 0E8C 1C4D 8AC5 862F F08F

Revision history for this message
Paul Hummer (rockstar) wrote :

Rejecting this merge on the basis that it's supposed to be proposed for merge.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'entertainerlib/client/client.py'
2--- entertainerlib/client/client.py 2009-05-09 03:37:11 +0000
3+++ entertainerlib/client/client.py 2009-05-09 05:24:36 +0000
4@@ -8,6 +8,12 @@
5 import sys
6
7 import gtk
8+from twisted.internet import gtk2reactor
9+gtk2reactor.install() # Install the gtk2 reactor before import the real reactor
10+from twisted.internet import reactor
11+from twisted.internet.protocol import ClientCreator
12+from twisted.python.log import startLogging
13+
14
15 from entertainerlib.client.backend_connection import BackendConnection
16 from entertainerlib.gui.user_interface import UserInterface
17@@ -16,8 +22,10 @@
18 from entertainerlib.client.medialibrary.images import ImageLibrary
19 from entertainerlib.client.medialibrary.videos import VideoLibrary
20 from entertainerlib.configuration import Configuration
21+from entertainerlib.gui.system_tray_icon import SystemTrayIcon
22 from entertainerlib.logger import Logger
23-from entertainerlib.gui.system_tray_icon import SystemTrayIcon
24+from entertainerlib.network.local.client import EntertainerLocalClientProtocol
25+
26
27 class Client:
28 '''
29@@ -50,12 +58,20 @@
30 SystemTrayIcon(
31 self.quit_client, self.toggle_interface_visibility)
32
33+ startLogging(sys.stdout)
34+ client = EntertainerLocalClientProtocol
35+
36+ ClientCreator(reactor, client).connectTCP(
37+ config.network_options['host'],
38+ config.network_options['port'])
39+
40+
41 def start(self):
42 '''Start the necessary main loop.'''
43 self.ui.start_up()
44 self.interface_visible = True
45 gtk.gdk.threads_enter()
46- gtk.main()
47+ reactor.run()
48 gtk.gdk.threads_leave()
49
50 def initialize_backend_connection(self):
51@@ -69,7 +85,7 @@
52 '''Clean up the connection to the backend then close the client.'''
53 self.backend_connection.close_connection()
54
55- gtk.main_quit()
56+ reactor.stop()
57 sys.exit(0)
58
59 def toggle_interface_visibility(self):
60
61=== modified file 'entertainerlib/configuration.py'
62--- entertainerlib/configuration.py 2009-05-06 05:37:53 +0000
63+++ entertainerlib/configuration.py 2009-05-09 05:26:08 +0000
64@@ -103,6 +103,12 @@
65 self.stage_width = None
66 self.stage_height = None
67
68+ # Network options specify the server type and extra options
69+ self.network_options = {
70+ 'type': 'local',
71+ 'host': 'localhost',
72+ 'port': 55545}
73+
74 def create_cfg_dir(self):
75 '''Create a configuration directory and default config files.'''
76
77
78=== modified file 'entertainerlib/network/__init__.py'
79--- entertainerlib/network/__init__.py 2009-04-30 01:11:22 +0000
80+++ entertainerlib/network/__init__.py 2009-05-09 05:24:36 +0000
81@@ -5,34 +5,25 @@
82 from twisted.internet.protocol import ClientCreator
83 from twisted.python.log import startLogging
84
85+from entertainerlib.configuration import Configuration
86 from entertainerlib.network.local.server import EntertainerLocalServer
87 from entertainerlib.network.local.client import EntertainerLocalClientProtocol
88
89+
90+# New server types must be registered here.
91+server_registry = {
92+ 'local': EntertainerLocalServer}
93+
94 # Entertainer really needs a good absctractable way to handle command line
95 # arguments.
96 def server_main(*args, **kwargs):
97 '''Entertainer Server main function.'''
98- # When multiple server types are supported, the following variable will be
99- # more dynamic.
100- startLogging(sys.stdout)
101- server_type = EntertainerLocalServer
102-
103- server = server_type()
104- # TODO: This port number could probably be a config var.
105- reactor.listenTCP(5545, server)
106- reactor.run()
107-
108-
109-def client_main():
110- '''Entertainer test client code.
111-
112- This code will go away when what is now the client is made into a true
113- client.
114- '''
115- startLogging(sys.stdout)
116- client = EntertainerLocalClientProtocol
117-
118- ClientCreator(reactor, client).connectTCP(
119- 'localhost', 5545)
120+ startLogging(sys.stdout)
121+ config = Configuration()
122+ server = server_registry.get(
123+ config.network_options['type'])
124+
125+ server = server()
126+ reactor.listenTCP(config.network_options['port'], server)
127 reactor.run()
128

Subscribers

People subscribed via source and target branches