Merge lp:~cmiller/desktopcouch/code-split-changes-relative-path-to-configs into lp:desktopcouch

Proposed by Chad Miller
Status: Merged
Approved by: dobey
Approved revision: 221
Merged at revision: 221
Proposed branch: lp:~cmiller/desktopcouch/code-split-changes-relative-path-to-configs
Merge into: lp:desktopcouch
Diff against target: 95 lines (+24/-14)
2 files modified
desktopcouch/application/start_local_couchdb.py (+13/-14)
desktopcouch/application/tests/test_local_files.py (+11/-0)
To merge this branch: bzr merge lp:~cmiller/desktopcouch/code-split-changes-relative-path-to-configs
Reviewer Review Type Date Requested Status
dobey (community) Approve
Eric Casteleijn (community) Approve
Review via email: mp+41515@code.launchpad.net

Commit message

Fix a problem with splitting code into packages. The relative path to config directories was no longer valid.

To post a comment you must log in.
Revision history for this message
Eric Casteleijn (thisfred) wrote :

Awesome job, looks good.

line 193 in start_local_couchdb.py is too long now, if you fix that +1

review: Approve
Revision history for this message
dobey (dobey) wrote :

The path string should be built with os.path.join() so that it also works correctly on other platforms that don't use / as the separator character.

review: Needs Fixing
219. By Chad Miller

Use OS-independent functions to locate files.

220. By Chad Miller

Fix minor lint complaint about exception instance names.

221. By Chad Miller

Remove debugging statement.

Revision history for this message
dobey (dobey) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'desktopcouch/application/start_local_couchdb.py'
2--- desktopcouch/application/start_local_couchdb.py 2010-11-22 18:21:40 +0000
3+++ desktopcouch/application/start_local_couchdb.py 2010-11-23 19:56:32 +0000
4@@ -67,16 +67,16 @@
5 try:
6 retcode = proc.wait()
7 break
8- except OSError, e:
9- if e.errno == errno.EINTR:
10+ except OSError, ex:
11+ if ex.errno == errno.EINTR:
12 continue
13 raise
14 if retcode < 0:
15 print >> sys.stderr, "Child was terminated by signal", -retcode
16 elif retcode > 0:
17 print >> sys.stderr, "Child returned", retcode
18- except OSError, e:
19- print >> sys.stderr, "Execution failed: %s: %s" % (e, local_exec)
20+ except OSError, ex:
21+ print >> sys.stderr, "Execution failed: %s: %s" % (ex, local_exec)
22 exit(1)
23
24 # give the process a chance to start
25@@ -99,13 +99,13 @@
26 port = find_port(pid=pid, ctx=ctx)
27 # returns valid port, or raises exception
28 break
29- except RuntimeError, e:
30+ except RuntimeError:
31 pass
32
33 try:
34 # Send no signal, merely test PID existence.
35 os.kill(pid, 0)
36- except OSError, e:
37+ except OSError:
38 raise RuntimeError("Couchdb PID%d exited. Permissions?" % (pid,))
39
40 time.sleep(timeout)
41@@ -193,16 +193,15 @@
42 raise IOError(
43 "Bookmark file is corrupt. Username/password are missing.")
44
45- if os.path.exists(
46- os.path.join(os.path.split(__file__)[0], "../data/couchdb.tmpl")):
47- bookmark_template = os.path.join(
48- os.path.split(__file__)[0], "../data/couchdb.tmpl")
49+ src_tmpl = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir,
50+ "data", "couchdb.tmpl")
51+ if os.path.exists(src_tmpl):
52+ bookmark_template = src_tmpl
53 else:
54 for base in xdg.BaseDirectory.xdg_data_dirs:
55 template_path = os.path.join(base, "desktopcouch", "couchdb.tmpl")
56 if os.path.exists(template_path):
57- bookmark_template = os.path.join(
58- os.path.split(__file__)[0], template_path)
59+ bookmark_template = os.path.abspath(template_path)
60
61 fp = open(bookmark_template)
62 html = fp.read()
63@@ -229,8 +228,8 @@
64 try:
65 pid, port = run_couchdb(ctx=ctx)
66 break
67- except RuntimeError, e:
68- saved_exception = e
69+ except RuntimeError, ex:
70+ saved_exception = ex
71 logging.exception("Starting couchdb failed on try %d", (retry,))
72 time.sleep(1)
73 continue
74
75=== modified file 'desktopcouch/application/tests/test_local_files.py'
76--- desktopcouch/application/tests/test_local_files.py 2010-11-19 00:45:03 +0000
77+++ desktopcouch/application/tests/test_local_files.py 2010-11-23 19:56:32 +0000
78@@ -22,6 +22,17 @@
79 cf = test_environment.test_context.configuration
80 # Test loading from file.
81 cf._fill_from_file(test_environment.test_context.file_ini)
82+ self.xdg_path = os.environ.get("XDG_CONFIG_DIRS")
83+ os.environ["XDG_CONFIG_DIRS"] = os.path.join(
84+ os.path.dirname(__file__), os.pardir, os.pardir,
85+ os.pardir, "config")
86+
87+ def tearDown(self):
88+ super(TestLocalFiles, self).tearDown()
89+ if self.xdg_path is None:
90+ del os.environ["XDG_CONFIG_DIRS"]
91+ else:
92+ os.environ["XDG_CONFIG_DIRS"] = self.xdg_path
93
94 def test_all_files_returned(self):
95 """Check local_files lists all the files that it needs to."""

Subscribers

People subscribed via source and target branches