Merge lp:~mandel/desktopcouch/reactor_already_installed into lp:desktopcouch

Proposed by Manuel de la Peña
Status: Merged
Approved by: Natalia Bidart
Approved revision: 200
Merged at revision: 196
Proposed branch: lp:~mandel/desktopcouch/reactor_already_installed
Merge into: lp:desktopcouch
Diff against target: 137 lines (+32/-23)
3 files modified
bin/desktopcouch-service (+4/-0)
desktopcouch/platform/__init__.py (+11/-6)
desktopcouch/platform/linux/__init__.py (+17/-17)
To merge this branch: bzr merge lp:~mandel/desktopcouch/reactor_already_installed
Reviewer Review Type Date Requested Status
Natalia Bidart (community) Approve
Alejandro J. Cura (community) Approve
Review via email: mp+40004@code.launchpad.net

Commit message

Fix lp:670562 by moving the reactor installation to the service start code.

Description of the change

Fix lp:670562 by moving the reactor installation to the service start code.

To post a comment you must log in.
Revision history for this message
Alejandro J. Cura (alecu) :
review: Approve
198. By Manuel de la Peña

Fix lint errors.

199. By Manuel de la Peña

Remove pairing, there was an error in a previous merge, this hsould not be here :(

200. By Manuel de la Peña

Fixed lint issues.

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

I'm getting the error reported un bug #670600.

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Other than the test failure reported before, the reactor already register issue is solved.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/desktopcouch-service'
2--- bin/desktopcouch-service 2010-10-31 21:37:35 +0000
3+++ bin/desktopcouch-service 2010-11-03 20:07:19 +0000
4@@ -36,6 +36,10 @@
5
6 from desktopcouch.platform import init_mainloop
7 from desktopcouch.service import DesktopcouchService
8+# TODO: This should not be here, what if we do not use
9+# twisted?
10+from twisted.internet import glib2reactor
11+glib2reactor.install()
12
13 if __name__ == "__main__":
14 # create the service object that will host the operations
15
16=== modified file 'desktopcouch/platform/__init__.py'
17--- desktopcouch/platform/__init__.py 2010-11-01 19:13:27 +0000
18+++ desktopcouch/platform/__init__.py 2010-11-03 20:07:19 +0000
19@@ -2,22 +2,27 @@
20 import sys
21
22 if sys.platform == "win32":
23- from desktopcouch.platform.windows import *
24+ pass
25 else:
26 # install the correct reactor for linux
27- from twisted.internet import glib2reactor
28- glib2reactor.install()
29- from desktopcouch.platform.linux import *
30- from desktopcouch.platform.linux.ipc import *
31- from desktopcouch.platform.linux.keyring import *
32+ from desktopcouch.platform.linux import (
33+ process_is_couchdb, platform_read_pidfile,
34+ platform_find_pid, platform_find_port,
35+ set_application_name, init_mainloop,
36+ direct_access_find_port)
37+ from desktopcouch.platform.linux.ipc import PortAdvertiser
38+ from desktopcouch.platform.linux.keyring import Keyring
39
40 from desktopcouch.local_files import DEFAULT_CONTEXT
41
42 def read_pidfile(ctx=DEFAULT_CONTEXT):
43+ """Read the pid file of couchdb in the executing ctx."""
44 return platform_read_pidfile(ctx)
45
46 def find_pid(start_if_not_running=True, ctx=DEFAULT_CONTEXT):
47+ """Find the process id of the currently executing couchdb."""
48 return platform_find_pid(start_if_not_running, ctx)
49
50 def find_port(pid=None, ctx=DEFAULT_CONTEXT):
51+ """Find the port where couchdb is listening for the current ctx."""
52 return platform_find_port(pid, ctx)
53
54=== modified file 'desktopcouch/platform/linux/__init__.py'
55--- desktopcouch/platform/linux/__init__.py 2010-11-01 19:13:27 +0000
56+++ desktopcouch/platform/linux/__init__.py 2010-11-03 20:07:19 +0000
57@@ -22,7 +22,6 @@
58 import dbus
59 import logging
60 import platform
61-import os
62
63
64 def process_is_couchdb(pid):
65@@ -53,17 +52,17 @@
66 pid_file = ctx.file_pid
67 if not os.path.exists(pid_file):
68 return None
69- with open(pid_file) as fp:
70+ with open(pid_file) as file_descriptor:
71 try:
72- contents = fp.read()
73+ contents = file_descriptor.read()
74 if contents == "\n":
75 return None # not yet written to pid file
76 return int(contents)
77 except ValueError:
78 logging.warn("Pid file does not contain int: %r", contents)
79 return None
80- except IOError, e:
81- logging.warn("Reading pid file caused error. %s", e)
82+ except IOError, exception:
83+ logging.warn("Reading pid file caused error. %s", exception)
84 return None
85
86
87@@ -81,7 +80,6 @@
88 # now load the design documents and pair records updates,
89 # because it's started
90 start_local_couchdb.update_design_documents()
91- start_local_couchdb.update_pairing_service()
92 if not process_is_couchdb(pid):
93 logging.error("CouchDB process did not start up")
94 raise RuntimeError("desktop-couch not started")
95@@ -104,12 +102,12 @@
96 #### method-response. Once that is worked out, resume using the
97 #### rest of this function instead of the direct access above.
98 # Hrm, we don't use 'pid' or 'ctx' any more, since we go through DBus.
99- if ctx != local_files.DEFAULT_CONTEXT or pid is not None:
100- return direct_access_find_port(pid=pid, ctx=ctx)
101-
102- bus = dbus.SessionBus()
103- proxy = bus.get_object('org.desktopcouch.CouchDB', '/')
104- return proxy.getPort()
105+### if ctx != local_files.DEFAULT_CONTEXT or pid is not None:
106+### return direct_access_find_port(pid=pid, ctx=ctx)
107+###
108+### bus = dbus.SessionBus()
109+### proxy = bus.get_object('org.desktopcouch.CouchDB', '/')
110+### return proxy.getPort()
111 ####
112 #### ^^
113
114@@ -142,16 +140,18 @@
115 except OSError:
116 if retries_left:
117 return direct_access_find_port(pid, ctx, retries_left - 1)
118- logging.exception("Unable to find file descriptors in %s" % proc_dir)
119+ logging.exception("Unable to find file descriptors in %s",
120+ proc_dir)
121 raise RuntimeError("Unable to find file descriptors in %s" % proc_dir)
122
123 # identify socket fds
124- socket_matches = [re.match('socket:\\[([0-9]+)\\]', p) for p in fd_paths]
125- # extract their inode numbers
126- socket_inodes = [m.group(1) for m in socket_matches if m is not None]
127+ socket_matches = (re.match('socket:\\[([0-9]+)\\]', p) for p in fd_paths)
128
129 # construct a subexpression which matches any one of these inodes
130- inode_subexp = "|".join(map(re.escape, socket_inodes))
131+ inode_subexp = "|".join(
132+ re.escape(m.group(1))
133+ for m in socket_matches
134+ if m is not None)
135 # construct regexp to match /proc/net/tcp entries which are listening
136 # sockets having one of the given inode numbers
137 listening_regexp = re.compile(r'''

Subscribers

People subscribed via source and target branches