Merge lp://qastaging/~cmiller/desktopcouch/config-file-clean-up into lp://qastaging/desktopcouch
- config-file-clean-up
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Chad Miller |
Approved revision: | not available |
Merged at revision: | not available |
Proposed branch: | lp://qastaging/~cmiller/desktopcouch/config-file-clean-up |
Merge into: | lp://qastaging/desktopcouch |
Diff against target: |
423 lines (+159/-148) 4 files modified
desktopcouch/local_files.py (+151/-44) desktopcouch/records/server.py (+1/-1) desktopcouch/start_local_couchdb.py (+2/-99) desktopcouch/tests/test_local_files.py (+5/-4) |
To merge this branch: | bzr merge lp://qastaging/~cmiller/desktopcouch/config-file-clean-up |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Nicola Larosa (community) | Approve | ||
Tim Cole (community) | Approve | ||
Review via email:
|
Commit message
Do not read from the keyring if we have a configuration file that has the information we need.
Move config file manipulation into execution-context code. Make all config access go though explicit context of execution.
Simplify config-value getting and setting.
Hard-code port for new configurations, since we are very unlikely to use a value other than zero.
Description of the change
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Nicola Larosa (teknico) wrote : | # |
Tests pass, nice code. Thanks for taking code out of exec scripts and into lib files: even more code can be moved, though. ;-)
I don't like static methods, why not just using functions outside classes? Especially for something like "_make_
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Chad Miller (cmiller) wrote : | # |
Attempt to merge lp:~cmiller/desktopcouch/config-file-clean-up into lp:desktopcouch failed due to merge conflicts:
text conflict in desktopcouch/
- 107. By Chad Miller
-
Merge to trunk.
Preview Diff
1 | === modified file 'desktopcouch/local_files.py' | |||
2 | --- desktopcouch/local_files.py 2009-11-24 13:11:54 +0000 | |||
3 | +++ desktopcouch/local_files.py 2009-11-27 03:36:11 +0000 | |||
4 | @@ -26,6 +26,10 @@ | |||
5 | 26 | import xdg.BaseDirectory as xdg_base_dirs | 26 | import xdg.BaseDirectory as xdg_base_dirs |
6 | 27 | import subprocess | 27 | import subprocess |
7 | 28 | import logging | 28 | import logging |
8 | 29 | import tempfile | ||
9 | 30 | import random | ||
10 | 31 | import string | ||
11 | 32 | import gnomekeyring | ||
12 | 29 | try: | 33 | try: |
13 | 30 | import ConfigParser as configparser | 34 | import ConfigParser as configparser |
14 | 31 | except ImportError: | 35 | except ImportError: |
15 | @@ -41,6 +45,128 @@ | |||
16 | 41 | raise ImportError("Could not find couchdb") | 45 | raise ImportError("Could not find couchdb") |
17 | 42 | 46 | ||
18 | 43 | 47 | ||
19 | 48 | class _Configuration(object): | ||
20 | 49 | def __init__(self, ctx): | ||
21 | 50 | super(_Configuration, self).__init__() | ||
22 | 51 | self.file_name_used = ctx.file_ini | ||
23 | 52 | self._c = configparser.SafeConfigParser() | ||
24 | 53 | # monkeypatch ConfigParser to stop it lower-casing option names | ||
25 | 54 | self._c.optionxform = lambda s: s | ||
26 | 55 | |||
27 | 56 | try: | ||
28 | 57 | self._fill_from_file(self.file_name_used) | ||
29 | 58 | return | ||
30 | 59 | except (IOError,): | ||
31 | 60 | pass # Loading failed. Let's fill it with sensible defaults. | ||
32 | 61 | |||
33 | 62 | try: | ||
34 | 63 | data = gnomekeyring.find_items_sync(gnomekeyring.ITEM_GENERIC_SECRET, | ||
35 | 64 | {'desktopcouch': 'basic'}) | ||
36 | 65 | admin_username, admin_password = data[0].secret.split(":", 1) | ||
37 | 66 | except gnomekeyring.NoMatchError: | ||
38 | 67 | admin_username = self._make_random_string(10) | ||
39 | 68 | admin_password = _self._make_random_string(10) | ||
40 | 69 | |||
41 | 70 | try: | ||
42 | 71 | # save admin account details in keyring | ||
43 | 72 | item_id = gnomekeyring.item_create_sync(None, | ||
44 | 73 | gnomekeyring.ITEM_GENERIC_SECRET, | ||
45 | 74 | 'Desktop Couch user authentication', | ||
46 | 75 | {'desktopcouch': 'basic'}, | ||
47 | 76 | ":".join([admin_username, admin_password]), True) | ||
48 | 77 | except gnomekeyring.NoKeyringDaemonError: | ||
49 | 78 | logging.warn("There is no keyring to store our admin credentials.") | ||
50 | 79 | |||
51 | 80 | consumer_key = self._make_random_string(10) | ||
52 | 81 | consumer_secret = self._make_random_string(10) | ||
53 | 82 | token = self._make_random_string(10) | ||
54 | 83 | token_secret = self._make_random_string(10) | ||
55 | 84 | |||
56 | 85 | # Save the new OAuth creds so that 3rd-party apps can authenticate by | ||
57 | 86 | # accessing the keyring first. This is one-way. We don't read from keyring. | ||
58 | 87 | item_id = gnomekeyring.item_create_sync( | ||
59 | 88 | None, gnomekeyring.ITEM_GENERIC_SECRET, | ||
60 | 89 | 'Desktop Couch user authentication', {'desktopcouch': 'oauth'}, | ||
61 | 90 | ":".join([consumer_key, consumer_secret, token, token_secret]), | ||
62 | 91 | True) | ||
63 | 92 | |||
64 | 93 | local = { | ||
65 | 94 | 'couchdb': { | ||
66 | 95 | 'database_dir': ctx.db_dir, | ||
67 | 96 | 'view_index_dir': ctx.db_dir, | ||
68 | 97 | }, | ||
69 | 98 | 'httpd': { | ||
70 | 99 | 'bind_address': '127.0.0.1', | ||
71 | 100 | 'port': '0', | ||
72 | 101 | }, | ||
73 | 102 | 'log': { | ||
74 | 103 | 'file': ctx.file_log, | ||
75 | 104 | 'level': ctx.couchdb_log_level, | ||
76 | 105 | }, | ||
77 | 106 | 'admins': { | ||
78 | 107 | admin_username: admin_password | ||
79 | 108 | }, | ||
80 | 109 | 'oauth_consumer_secrets': { | ||
81 | 110 | consumer_key: consumer_secret | ||
82 | 111 | }, | ||
83 | 112 | 'oauth_token_secrets': { | ||
84 | 113 | token: token_secret | ||
85 | 114 | }, | ||
86 | 115 | 'oauth_token_users': { | ||
87 | 116 | token: admin_username | ||
88 | 117 | }, | ||
89 | 118 | 'couch_httpd_auth': { | ||
90 | 119 | 'require_valid_user': 'true' | ||
91 | 120 | } | ||
92 | 121 | } | ||
93 | 122 | |||
94 | 123 | self._fill_from_structure(local) | ||
95 | 124 | self.save_to_file(self.file_name_used) | ||
96 | 125 | |||
97 | 126 | # randomly generate tokens and usernames | ||
98 | 127 | @staticmethod | ||
99 | 128 | def _make_random_string(count): | ||
100 | 129 | entropy = random.SystemRandom() | ||
101 | 130 | return ''.join([entropy.choice(string.letters) for x in range(count)]) | ||
102 | 131 | |||
103 | 132 | def _fill_from_structure(self, structure): | ||
104 | 133 | for section_name in structure: | ||
105 | 134 | for key in structure[section_name]: | ||
106 | 135 | self.set_item(section_name, key, structure[section_name][key]) | ||
107 | 136 | |||
108 | 137 | def _fill_from_file(self, file_name): | ||
109 | 138 | with file(file_name) as f: | ||
110 | 139 | self._c.readfp(f) | ||
111 | 140 | |||
112 | 141 | def save_to_file(self, file_name): | ||
113 | 142 | container = os.path.split(file_name)[0] | ||
114 | 143 | fd, temp_file_name = tempfile.mkstemp(dir=container) | ||
115 | 144 | f = os.fdopen(fd, "w") | ||
116 | 145 | try: | ||
117 | 146 | self._c.write(f) | ||
118 | 147 | finally: | ||
119 | 148 | f.close() | ||
120 | 149 | os.rename(temp_file_name, file_name) | ||
121 | 150 | |||
122 | 151 | def items_in_section(self, section_name): | ||
123 | 152 | try: | ||
124 | 153 | return self._c.items(section_name) | ||
125 | 154 | except configparser.NoSectionError: | ||
126 | 155 | raise ValueError("Section %r not present." % (section_name,)) | ||
127 | 156 | |||
128 | 157 | def set_item(self, section_name, key, value): | ||
129 | 158 | if not self._c.has_section(section_name): | ||
130 | 159 | self._c.add_section(section_name) | ||
131 | 160 | self._c.set(section_name, key, value) | ||
132 | 161 | |||
133 | 162 | def sync(self): | ||
134 | 163 | """Write back to the file named when we tried to read in init.""" | ||
135 | 164 | self.save_to_file(self.file_name_used) | ||
136 | 165 | |||
137 | 166 | def __str__(self): | ||
138 | 167 | return self.file_name_used | ||
139 | 168 | |||
140 | 169 | |||
141 | 44 | class Context(): | 170 | class Context(): |
142 | 45 | """A mimic of xdg BaseDirectory, with overridable values that do not | 171 | """A mimic of xdg BaseDirectory, with overridable values that do not |
143 | 46 | depend on environment variables.""" | 172 | depend on environment variables.""" |
144 | @@ -71,6 +197,7 @@ | |||
145 | 71 | '-o', self.file_stdout, | 197 | '-o', self.file_stdout, |
146 | 72 | '-e', self.file_stderr] | 198 | '-e', self.file_stderr] |
147 | 73 | 199 | ||
148 | 200 | self.configuration = _Configuration(self) | ||
149 | 74 | 201 | ||
150 | 75 | def ensure_files_not_readable(self): | 202 | def ensure_files_not_readable(self): |
151 | 76 | for descr in ("ini", "pid", "log", "stdout", "stderr",): | 203 | for descr in ("ini", "pid", "log", "stdout", "stderr",): |
152 | @@ -113,13 +240,11 @@ | |||
153 | 113 | 240 | ||
154 | 114 | return chain | 241 | return chain |
155 | 115 | 242 | ||
156 | 116 | |||
157 | 117 | DEFAULT_CONTEXT = Context( | 243 | DEFAULT_CONTEXT = Context( |
158 | 118 | os.path.join(xdg_base_dirs.xdg_cache_home, "desktop-couch"), | 244 | os.path.join(xdg_base_dirs.xdg_cache_home, "desktop-couch"), |
159 | 119 | xdg_base_dirs.save_data_path("desktop-couch"), | 245 | xdg_base_dirs.save_data_path("desktop-couch"), |
160 | 120 | xdg_base_dirs.save_config_path("desktop-couch")) | 246 | xdg_base_dirs.save_config_path("desktop-couch")) |
161 | 121 | 247 | ||
162 | 122 | |||
163 | 123 | class NoOAuthTokenException(Exception): | 248 | class NoOAuthTokenException(Exception): |
164 | 124 | def __init__(self, file_name): | 249 | def __init__(self, file_name): |
165 | 125 | super(Exception, self).__init__() | 250 | super(Exception, self).__init__() |
166 | @@ -128,7 +253,10 @@ | |||
167 | 128 | return "OAuth details were not found in the ini file (%s)" % ( | 253 | return "OAuth details were not found in the ini file (%s)" % ( |
168 | 129 | self.file_name) | 254 | self.file_name) |
169 | 130 | 255 | ||
171 | 131 | def get_oauth_tokens(config_file_name=None): | 256 | def get_admin_credentials(ctx=DEFAULT_CONTEXT): |
172 | 257 | return ctx.configuration.items_in_section("admins")[0] # return first tuple | ||
173 | 258 | |||
174 | 259 | def get_oauth_tokens(ctx=DEFAULT_CONTEXT): | ||
175 | 132 | """Return the OAuth tokens from the desktop Couch ini file. | 260 | """Return the OAuth tokens from the desktop Couch ini file. |
176 | 133 | CouchDB OAuth is two-legged OAuth (not three-legged like most OAuth). | 261 | CouchDB OAuth is two-legged OAuth (not three-legged like most OAuth). |
177 | 134 | We have one "consumer", defined by a consumer_key and a secret, | 262 | We have one "consumer", defined by a consumer_key and a secret, |
178 | @@ -138,55 +266,34 @@ | |||
179 | 138 | (More traditional 3-legged OAuth starts with a "request token" which is | 266 | (More traditional 3-legged OAuth starts with a "request token" which is |
180 | 139 | then used to procure an "access token". We do not require this.) | 267 | then used to procure an "access token". We do not require this.) |
181 | 140 | """ | 268 | """ |
182 | 141 | if config_file_name is None: | ||
183 | 142 | config_file_name = DEFAULT_CONTEXT.file_ini | ||
184 | 143 | 269 | ||
189 | 144 | c = configparser.ConfigParser() | 270 | cf = ctx.configuration |
186 | 145 | # monkeypatch ConfigParser to stop it lower-casing option names | ||
187 | 146 | c.optionxform = lambda s: s | ||
188 | 147 | c.read(config_file_name) | ||
190 | 148 | try: | 271 | try: |
193 | 149 | oauth_token_secrets = c.items("oauth_token_secrets") | 272 | oauth_token_secrets = cf.items_in_section("oauth_token_secrets")[0] |
194 | 150 | oauth_consumer_secrets = c.items("oauth_consumer_secrets") | 273 | oauth_consumer_secrets = cf.items_in_section("oauth_consumer_secrets")[0] |
195 | 151 | except configparser.NoSectionError: | 274 | except configparser.NoSectionError: |
197 | 152 | raise NoOAuthTokenException(config_file_name) | 275 | raise NoOAuthTokenException(cf) |
198 | 276 | except IndexError: | ||
199 | 277 | raise NoOAuthTokenException(cf) | ||
200 | 153 | if not oauth_token_secrets or not oauth_consumer_secrets: | 278 | if not oauth_token_secrets or not oauth_consumer_secrets: |
202 | 154 | raise NoOAuthTokenException(config_file_name) | 279 | raise NoOAuthTokenException(cf) |
203 | 155 | try: | 280 | try: |
204 | 156 | out = { | 281 | out = { |
209 | 157 | "token": oauth_token_secrets[0][0], | 282 | "token": oauth_token_secrets[0], |
210 | 158 | "token_secret": oauth_token_secrets[0][1], | 283 | "token_secret": oauth_token_secrets[1], |
211 | 159 | "consumer_key": oauth_consumer_secrets[0][0], | 284 | "consumer_key": oauth_consumer_secrets[0], |
212 | 160 | "consumer_secret": oauth_consumer_secrets[0][1] | 285 | "consumer_secret": oauth_consumer_secrets[1] |
213 | 161 | } | 286 | } |
214 | 162 | except IndexError: | 287 | except IndexError: |
216 | 163 | raise NoOAuthTokenException(config_file_name) | 288 | raise NoOAuthTokenException(cf) |
217 | 164 | return out | 289 | return out |
218 | 165 | 290 | ||
220 | 166 | def get_bind_address(config_file_name=None): | 291 | def get_bind_address(ctx=DEFAULT_CONTEXT): |
221 | 167 | """Retreive a string if it exists, or None if it doesn't.""" | 292 | """Retreive a string if it exists, or None if it doesn't.""" |
247 | 168 | if config_file_name is None: | 293 | for k, v in ctx.configuration.items_in_section("httpd"): |
248 | 169 | config_file_name = DEFAULT_CONTEXT.file_ini | 294 | if k == "bind_address": |
249 | 170 | 295 | return v | |
250 | 171 | c = configparser.ConfigParser() | 296 | |
251 | 172 | try: | 297 | def set_bind_address(address, ctx=DEFAULT_CONTEXT): |
252 | 173 | c.read(config_file_name) | 298 | ctx.configuration.set_item("httpd", "bind_address", address) |
253 | 174 | return c.get("httpd", "bind_address") | 299 | ctx.configuration.sync() |
229 | 175 | except (configparser.NoOptionError, OSError), e: | ||
230 | 176 | logging.warn("config file %r error. %s", config_file_name, e) | ||
231 | 177 | return None | ||
232 | 178 | |||
233 | 179 | def set_bind_address(address, config_file_name=None): | ||
234 | 180 | if config_file_name is None: | ||
235 | 181 | config_file_name = DEFAULT_CONTEXT.file_ini | ||
236 | 182 | |||
237 | 183 | c = configparser.SafeConfigParser() | ||
238 | 184 | # monkeypatch ConfigParser to stop it lower-casing option names | ||
239 | 185 | c.optionxform = lambda s: s | ||
240 | 186 | c.read(config_file_name) | ||
241 | 187 | if not c.has_section("httpd"): | ||
242 | 188 | c.add_section("httpd") | ||
243 | 189 | c.set("httpd", "bind_address", address) | ||
244 | 190 | with open(config_file_name, 'wb') as configfile: | ||
245 | 191 | c.write(configfile) | ||
246 | 192 | |||
254 | 193 | 300 | ||
255 | === modified file 'desktopcouch/records/server.py' | |||
256 | --- desktopcouch/records/server.py 2009-11-11 16:24:22 +0000 | |||
257 | +++ desktopcouch/records/server.py 2009-11-27 03:36:11 +0000 | |||
258 | @@ -36,7 +36,7 @@ | |||
259 | 36 | if ctx is None: | 36 | if ctx is None: |
260 | 37 | ctx = desktopcouch.local_files.DEFAULT_CONTEXT | 37 | ctx = desktopcouch.local_files.DEFAULT_CONTEXT |
261 | 38 | if oauth_tokens is None: | 38 | if oauth_tokens is None: |
263 | 39 | oauth_tokens = desktopcouch.local_files.get_oauth_tokens(ctx.file_ini) | 39 | oauth_tokens = desktopcouch.local_files.get_oauth_tokens(ctx) |
264 | 40 | (consumer_key, consumer_secret, token, token_secret) = ( | 40 | (consumer_key, consumer_secret, token, token_secret) = ( |
265 | 41 | oauth_tokens["consumer_key"], oauth_tokens["consumer_secret"], | 41 | oauth_tokens["consumer_key"], oauth_tokens["consumer_secret"], |
266 | 42 | oauth_tokens["token"], oauth_tokens["token_secret"]) | 42 | oauth_tokens["token"], oauth_tokens["token_secret"]) |
267 | 43 | 43 | ||
268 | === modified file 'desktopcouch/start_local_couchdb.py' | |||
269 | --- desktopcouch/start_local_couchdb.py 2009-11-24 17:27:27 +0000 | |||
270 | +++ desktopcouch/start_local_couchdb.py 2009-11-27 03:36:11 +0000 | |||
271 | @@ -33,7 +33,7 @@ | |||
272 | 33 | """ | 33 | """ |
273 | 34 | 34 | ||
274 | 35 | from __future__ import with_statement | 35 | from __future__ import with_statement |
276 | 36 | import os, subprocess, sys, glob, random, string | 36 | import os, subprocess, sys, glob |
277 | 37 | import desktopcouch | 37 | import desktopcouch |
278 | 38 | from desktopcouch import local_files | 38 | from desktopcouch import local_files |
279 | 39 | import xdg.BaseDirectory | 39 | import xdg.BaseDirectory |
280 | @@ -43,103 +43,6 @@ | |||
281 | 43 | import logging | 43 | import logging |
282 | 44 | import itertools | 44 | import itertools |
283 | 45 | 45 | ||
284 | 46 | ACCEPTABLE_USERNAME_PASSWORD_CHARS = string.lowercase + string.uppercase | ||
285 | 47 | |||
286 | 48 | def dump_ini(data, filename): | ||
287 | 49 | """Dump INI data with sorted sections and keywords""" | ||
288 | 50 | fd = open(filename, 'w') | ||
289 | 51 | sections = data.keys() | ||
290 | 52 | sections.sort() | ||
291 | 53 | for section in sections: | ||
292 | 54 | fd.write("[%s]\n" % (section)) | ||
293 | 55 | keys = data[section].keys() | ||
294 | 56 | keys.sort() | ||
295 | 57 | for key in keys: | ||
296 | 58 | fd.write("%s=%s\n" % (key, data[section][key])) | ||
297 | 59 | fd.write("\n") | ||
298 | 60 | fd.close() | ||
299 | 61 | |||
300 | 62 | def create_ini_file(port="0", ctx=local_files.DEFAULT_CONTEXT): | ||
301 | 63 | """Write CouchDB ini file if not already present""" | ||
302 | 64 | |||
303 | 65 | if os.path.exists(ctx.file_ini): | ||
304 | 66 | # load the username and password from the keyring | ||
305 | 67 | try: | ||
306 | 68 | data = gnomekeyring.find_items_sync(gnomekeyring.ITEM_GENERIC_SECRET, | ||
307 | 69 | {'desktopcouch': 'basic'}) | ||
308 | 70 | except gnomekeyring.NoMatchError: | ||
309 | 71 | data = None | ||
310 | 72 | if data: | ||
311 | 73 | username, password = data[0].secret.split(":") | ||
312 | 74 | return username, password | ||
313 | 75 | # otherwise fall through; for some reason the access details aren't | ||
314 | 76 | # in the keyring, so re-create the ini file and do it all again | ||
315 | 77 | |||
316 | 78 | # randomly generate tokens and usernames | ||
317 | 79 | def make_random_string(count): | ||
318 | 80 | return ''.join([ | ||
319 | 81 | random.SystemRandom().choice(ACCEPTABLE_USERNAME_PASSWORD_CHARS) | ||
320 | 82 | for x in range(count)]) | ||
321 | 83 | |||
322 | 84 | admin_account_username = make_random_string(10) | ||
323 | 85 | admin_account_basic_auth_password = make_random_string(10) | ||
324 | 86 | consumer_key = make_random_string(10) | ||
325 | 87 | consumer_secret = make_random_string(10) | ||
326 | 88 | token = make_random_string(10) | ||
327 | 89 | token_secret = make_random_string(10) | ||
328 | 90 | local = { | ||
329 | 91 | 'couchdb': { | ||
330 | 92 | 'database_dir': ctx.db_dir, | ||
331 | 93 | 'view_index_dir': ctx.db_dir, | ||
332 | 94 | }, | ||
333 | 95 | 'httpd': { | ||
334 | 96 | 'bind_address': '127.0.0.1', | ||
335 | 97 | 'port': port, | ||
336 | 98 | }, | ||
337 | 99 | 'log': { | ||
338 | 100 | 'file': ctx.file_log, | ||
339 | 101 | 'level': ctx.couchdb_log_level, | ||
340 | 102 | }, | ||
341 | 103 | 'admins': { | ||
342 | 104 | admin_account_username: admin_account_basic_auth_password | ||
343 | 105 | }, | ||
344 | 106 | 'oauth_consumer_secrets': { | ||
345 | 107 | consumer_key: consumer_secret | ||
346 | 108 | }, | ||
347 | 109 | 'oauth_token_secrets': { | ||
348 | 110 | token: token_secret | ||
349 | 111 | }, | ||
350 | 112 | 'oauth_token_users': { | ||
351 | 113 | token: admin_account_username | ||
352 | 114 | }, | ||
353 | 115 | 'couch_httpd_auth': { | ||
354 | 116 | 'require_valid_user': 'true' | ||
355 | 117 | } | ||
356 | 118 | } | ||
357 | 119 | |||
358 | 120 | dump_ini(local, ctx.file_ini) | ||
359 | 121 | ctx.ensure_files_not_readable() | ||
360 | 122 | |||
361 | 123 | # save admin account details in keyring | ||
362 | 124 | item_id = gnomekeyring.item_create_sync( | ||
363 | 125 | None, | ||
364 | 126 | gnomekeyring.ITEM_GENERIC_SECRET, | ||
365 | 127 | 'Desktop Couch user authentication', | ||
366 | 128 | {'desktopcouch': 'basic'}, | ||
367 | 129 | "%s:%s" % ( | ||
368 | 130 | admin_account_username, admin_account_basic_auth_password), | ||
369 | 131 | True) | ||
370 | 132 | # and oauth tokens | ||
371 | 133 | item_id = gnomekeyring.item_create_sync( | ||
372 | 134 | None, | ||
373 | 135 | gnomekeyring.ITEM_GENERIC_SECRET, | ||
374 | 136 | 'Desktop Couch user authentication', | ||
375 | 137 | {'desktopcouch': 'oauth'}, | ||
376 | 138 | "%s:%s:%s:%s" % ( | ||
377 | 139 | consumer_key, consumer_secret, token, token_secret), | ||
378 | 140 | True) | ||
379 | 141 | return (admin_account_username, admin_account_basic_auth_password) | ||
380 | 142 | |||
381 | 143 | 46 | ||
382 | 144 | def process_is_couchdb__linux(pid): | 47 | def process_is_couchdb__linux(pid): |
383 | 145 | if pid is None: | 48 | if pid is None: |
384 | @@ -317,7 +220,7 @@ | |||
385 | 317 | 220 | ||
386 | 318 | def start_couchdb(ctx=local_files.DEFAULT_CONTEXT): | 221 | def start_couchdb(ctx=local_files.DEFAULT_CONTEXT): |
387 | 319 | """Execute each step to start a desktop CouchDB.""" | 222 | """Execute each step to start a desktop CouchDB.""" |
389 | 320 | username, password = create_ini_file(ctx=ctx) | 223 | username, password = local_files.get_admin_credentials(ctx=ctx) |
390 | 321 | pid, port = run_couchdb(ctx=ctx) | 224 | pid, port = run_couchdb(ctx=ctx) |
391 | 322 | # Note that we do not call update_design_documents here. This is because | 225 | # Note that we do not call update_design_documents here. This is because |
392 | 323 | # Couch won't actually have started yet, so when update_design_documents | 226 | # Couch won't actually have started yet, so when update_design_documents |
393 | 324 | 227 | ||
394 | === modified file 'desktopcouch/tests/test_local_files.py' | |||
395 | --- desktopcouch/tests/test_local_files.py 2009-11-18 18:43:41 +0000 | |||
396 | +++ desktopcouch/tests/test_local_files.py 2009-11-27 03:36:11 +0000 | |||
397 | @@ -7,6 +7,11 @@ | |||
398 | 7 | 7 | ||
399 | 8 | class TestLocalFiles(testtools.TestCase): | 8 | class TestLocalFiles(testtools.TestCase): |
400 | 9 | """Testing that local files returns the right things""" | 9 | """Testing that local files returns the right things""" |
401 | 10 | |||
402 | 11 | def setUp(self): | ||
403 | 12 | cf = test_environment.test_context.configuration | ||
404 | 13 | cf._fill_from_file(test_environment.test_context.file_ini) # Test loading from file. | ||
405 | 14 | |||
406 | 10 | def test_all_files_returned(self): | 15 | def test_all_files_returned(self): |
407 | 11 | "Does local_files list all the files that it needs to?" | 16 | "Does local_files list all the files that it needs to?" |
408 | 12 | import desktopcouch.local_files | 17 | import desktopcouch.local_files |
409 | @@ -29,9 +34,6 @@ | |||
410 | 29 | self.assertTrue(len(ok) > 0) | 34 | self.assertTrue(len(ok) > 0) |
411 | 30 | 35 | ||
412 | 31 | def test_bind_address(self): | 36 | def test_bind_address(self): |
413 | 32 | desktopcouch.start_local_couchdb.create_ini_file() | ||
414 | 33 | desktopcouch.start_local_couchdb.create_ini_file() # Make sure the loader works. | ||
415 | 34 | |||
416 | 35 | old = desktopcouch.local_files.get_bind_address() | 37 | old = desktopcouch.local_files.get_bind_address() |
417 | 36 | octets = old.split(".") | 38 | octets = old.split(".") |
418 | 37 | octets[2] = str((int(octets[2]) + 128) % 256) | 39 | octets[2] = str((int(octets[2]) + 128) % 256) |
419 | @@ -41,4 +43,3 @@ | |||
420 | 41 | self.assertEquals(desktopcouch.local_files.get_bind_address(), new) | 43 | self.assertEquals(desktopcouch.local_files.get_bind_address(), new) |
421 | 42 | desktopcouch.local_files.set_bind_address(old) | 44 | desktopcouch.local_files.set_bind_address(old) |
422 | 43 | self.assertEquals(desktopcouch.local_files.get_bind_address(), old) | 45 | self.assertEquals(desktopcouch.local_files.get_bind_address(), old) |
423 | 44 |
Hmm. Okay.