Merge lp:~eday/burrow/cleanup into lp:burrow

Proposed by Eric Day
Status: Merged
Approved by: Eric Day
Approved revision: 12
Merged at revision: 12
Proposed branch: lp:~eday/burrow/cleanup
Merge into: lp:burrow
Diff against target: 245 lines (+65/-15)
8 files modified
burrow/backend/__init__.py (+2/-1)
burrow/backend/http.py (+15/-2)
burrow/backend/sqlite.py (+12/-9)
burrow/client.py (+13/-1)
burrow/config.py (+7/-0)
burrow/frontend/wsgi.py (+3/-1)
burrow/shell.py (+4/-1)
etc/burrowd.conf (+9/-0)
To merge this branch: bzr merge lp:~eday/burrow/cleanup
Reviewer Review Type Date Requested Status
Burrow Core Team Pending
Review via email: mp+58777@code.launchpad.net

Description of the change

Misc. bug fixes.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'burrow/backend/__init__.py'
2--- burrow/backend/__init__.py 2011-04-20 05:14:30 +0000
3+++ burrow/backend/__init__.py 2011-04-22 02:20:47 +0000
4@@ -69,7 +69,8 @@
5 a visible message.'''
6 queue = '%s/%s' % (account, queue)
7 if queue in self.queues:
8- self.queues[queue].put(0)
9+ for count in xrange(0, self.queues[queue].getting()):
10+ self.queues[queue].put(0)
11
12 def wait(self, account, queue, seconds):
13 '''Wait for a message to appear in the account/queue.'''
14
15=== modified file 'burrow/backend/http.py'
16--- burrow/backend/http.py 2011-04-20 18:21:51 +0000
17+++ burrow/backend/http.py 2011-04-22 02:20:47 +0000
18@@ -16,9 +16,14 @@
19
20 import httplib
21 import json
22+import urlparse
23
24 import burrow.backend
25
26+# Default configuration values for this module.
27+DEFAULT_HOST = 'localhost'
28+DEFAULT_PORT = 8080
29+
30
31 class Backend(burrow.backend.Backend):
32 '''This backend forwards all requests via HTTP using the httplib
33@@ -26,7 +31,15 @@
34
35 def __init__(self, config):
36 super(Backend, self).__init__(config)
37- self.server = ('localhost', 8080)
38+ url = self.config.get('url')
39+ if url:
40+ url = urlparse.urlparse(url)
41+ self.config.set('host', url.hostname)
42+ if url.port is not None:
43+ self.config.set('port', str(url.port))
44+ host = self.config.get('host', DEFAULT_HOST)
45+ port = self.config.getint('port', DEFAULT_PORT)
46+ self.server = (host, port)
47
48 def delete_accounts(self, filters={}):
49 url = self._add_parameters('', filters=filters)
50@@ -87,7 +100,7 @@
51 if value is not None:
52 url += '%s%s=%s' % (separator, attribute, value)
53 separator = '&'
54- for filter in ['marker', 'limit', 'match_hidden', 'detail']:
55+ for filter in ['marker', 'limit', 'match_hidden', 'detail', 'wait']:
56 value = filters.get(filter, None)
57 if value is not None:
58 url += '%s%s=%s' % (separator, filter, value)
59
60=== modified file 'burrow/backend/sqlite.py'
61--- burrow/backend/sqlite.py 2011-04-06 02:03:37 +0000
62+++ burrow/backend/sqlite.py 2011-04-22 02:20:47 +0000
63@@ -16,6 +16,7 @@
64
65 import sqlite3
66 import time
67+import urlparse
68
69 import burrow.backend
70
71@@ -27,15 +28,19 @@
72
73 def __init__(self, config):
74 super(Backend, self).__init__(config)
75+ url = self.config.get('url')
76+ if url:
77+ url = urlparse.urlparse(url)
78+ self.config.set('database', url.netloc)
79 database = self.config.get('database', DEFAULT_DATABASE)
80 self.db = sqlite3.connect(database)
81 self.db.isolation_level = None
82 queries = [
83- 'CREATE TABLE queues ('
84+ 'CREATE TABLE IF NOT EXISTS queues ('
85 'account VARCHAR(255) NOT NULL,'
86 'queue VARCHAR(255) NOT NULL,'
87 'PRIMARY KEY (account, queue))',
88- 'CREATE TABLE messages ('
89+ 'CREATE TABLE IF NOT EXISTS messages ('
90 'queue INT UNSIGNED NOT NULL,'
91 'name VARCHAR(255) NOT NULL,'
92 'ttl INT UNSIGNED NOT NULL,'
93@@ -150,14 +155,12 @@
94 ttl = attributes.get('ttl', 0)
95 hide = attributes.get('hide', 0)
96 if len(result) == 0:
97- query = "INSERT INTO messages VALUES (%d, '%s', %d, %d, '%s')" % \
98- (rowid, message, ttl, hide, body)
99- self.db.execute(query)
100+ query = "INSERT INTO messages VALUES (?, ?, ?, ?, ?)"
101+ self.db.execute(query, (rowid, message, ttl, hide, body))
102 self.notify(account, queue)
103 return True
104- query = "UPDATE messages SET ttl=%d, hide=%d, body='%s'" \
105- "WHERE rowid=%d" % (ttl, hide, body, result[0][0])
106- self.db.execute(query)
107+ query = "UPDATE messages SET ttl=?, hide=?, body=? WHERE rowid=?"
108+ self.db.execute(query, (ttl, hide, body, result[0][0]))
109 if hide == 0:
110 self.notify(account, queue)
111 return False
112@@ -254,7 +257,7 @@
113 self.notify(result[0], result[1])
114
115 def _get_queue(self, account, queue):
116- query = "SELECT COUNT(*) FROM queues " \
117+ query = "SELECT rowid FROM queues " \
118 "WHERE account='%s' AND queue='%s'" % \
119 (account, queue)
120 result = self.db.execute(query).fetchall()
121
122=== modified file 'burrow/client.py'
123--- burrow/client.py 2011-04-20 18:21:51 +0000
124+++ burrow/client.py 2011-04-22 02:20:47 +0000
125@@ -14,6 +14,8 @@
126
127 '''Client module for burrow.'''
128
129+import urlparse
130+
131 import burrow.common
132 import burrow.config
133
134@@ -31,13 +33,23 @@
135 so files should be in ConfigParser format. This will load
136 all the backend class from the configuration.'''
137 self._config = burrow.config.load_config_files(config_files)
138- # TODO: Parse URL if given and overwrite any values in self._config.
139 self.config = burrow.config.Config(self._config, 'burrow.client')
140+ if url is not None:
141+ self._parse_url(url)
142 self.log = burrow.common.get_logger(self.config)
143 if len(self.log.handlers) == 0 and add_default_log_handler:
144 burrow.common.add_default_log_handler()
145 self.backend = self._import_backend()
146
147+ def _parse_url(self, url):
148+ '''Parse a backend URL and set config values so it overrides
149+ previous values.'''
150+ backend = 'burrow.backend.' + urlparse.urlparse(url).scheme
151+ self.config.set('backend', backend)
152+ if not self._config.has_section(backend):
153+ self._config.add_section(backend)
154+ self._config.set(backend, 'url', url)
155+
156 def _import_backend(self):
157 '''Load backend given in the 'backend' option.'''
158 backend = self.config.get('backend', DEFAULT_BACKEND)
159
160=== modified file 'burrow/config.py'
161--- burrow/config.py 2011-04-20 05:14:30 +0000
162+++ burrow/config.py 2011-04-22 02:20:47 +0000
163@@ -63,6 +63,13 @@
164 return method(ConfigParser.DEFAULTSECT, option)
165 return default
166
167+ def set(self, option, value):
168+ '''Set an option for this section.'''
169+ section = self.instance or self.section
170+ if not self.config.has_section(section):
171+ self.config.add_section(section)
172+ self.config.set(section, option, value)
173+
174
175 def load_config_files(config_files):
176 '''Load the config files, if any, into the logging and ConfigParser
177
178=== modified file 'burrow/frontend/wsgi.py'
179--- burrow/frontend/wsgi.py 2011-04-20 18:21:51 +0000
180+++ burrow/frontend/wsgi.py 2011-04-22 02:20:47 +0000
181@@ -213,7 +213,7 @@
182 def _filter_message(self, detail, message):
183 if detail == 'id':
184 return dict(id=message['id'])
185- elif detail == 'metadata':
186+ elif detail == 'attributes':
187 message = message.copy()
188 del message['body']
189 return message
190@@ -224,6 +224,8 @@
191 def _return_message(self, req, account, queue, message, detail):
192 if 'detail' in req.params:
193 detail = req.params['detail']
194+ if detail == 'body':
195+ return webob.exc.HTTPOk(body=message['body'])
196 message = self._filter_message(detail, message)
197 if message is not None:
198 return webob.exc.HTTPOk(body=json.dumps(message, indent=2))
199
200=== modified file 'burrow/shell.py'
201--- burrow/shell.py 2011-04-20 18:21:51 +0000
202+++ burrow/shell.py 2011-04-22 02:20:47 +0000
203@@ -20,6 +20,7 @@
204 import optparse
205 import os
206 import sys
207+import types
208
209 import burrow
210
211@@ -195,11 +196,13 @@
212 filters['marker'] = self.options.marker
213 if self.options.all is not None:
214 filters['match_hidden'] = self.options.all
215+ if self.options.detail is not None:
216+ filters['detail'] = self.options.detail
217 return filters
218
219 def _print_result(self, result):
220 '''Format and print the result.'''
221- if isinstance(result, list):
222+ if isinstance(result, list) or isinstance(result, types.GeneratorType):
223 for item in result:
224 if isinstance(item, dict):
225 self._print_message(item)
226
227=== modified file 'etc/burrowd.conf'
228--- etc/burrowd.conf 2011-03-30 19:51:34 +0000
229+++ etc/burrowd.conf 2011-04-22 02:20:47 +0000
230@@ -30,6 +30,15 @@
231 database = :memory:
232
233
234+[burrow.backend.http]
235+
236+# Host to connect to.
237+host = localhost
238+
239+# Port to connect to.
240+port = 8080
241+
242+
243 [burrow.frontend.wsgi]
244
245 # Host to listen on.

Subscribers

People subscribed via source and target branches