Merge lp:~rodrigo-moya/desktopcouch/no-lsof into lp:desktopcouch

Proposed by Rodrigo Moya
Status: Merged
Approved by: Elliot Murphy
Approved revision: 9
Merged at revision: not available
Proposed branch: lp:~rodrigo-moya/desktopcouch/no-lsof
Merge into: lp:desktopcouch
Diff against target: None lines
To merge this branch: bzr merge lp:~rodrigo-moya/desktopcouch/no-lsof
Reviewer Review Type Date Requested Status
Elliot Murphy (community) Approve
Tim Cole (community) Approve
Review via email: mp+8931@code.launchpad.net

Commit message

[r=statik, r=tcole] Replace lsof hack with dbus call to getPort method

To post a comment you must log in.
Revision history for this message
Rodrigo Moya (rodrigo-moya) wrote :

Resubmitting this again, since some files were moved while it was being approved. It contains the same code as before, plus the 2 import lines which were missing (don't know why, I had them locally, but probably missed them when submitting) in the previous merge proposal

Revision history for this message
Tim Cole (tcole) :
review: Approve
Revision history for this message
Elliot Murphy (statik) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'utilities/start_local_couchdb.py'
2--- utilities/start_local_couchdb.py 2009-07-09 19:44:43 +0000
3+++ utilities/start_local_couchdb.py 2009-07-17 09:40:17 +0000
4@@ -34,6 +34,8 @@
5 from __future__ import with_statement
6 import os, subprocess, sys
7 import local_files
8+import dbus
9+from dbus.exceptions import DBusException
10
11 def dump_ini(data, filename):
12 """Dump INI data with sorted sections and keywords"""
13@@ -107,16 +109,17 @@
14 html = fp.read()
15 fp.close()
16
17- # work out port number the horrible lsof way
18+ # work out port number
19 import time
20 time.sleep(1)
21- lsofcmd = 'lsof -i4TCP@localhost | grep $(couchdb -C %s -p %s -s | ' + \
22- 'cut -d" " -f7 | cut -d "," -f1) | grep "TCP " | ' + \
23- 'grep LISTEN | awk \'{print $8}\' | cut -d":" -f2'
24- actual_lsof_cmd = lsofcmd % (local_files.FILE_INI, local_files.FILE_PID)
25- stdout, stderr = subprocess.Popen(actual_lsof_cmd, shell=True,
26- stdout=subprocess.PIPE).communicate()
27- port = stdout.strip()
28+
29+ try:
30+ bus = dbus.SessionBus()
31+ port_advertiser = bus.get_object("org.desktopcouch.CouchDB", "/")
32+ iface = bus.Interface(port_advertiser, "org.desktopcouch.CouchDB")
33+ port = iface.getPort()
34+ except DBusException:
35+ sys.exit(1)
36
37 fp = open(bookmark_file, "w")
38 fp.write(html.replace("[[COUCHDB_PORT]]", port))

Subscribers

People subscribed via source and target branches