Merge lp:~thisfred/desktopcouch/cut-gordian-knot into lp:desktopcouch
- cut-gordian-knot
- Merge into trunk
Proposed by
Eric Casteleijn
Status: | Merged |
---|---|
Approved by: | Eric Casteleijn |
Approved revision: | 224 |
Merged at revision: | 224 |
Proposed branch: | lp:~thisfred/desktopcouch/cut-gordian-knot |
Merge into: | lp:desktopcouch |
Diff against target: |
1052 lines (+229/-184) 30 files modified
bin/desktopcouch-pair (+2/-2) desktopcouch/application/migration/__init__.py (+7/-7) desktopcouch/application/migration/tests/test_migration.py (+11/-10) desktopcouch/application/pair/couchdb_pairing/couchdb_io.py (+6/-6) desktopcouch/application/pair/couchdb_pairing/ubuntuone_pairing.py (+2/-2) desktopcouch/application/pair/tests/test_couchdb_io.py (+4/-4) desktopcouch/application/platform/linux/__init__.py (+1/-1) desktopcouch/application/platform/windows/__init__.py (+1/-1) desktopcouch/application/replication_services/ubuntuone.py (+3/-3) desktopcouch/application/server.py (+48/-50) desktopcouch/application/service.py (+7/-12) desktopcouch/application/start_local_couchdb.py (+2/-2) desktopcouch/application/tests/test_replication.py (+4/-4) desktopcouch/application/tests/test_start_local_couchdb.py (+3/-2) desktopcouch/records/database.py (+40/-8) desktopcouch/records/doc/records.txt (+2/-2) desktopcouch/records/server.py (+9/-0) desktopcouch/records/server_base.py (+9/-0) desktopcouch/records/tests/__init__.py (+1/-2) desktopcouch/records/tests/test_record.py (+3/-3) desktopcouch/records/tests/test_server.py (+12/-13) desktopcouch/recordtypes/contacts/__init__.py (+0/-1) desktopcouch/recordtypes/contacts/testing/create.py (+2/-2) desktopcouch/recordtypes/contacts/tests/test_record.py (+1/-1) desktopcouch/recordtypes/contacts/tests/test_view.py (+2/-2) desktopcouch/recordtypes/contacts/view.py (+42/-37) desktopcouch/recordtypes/notes.py (+1/-0) desktopcouch/recordtypes/tasks.py (+1/-1) desktopcouch/recordtypes/tests/test_notes.py (+2/-5) desktopcouch/recordtypes/tests/test_tasks.py (+1/-1) |
To merge this branch: | bzr merge lp:~thisfred/desktopcouch/cut-gordian-knot |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Chad Miller (community) | Approve | ||
Vincenzo Di Somma (community) | Approve | ||
Review via email: mp+41643@code.launchpad.net |
Commit message
This cuts out all the dependencies on desktopcouch.
Description of the change
This cuts out all the dependencies on desktopcouch.
The tests still depend on it, because we need it to start and stop the test couchdb instance, and there is one deprecated class that imports from application, since I did not want to break bw compatibility. People who use desktopcouch.
To post a comment you must log in.
Revision history for this message
Vincenzo Di Somma (vds) : | # |
review:
Approve
Revision history for this message
Chad Miller (cmiller) : | # |
review:
Approve
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote : | # |
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote : | # |
There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'bin/desktopcouch-pair' |
2 | --- bin/desktopcouch-pair 2010-11-22 21:36:06 +0000 |
3 | +++ bin/desktopcouch-pair 2010-11-24 15:19:50 +0000 |
4 | @@ -849,7 +849,7 @@ |
5 | |
6 | def set_couchdb_bind_address(): |
7 | """Set a couchdb bind address.""" |
8 | - from desktopcouch.records.server import CouchDatabase |
9 | + from desktopcouch.application.server import DesktopDatabase |
10 | # FIXME I don't think this will reimport anything |
11 | from desktopcouch import local_files # pylint: disable=W0621,W0404 |
12 | bind_address = local_files.get_bind_address() |
13 | @@ -859,7 +859,7 @@ |
14 | bind_address) |
15 | return False |
16 | |
17 | - db = CouchDatabase("management", create=True) |
18 | + db = DesktopDatabase("management", create=True) |
19 | results = db.get_records(create_view=True) |
20 | count = 0 |
21 | for row in results[pairing_record_type]: |
22 | |
23 | === modified file 'desktopcouch/application/migration/__init__.py' |
24 | --- desktopcouch/application/migration/__init__.py 2010-11-22 19:27:42 +0000 |
25 | +++ desktopcouch/application/migration/__init__.py 2010-11-24 15:19:50 +0000 |
26 | @@ -23,7 +23,8 @@ |
27 | |
28 | from couchdb.client import ResourceConflict |
29 | |
30 | -from desktopcouch.records import server, server_base |
31 | +from desktopcouch.records import database |
32 | +from desktopcouch.application import server |
33 | from desktopcouch.application.platform import find_port |
34 | |
35 | MIGRATION_DESIGN_DOCUMENT = 'dc_migration' |
36 | @@ -35,8 +36,7 @@ |
37 | """Get all the non private dbs from a server""" |
38 | port = find_port(ctx=ctx) |
39 | uri = "http://localhost:%s" % port |
40 | - couchdb_server = server.OAuthCapableServer( |
41 | - uri, oauth_tokens=None, ctx=ctx) |
42 | + couchdb_server = server.DesktopServer(uri, oauth_tokens=None, ctx=ctx) |
43 | return [x for x in couchdb_server.resource.get('/_all_dbs')[1]] |
44 | |
45 | |
46 | @@ -46,8 +46,8 @@ |
47 | dbs = _all_dbs(ctx) |
48 | for db_name in [db for db in dbs if not db.startswith('_')]: |
49 | try: |
50 | - db = server.CouchDatabase(database=db_name, ctx=ctx) |
51 | - except server_base.NoSuchDatabase: |
52 | + db = server.DesktopDatabase(database=db_name, ctx=ctx) |
53 | + except database.NoSuchDatabase: |
54 | return |
55 | try: |
56 | db.add_view(view_name, map_js=view_code, reduce_js='', |
57 | @@ -79,6 +79,6 @@ |
58 | for db in dbs: |
59 | try: |
60 | MIGRATIONS_REGISTRY[migration]['method']( |
61 | - server.CouchDatabase(database=db, ctx=ctx)) |
62 | - except server_base.NoSuchDatabase: |
63 | + server.DesktopDatabase(database=db, ctx=ctx)) |
64 | + except database.NoSuchDatabase: |
65 | pass |
66 | |
67 | === modified file 'desktopcouch/application/migration/tests/test_migration.py' |
68 | --- desktopcouch/application/migration/tests/test_migration.py 2010-11-18 19:58:16 +0000 |
69 | +++ desktopcouch/application/migration/tests/test_migration.py 2010-11-24 15:19:50 +0000 |
70 | @@ -26,7 +26,7 @@ |
71 | |
72 | from desktopcouch.application import migration |
73 | import desktopcouch.application.tests as test_environment |
74 | -from desktopcouch.records.server import CouchDatabase |
75 | +from desktopcouch.application.server import DesktopDatabase |
76 | from desktopcouch.records import Record |
77 | from desktopcouch.application.stop_local_couchdb import stop_couchdb |
78 | |
79 | @@ -35,6 +35,7 @@ |
80 | """Return test context.""" |
81 | return test_environment.test_context |
82 | |
83 | + |
84 | def fake_migration(): |
85 | """fake migration code""" |
86 | pass |
87 | @@ -48,7 +49,7 @@ |
88 | super(MigrationBase, self).setUp() |
89 | self.ctx = get_test_context() |
90 | self.dbname = self._testMethodName |
91 | - self.database = CouchDatabase(self.dbname, create=True, ctx=self.ctx) |
92 | + self.database = DesktopDatabase(self.dbname, create=True, ctx=self.ctx) |
93 | self.server = self.database._server |
94 | |
95 | def tearDown(self): |
96 | @@ -59,15 +60,15 @@ |
97 | stop_couchdb(ctx=this_context) |
98 | super(MigrationBase, self).tearDown() |
99 | |
100 | + |
101 | class TestRegistration(MigrationBase): |
102 | """Tests the registration of a migration script""" |
103 | |
104 | def setUp(self): |
105 | """setup each test""" |
106 | super(TestRegistration, self).setUp() |
107 | - self.one_more_database = CouchDatabase('one_more_database', |
108 | - create=True, |
109 | - ctx=self.ctx) |
110 | + self.one_more_database = DesktopDatabase( |
111 | + 'one_more_database', create=True, ctx=self.ctx) |
112 | |
113 | def tearDown(self): |
114 | """tear down each test""" |
115 | @@ -85,9 +86,9 @@ |
116 | ctx=self.ctx) |
117 | self.assertEqual( |
118 | {'method': fake_migration, |
119 | - 'dbs':[self.dbname]}, |
120 | + 'dbs': [self.dbname]}, |
121 | migration.MIGRATIONS_REGISTRY[self.dbname]) |
122 | - self.assertEqual(size+1, len(migration.MIGRATIONS_REGISTRY)) |
123 | + self.assertEqual(size + 1, len(migration.MIGRATIONS_REGISTRY)) |
124 | |
125 | def test_register_migration_add_view_to_a_given_db(self): |
126 | """Test that the migration is correctly registered.""" |
127 | @@ -111,10 +112,10 @@ |
128 | ctx=self.ctx) |
129 | self.assertEqual( |
130 | {'method': fake_migration, |
131 | - 'dbs':[]}, |
132 | + 'dbs': []}, |
133 | migration.MIGRATIONS_REGISTRY[self.dbname]) |
134 | for db in [db for db in self.server if not db.startswith('_')]: |
135 | - target = CouchDatabase(database=db, ctx=self.ctx) |
136 | + target = DesktopDatabase(database=db, ctx=self.ctx) |
137 | self.assert_(target.view_exists(self.dbname, 'dc_migration')) |
138 | |
139 | |
140 | @@ -125,6 +126,7 @@ |
141 | """tear down each test""" |
142 | super(TestMigration, self).tearDown() |
143 | migration.MIGRATIONS_REGISTRY = {} |
144 | + |
145 | def test_migration_script_is_run(self): |
146 | """Test that the migration script is run.""" |
147 | |
148 | @@ -173,4 +175,3 @@ |
149 | dbs=['db_that_doesnt_exixts'], |
150 | ctx=self.ctx) |
151 | self.assertIs(None, migration.run_needed_migrations(ctx=self.ctx)) |
152 | - |
153 | |
154 | === modified file 'desktopcouch/application/pair/couchdb_pairing/couchdb_io.py' |
155 | --- desktopcouch/application/pair/couchdb_pairing/couchdb_io.py 2010-11-22 20:33:58 +0000 |
156 | +++ desktopcouch/application/pair/couchdb_pairing/couchdb_io.py 2010-11-24 15:19:50 +0000 |
157 | @@ -27,7 +27,7 @@ |
158 | |
159 | from desktopcouch.application import local_files |
160 | from desktopcouch.application.platform import find_port |
161 | -from desktopcouch.records import server |
162 | +from desktopcouch.application import server |
163 | from desktopcouch.records import Record |
164 | |
165 | RECTYPE_BASE = "http://www.freedesktop.org/wiki/Specifications/desktopcouch/" |
166 | @@ -68,7 +68,7 @@ |
167 | |
168 | def _get_db(name, create=True, uri=None, ctx=local_files.DEFAULT_CONTEXT): |
169 | """Get (and create?) a database.""" |
170 | - return server.CouchDatabase(name, create=create, uri=uri, ctx=ctx) |
171 | + return server.DesktopDatabase(name, create=create, uri=uri, ctx=ctx) |
172 | |
173 | |
174 | def put_paired_host(oauth_data, uri=None, |
175 | @@ -141,7 +141,7 @@ |
176 | if not uri: |
177 | port = find_port(ctx=ctx) |
178 | uri = "http://localhost:%s" % port |
179 | - couchdb_server = server.OAuthCapableServer(uri, oauth_tokens=oauth_tokens, |
180 | + couchdb_server = server.DesktopServer(uri, oauth_tokens=oauth_tokens, |
181 | ctx=ctx) |
182 | try: |
183 | if user_id is None: |
184 | @@ -248,7 +248,7 @@ |
185 | oauth_tokens=None): |
186 | """Given parts, create a database.""" |
187 | dst_url = mkuri(dst_host, dst_port, use_ssl) |
188 | - return server.CouchDatabase(dst_name, dst_url, create=True, |
189 | + return server.DesktopDatabase(dst_name, dst_url, create=True, |
190 | oauth_tokens=oauth_tokens) |
191 | |
192 | |
193 | @@ -267,7 +267,7 @@ |
194 | target_host, target_port, target_database, use_ssl=target_ssl, |
195 | oauth_tokens=target_oauth) |
196 | else: |
197 | - server.CouchDatabase(target_database, create=True, uri=local_uri) |
198 | + server.DesktopDatabase(target_database, create=True, uri=local_uri) |
199 | logging.debug("db exists, and we're ready to replicate") |
200 | except: # pylint: disable=W0702 |
201 | logging.exception( |
202 | @@ -305,7 +305,7 @@ |
203 | obsfuscate(source), obsfuscate(target),) |
204 | |
205 | # All until python-couchdb gets a Server.replicate() function |
206 | - local_server = server.OAuthCapableServer(local_uri) |
207 | + local_server = server.DesktopServer(local_uri) |
208 | resp, data = local_server.resource.post(path='/_replicate', |
209 | content=record) |
210 | logging.debug( |
211 | |
212 | === modified file 'desktopcouch/application/pair/couchdb_pairing/ubuntuone_pairing.py' |
213 | --- desktopcouch/application/pair/couchdb_pairing/ubuntuone_pairing.py 2010-11-22 20:33:58 +0000 |
214 | +++ desktopcouch/application/pair/couchdb_pairing/ubuntuone_pairing.py 2010-11-24 15:19:50 +0000 |
215 | @@ -21,7 +21,7 @@ |
216 | import logging |
217 | from desktopcouch.application.pair.couchdb_pairing.couchdb_io import ( |
218 | put_static_paired_service) |
219 | -from desktopcouch.records.server import CouchDatabase |
220 | +from desktopcouch.application.server import DesktopDatabase |
221 | |
222 | U1_PAIR_RECORD = "ubuntu_one_pair_record" |
223 | MAP_JS = """function(doc) { |
224 | @@ -41,7 +41,7 @@ |
225 | def pair_with_ubuntuone(management_db=None): |
226 | """Adds a pairing record with ubuntu one when is needed.""" |
227 | if not management_db: |
228 | - management_db = CouchDatabase("management", create=True) |
229 | + management_db = DesktopDatabase("management", create=True) |
230 | # we indeed have credentials to add to the pairing records |
231 | # but first we ensure that the required view is present |
232 | if not management_db.view_exists(U1_PAIR_RECORD, U1_PAIR_RECORD): |
233 | |
234 | === modified file 'desktopcouch/application/pair/tests/test_couchdb_io.py' |
235 | --- desktopcouch/application/pair/tests/test_couchdb_io.py 2010-11-22 20:33:58 +0000 |
236 | +++ desktopcouch/application/pair/tests/test_couchdb_io.py 2010-11-24 15:19:50 +0000 |
237 | @@ -22,7 +22,7 @@ |
238 | import desktopcouch.application.tests as test_environment |
239 | |
240 | from desktopcouch.application.pair.couchdb_pairing import couchdb_io |
241 | -from desktopcouch.records.server import CouchDatabase |
242 | +from desktopcouch.application.server import DesktopDatabase |
243 | from desktopcouch.records import Record |
244 | from desktopcouch.application.replication_services import ubuntuone |
245 | import unittest |
246 | @@ -37,12 +37,12 @@ |
247 | |
248 | def setUp(self): |
249 | """setup each test""" |
250 | - self.mgt_database = CouchDatabase('management', create=True, uri=URI, |
251 | + self.mgt_database = DesktopDatabase('management', create=True, uri=URI, |
252 | ctx=test_environment.test_context) |
253 | - self.foo_database = CouchDatabase('foo', create=True, uri=URI, |
254 | + self.foo_database = DesktopDatabase('foo', create=True, uri=URI, |
255 | ctx=test_environment.test_context) |
256 | #create some records to pull out and test |
257 | - self.foo_database = CouchDatabase('bar', create=True, uri=URI, |
258 | + self.foo_database = DesktopDatabase('bar', create=True, uri=URI, |
259 | ctx=test_environment.test_context) |
260 | #create some records to pull out and test |
261 | self.foo_database.put_record(Record({ |
262 | |
263 | === modified file 'desktopcouch/application/platform/linux/__init__.py' |
264 | --- desktopcouch/application/platform/linux/__init__.py 2010-11-22 18:21:40 +0000 |
265 | +++ desktopcouch/application/platform/linux/__init__.py 2010-11-24 15:19:50 +0000 |
266 | @@ -73,7 +73,7 @@ |
267 | if start_if_not_running: |
268 | # start CouchDB by running the startup script |
269 | logging.info("Desktop CouchDB is not running; starting it.") |
270 | - from desktopcouch import start_local_couchdb |
271 | + from desktopcouch.application import start_local_couchdb |
272 | pid = start_local_couchdb.start_couchdb(ctx=ctx) |
273 | # now load the design documents and pair records updates, |
274 | # because it's started |
275 | |
276 | === modified file 'desktopcouch/application/platform/windows/__init__.py' |
277 | --- desktopcouch/application/platform/windows/__init__.py 2010-11-22 18:21:40 +0000 |
278 | +++ desktopcouch/application/platform/windows/__init__.py 2010-11-24 15:19:50 +0000 |
279 | @@ -1,7 +1,7 @@ |
280 | """Windows platform specific code.""" |
281 | |
282 | + |
283 | # FIXME make thisdo something or document why it does not |
284 | - |
285 | def set_application_name(app_name): |
286 | """Set the application name.""" |
287 | pass |
288 | |
289 | === modified file 'desktopcouch/application/replication_services/ubuntuone.py' |
290 | --- desktopcouch/application/replication_services/ubuntuone.py 2010-11-19 00:45:03 +0000 |
291 | +++ desktopcouch/application/replication_services/ubuntuone.py 2010-11-24 15:19:50 +0000 |
292 | @@ -113,7 +113,7 @@ |
293 | db_name_prefix = PrefixGetter() # pylint: disable=C0103 |
294 | |
295 | |
296 | -from desktopcouch.records.server import CouchDatabase |
297 | +from desktopcouch.application.server import DesktopDatabase |
298 | from desktopcouch.application.pair.couchdb_pairing import couchdb_io |
299 | from desktopcouch.application import local_files |
300 | |
301 | @@ -128,8 +128,8 @@ |
302 | Ubuntu One cloud couchdb servers.""" |
303 | def __init__(self, url=None, ctx=local_files.DEFAULT_CONTEXT): |
304 | super(ReplicationExclusion, self).__init__() |
305 | - self.management_db = CouchDatabase("management", uri=url, create=True, |
306 | - ctx=ctx) |
307 | + self.management_db = DesktopDatabase( |
308 | + "management", uri=url, create=True, ctx=ctx) |
309 | all_pairing_records = self.management_db.get_all_records( |
310 | record_type=couchdb_io.PAIRED_SERVER_RECORD_TYPE) |
311 | for result in all_pairing_records: |
312 | |
313 | === renamed file 'desktopcouch/records/server.py' => 'desktopcouch/application/server.py' |
314 | --- desktopcouch/records/server.py 2010-11-23 21:02:32 +0000 |
315 | +++ desktopcouch/application/server.py 2010-11-24 15:19:50 +0000 |
316 | @@ -21,35 +21,31 @@ |
317 | |
318 | """The Desktop Couch Records API.""" |
319 | |
320 | -import copy |
321 | -import uuid |
322 | +import urlparse |
323 | +import warnings |
324 | |
325 | from couchdb import Server |
326 | from couchdb.client import Resource |
327 | -import desktopcouch |
328 | -from desktopcouch.records import server_base |
329 | + |
330 | +from desktopcouch.application.local_files import ( |
331 | + DEFAULT_CONTEXT, get_oauth_tokens) |
332 | +from desktopcouch.records.database import Database, OAuthCapableHttp |
333 | from desktopcouch.application.platform import find_port |
334 | -from desktopcouch.application.local_files import DEFAULT_CONTEXT |
335 | -import urlparse |
336 | - |
337 | -DCTRASH = 'dctrash' |
338 | - |
339 | - |
340 | -class OAuthCapableServer(Server): |
341 | + |
342 | + |
343 | +class DesktopServer(Server): |
344 | """Subclass Server to provide oauth magic""" |
345 | # pylint: disable=W0231 |
346 | # __init__ method from base class is not called |
347 | def __init__(self, uri, oauth_tokens=None, ctx=None): |
348 | """Subclass of couchdb.client.Server which creates a custom |
349 | httplib2.Http subclass which understands OAuth""" |
350 | - http = server_base.OAuthCapableHttp(scheme=urlparse.urlparse(uri)[0], |
351 | - timeout=30) |
352 | + http = OAuthCapableHttp(scheme=urlparse.urlparse(uri)[0], timeout=30) |
353 | http.force_exception_to_status_code = False |
354 | if ctx is None: |
355 | - ctx = desktopcouch.application.local_files.DEFAULT_CONTEXT |
356 | + ctx = DEFAULT_CONTEXT |
357 | if oauth_tokens is None: |
358 | - oauth_tokens = \ |
359 | - desktopcouch.application.local_files.get_oauth_tokens(ctx) |
360 | + oauth_tokens = get_oauth_tokens(ctx) |
361 | (consumer_key, consumer_secret, token, token_secret) = ( |
362 | oauth_tokens["consumer_key"], oauth_tokens["consumer_secret"], |
363 | oauth_tokens["token"], oauth_tokens["token_secret"]) |
364 | @@ -59,44 +55,31 @@ |
365 | # pylint: enable=W0231 |
366 | |
367 | |
368 | -class CouchDatabase(server_base.CouchDatabaseBase): |
369 | - """An small records specific abstraction over a couch db database.""" |
370 | - |
371 | - def __init__(self, database, uri=None, record_factory=None, create=False, |
372 | - server_class=OAuthCapableServer, oauth_tokens=None, |
373 | +class OAuthCapableServer(DesktopServer): |
374 | + """Deprecated.""" |
375 | + |
376 | + def __init__(self, uri, oauth_tokens=None, ctx=None): |
377 | + warnings.warn( |
378 | + "OAuthCapableServer is deprecated, use DesktopServer " |
379 | + "instead.", DeprecationWarning, stacklevel=2) |
380 | + super(OAuthCapableServer, self).__init__( |
381 | + uri, oauth_tokens=oauth_tokens, ctx=ctx) |
382 | + |
383 | + |
384 | +class DesktopDatabase(Database): |
385 | + """A desktopcouch specific CouchDb database.""" |
386 | + |
387 | + def __init__(self, database, uri=None, record_factory=None, |
388 | + create=False, server_class=DesktopServer, oauth_tokens=None, |
389 | ctx=None): |
390 | if ctx is None: |
391 | ctx = DEFAULT_CONTEXT |
392 | self.ctx = ctx |
393 | self.server_uri = uri |
394 | - super(CouchDatabase, self).__init__( |
395 | - database, uri, record_factory=record_factory, create=create, |
396 | - server_class=server_class, oauth_tokens=oauth_tokens, ctx=ctx) |
397 | - |
398 | - # pylint: disable=W0212 |
399 | - #Access to a protected member |
400 | - def delete_record(self, record_id): |
401 | - """Delete record with given id""" |
402 | - record = self.get_record(record_id) |
403 | - new_record = copy.deepcopy(record) |
404 | - dctrash = CouchDatabase( |
405 | - database=DCTRASH, |
406 | - uri=self.server_uri, |
407 | - create=True, |
408 | - **self._server_class_extras) |
409 | - new_record.record_id = str(uuid.uuid4()) |
410 | - del new_record._data['_rev'] |
411 | - try: |
412 | - del new_record._data['_attachments'] |
413 | - except KeyError: |
414 | - pass |
415 | - new_record.application_annotations['desktopcouch'] = { |
416 | - 'private_application_annotations': |
417 | - {'original_database_name': self._database_name, |
418 | - 'original_id': record_id}} |
419 | - del self.db[record_id] |
420 | - return dctrash.put_record(new_record) |
421 | - # pylint: enable=W0212 |
422 | + super(DesktopDatabase, self).__init__( |
423 | + database, uri, record_factory=record_factory, |
424 | + create=create, server_class=server_class, |
425 | + oauth_tokens=oauth_tokens, ctx=ctx) |
426 | |
427 | # pylint: disable=W0221 |
428 | # Arguments number differs from overridden method |
429 | @@ -106,5 +89,20 @@ |
430 | uri = "http://localhost:%s" % port |
431 | else: |
432 | uri = self.server_uri |
433 | - super(CouchDatabase, self)._reconnect(uri=uri) |
434 | + super(DesktopDatabase, self)._reconnect(uri=uri) |
435 | # pylint: enable=W0221 |
436 | + |
437 | + |
438 | +class CouchDatabase(DesktopDatabase): |
439 | + """Deprecated.""" |
440 | + |
441 | + def __init__(self, database, uri=None, record_factory=None, |
442 | + create=False, server_class=DesktopServer, oauth_tokens=None, |
443 | + ctx=None): |
444 | + warnings.warn( |
445 | + "CouchDatabase is deprecated, use DesktopDatabase instead.", |
446 | + DeprecationWarning, stacklevel=2) |
447 | + super(CouchDatabase, self).__init__( |
448 | + database, uri=uri, record_factory=record_factory, |
449 | + create=create, server_class=server_class, |
450 | + oauth_tokens=oauth_tokens, ctx=ctx) |
451 | |
452 | === modified file 'desktopcouch/application/service.py' |
453 | --- desktopcouch/application/service.py 2010-11-19 16:23:47 +0000 |
454 | +++ desktopcouch/application/service.py 2010-11-24 15:19:50 +0000 |
455 | @@ -41,11 +41,11 @@ |
456 | import logging.handlers |
457 | import signal |
458 | |
459 | -import desktopcouch |
460 | from desktopcouch.application import local_files |
461 | from desktopcouch.application import replication |
462 | from desktopcouch.application import stop_local_couchdb |
463 | -from desktopcouch.application.platform import PortAdvertiser |
464 | +from desktopcouch.application.platform import ( |
465 | + PortAdvertiser, find_pid, direct_access_find_port) |
466 | |
467 | MAIN_START_EXTENSION_ENTRY_POINT = "desktopcouch.service.start" |
468 | |
469 | @@ -80,19 +80,14 @@ |
470 | """Host the services.""" |
471 | |
472 | # pylint: disable=C0301 |
473 | - def __init__(self, main_loop, |
474 | - pid_finder=desktopcouch.application.platform.find_pid, |
475 | - port_finder=desktopcouch.application.platform.direct_access_find_port, |
476 | + def __init__(self, main_loop, pid_finder=find_pid, |
477 | + port_finder=direct_access_find_port, |
478 | ctx=local_files.DEFAULT_CONTEXT, |
479 | stop_couchdb=stop_local_couchdb.stop_couchdb, |
480 | replication_actions=replication, |
481 | - advertiser_factory=PortAdvertiser, |
482 | - set_logging=set_up_logging, |
483 | - resources=pkg_resources, |
484 | - fork=os.fork, |
485 | - nice=os.nice, |
486 | - kill=os.kill, |
487 | - sleep=time.sleep): |
488 | + advertiser_factory=PortAdvertiser, set_logging=set_up_logging, |
489 | + resources=pkg_resources, fork=os.fork, nice=os.nice, |
490 | + kill=os.kill, sleep=time.sleep): |
491 | self._mainloop = main_loop |
492 | self._pid_finder = pid_finder |
493 | self._port_finder = port_finder |
494 | |
495 | === modified file 'desktopcouch/application/start_local_couchdb.py' |
496 | --- desktopcouch/application/start_local_couchdb.py 2010-11-23 22:43:14 +0000 |
497 | +++ desktopcouch/application/start_local_couchdb.py 2010-11-24 15:19:50 +0000 |
498 | @@ -49,7 +49,7 @@ |
499 | from desktopcouch.application import local_files |
500 | from desktopcouch.application.platform import ( |
501 | read_pidfile, process_is_couchdb, find_port) |
502 | -from desktopcouch.records.server import CouchDatabase |
503 | +from desktopcouch.application.server import DesktopDatabase |
504 | import xdg.BaseDirectory |
505 | |
506 | |
507 | @@ -142,7 +142,7 @@ |
508 | database_name = os.path.split(database_root)[1] |
509 | # Just the presence of database.cfg is enough to create |
510 | # the database |
511 | - db = CouchDatabase(database_name, create=True, ctx=ctx) |
512 | + db = DesktopDatabase(database_name, create=True, ctx=ctx) |
513 | # look for design documents |
514 | dd_spec = os.path.join( |
515 | database_root, "_design", "*", "views", "*", "map.js") |
516 | |
517 | === modified file 'desktopcouch/application/tests/test_replication.py' |
518 | --- desktopcouch/application/tests/test_replication.py 2010-11-19 00:45:03 +0000 |
519 | +++ desktopcouch/application/tests/test_replication.py 2010-11-24 15:19:50 +0000 |
520 | @@ -21,11 +21,11 @@ |
521 | |
522 | def test_creation(self): |
523 | """Test creation.""" |
524 | - self.db_apple = desktopcouch.records.server.CouchDatabase("apple", |
525 | - create=True, ctx=test_environment.test_context) |
526 | + self.db_apple = desktopcouch.application.server.DesktopDatabase( |
527 | + "apple", create=True, ctx=test_environment.test_context) |
528 | other_context = test_environment.create_new_test_environment() |
529 | - self.db_banana = desktopcouch.records.server.CouchDatabase("banana", |
530 | - create=True, ctx=other_context) |
531 | + self.db_banana = desktopcouch.application.server.DesktopDatabase( |
532 | + "banana", create=True, ctx=other_context) |
533 | # XXX: assert something. |
534 | |
535 | |
536 | |
537 | === modified file 'desktopcouch/application/tests/test_start_local_couchdb.py' |
538 | --- desktopcouch/application/tests/test_start_local_couchdb.py 2010-11-19 00:45:03 +0000 |
539 | +++ desktopcouch/application/tests/test_start_local_couchdb.py 2010-11-24 15:19:50 +0000 |
540 | @@ -92,9 +92,10 @@ |
541 | def test_create_databases_and_design_docs(self): # pylint: disable=R0201 |
542 | """Are databases and design documents correctly |
543 | created from the filesystem?""" |
544 | - # Mock CouchDatabase |
545 | + # Mock DesktopDatabase |
546 | mocker = Mocker() |
547 | - couchdb = mocker.replace("desktopcouch.records.server.CouchDatabase") |
548 | + couchdb = mocker.replace( |
549 | + "desktopcouch.application.server.DesktopDatabase") |
550 | |
551 | # databases that should be created |
552 | couchdb("cfg", create=True, ctx=test_environment.test_context) |
553 | |
554 | === renamed file 'desktopcouch/records/server_base.py' => 'desktopcouch/records/database.py' |
555 | --- desktopcouch/records/server_base.py 2010-11-22 18:21:40 +0000 |
556 | +++ desktopcouch/records/database.py 2010-11-24 15:19:50 +0000 |
557 | @@ -25,6 +25,7 @@ |
558 | import cgi |
559 | import copy |
560 | import httplib2 |
561 | +import uuid |
562 | import urlparse |
563 | import warnings |
564 | |
565 | @@ -35,7 +36,7 @@ |
566 | from oauth import oauth |
567 | |
568 | from couchdb import Server |
569 | -from couchdb.client import ResourceNotFound, ResourceConflict |
570 | +from couchdb.client import ResourceConflict, ResourceNotFound |
571 | from couchdb.design import ViewDefinition |
572 | from desktopcouch.records import Record |
573 | import logging |
574 | @@ -43,6 +44,7 @@ |
575 | import string # pylint: disable=W0402 |
576 | |
577 | DEFAULT_DESIGN_DOCUMENT = None # each view in its own eponymous design doc. |
578 | +DCTRASH = 'dc_trash' |
579 | |
580 | |
581 | def base_n(num, base, numerals=string.printable): |
582 | @@ -170,8 +172,8 @@ |
583 | return False |
584 | |
585 | |
586 | -class CouchDatabaseBase(object): |
587 | - """An small records specific abstraction over a couch db database.""" |
588 | +class Database(object): |
589 | + """A desktopcouch.records specific CouchDb database.""" |
590 | |
591 | def __init__(self, database, uri, record_factory=None, create=False, |
592 | server_class=Server, **server_class_extras): |
593 | @@ -410,13 +412,30 @@ |
594 | return False |
595 | return not row_is_deleted(record) |
596 | |
597 | + # pylint: disable=W0212 |
598 | + #Access to a protected member |
599 | def delete_record(self, record_id): |
600 | """Delete record with given id""" |
601 | - record = self.db[record_id] |
602 | - record.setdefault('application_annotations', {}).setdefault( |
603 | - 'Ubuntu One', {}).setdefault( |
604 | - 'private_application_annotations', {})['deleted'] = True |
605 | - self.db[record_id] = record |
606 | + record = self.get_record(record_id) |
607 | + new_record = copy.deepcopy(record) |
608 | + dctrash = self.__class__( |
609 | + database=DCTRASH, |
610 | + uri=self.server_uri, |
611 | + create=True, |
612 | + **self._server_class_extras) |
613 | + new_record.record_id = str(uuid.uuid4()) |
614 | + del new_record._data['_rev'] |
615 | + try: |
616 | + del new_record._data['_attachments'] |
617 | + except KeyError: |
618 | + pass |
619 | + new_record.application_annotations['desktopcouch'] = { |
620 | + 'private_application_annotations': |
621 | + {'original_database_name': self._database_name, |
622 | + 'original_id': record_id}} |
623 | + del self.db[record_id] |
624 | + return dctrash.put_record(new_record) |
625 | + # pylint: enable=W0212 |
626 | |
627 | def delete_view(self, view_name, design_doc=DEFAULT_DESIGN_DOCUMENT): |
628 | """Remove a view, given its name. Raises a KeyError on a unknown |
629 | @@ -656,3 +675,16 @@ |
630 | self.db.resource.post( |
631 | path='_ensure_full_commit', |
632 | headers={'Content-Type': 'application/json'}) |
633 | + |
634 | + |
635 | +class CouchDatabaseBase(Database): |
636 | + """Deprecated.""" |
637 | + |
638 | + def __init__(self, database, uri, record_factory=None, create=False, |
639 | + server_class=Server, **server_class_extras): |
640 | + warnings.warn( |
641 | + "CouchDatabaseBase is deprecated, use Database instead.", |
642 | + DeprecationWarning, stacklevel=2) |
643 | + super(CouchDatabaseBase, self).__init__( |
644 | + database, uri, record_factory=record_factory, create=create, |
645 | + server_class=server_class, **server_class_extras) |
646 | |
647 | === modified file 'desktopcouch/records/doc/records.txt' |
648 | --- desktopcouch/records/doc/records.txt 2010-11-18 19:58:16 +0000 |
649 | +++ desktopcouch/records/doc/records.txt 2010-11-24 15:19:50 +0000 |
650 | @@ -1,6 +1,6 @@ |
651 | The Records API |
652 | |
653 | ->>> from desktopcouch.records.server import CouchDatabase |
654 | +>>> from desktopcouch.application.server import DesktopDatabase |
655 | >>> from desktopcouch.records import Record |
656 | |
657 | Create a database object. Your database needs to exist. If it doesn't, you |
658 | @@ -8,7 +8,7 @@ |
659 | |
660 | # for this doctest the db is created and passed in, to make it work |
661 | # with the test couchdb instance, but normally you would have to do: |
662 | -# >>> db = CouchDatabase('testing', create=True) |
663 | +# >>> db = DesktopDatabase('testing', create=True) |
664 | |
665 | Create a Record object. Records have a record type, which should be a |
666 | URL. The URL should point to a human-readable document which |
667 | |
668 | === added file 'desktopcouch/records/server.py' |
669 | --- desktopcouch/records/server.py 1970-01-01 00:00:00 +0000 |
670 | +++ desktopcouch/records/server.py 2010-11-24 15:19:50 +0000 |
671 | @@ -0,0 +1,9 @@ |
672 | +"""Deprecated.""" |
673 | + |
674 | +import warnings |
675 | +warnings.warn( |
676 | + 'Deprecated import path; use desktopcouch.application.server ' |
677 | + 'instead.', DeprecationWarning, stacklevel=2) |
678 | + |
679 | +# pylint: disable=W0401,W0614 |
680 | +from desktopcouch.application.server import * |
681 | |
682 | === added file 'desktopcouch/records/server_base.py' |
683 | --- desktopcouch/records/server_base.py 1970-01-01 00:00:00 +0000 |
684 | +++ desktopcouch/records/server_base.py 2010-11-24 15:19:50 +0000 |
685 | @@ -0,0 +1,9 @@ |
686 | +"""Deprecated.""" |
687 | + |
688 | +import warnings |
689 | +warnings.warn( |
690 | + 'Deprecated import path; use desktopcouch.records.database ' |
691 | + 'instead.', DeprecationWarning, stacklevel=2) |
692 | + |
693 | +# pylint: disable=W0401,W0614 |
694 | +from desktopcouch.records.database import * |
695 | |
696 | === modified file 'desktopcouch/records/tests/__init__.py' |
697 | --- desktopcouch/records/tests/__init__.py 2009-09-01 22:29:01 +0000 |
698 | +++ desktopcouch/records/tests/__init__.py 2010-11-24 15:19:50 +0000 |
699 | @@ -13,5 +13,4 @@ |
700 | # |
701 | # You should have received a copy of the GNU Lesser General Public License |
702 | # along with desktopcouch. If not, see <http://www.gnu.org/licenses/>. |
703 | -"""Tests for Documents API""" |
704 | - |
705 | +"""Tests for Records API.""" |
706 | |
707 | === modified file 'desktopcouch/records/tests/test_record.py' |
708 | --- desktopcouch/records/tests/test_record.py 2010-11-22 15:26:47 +0000 |
709 | +++ desktopcouch/records/tests/test_record.py 2010-11-24 15:19:50 +0000 |
710 | @@ -25,7 +25,7 @@ |
711 | from collections import MutableSequence, MutableMapping |
712 | |
713 | import desktopcouch |
714 | -from desktopcouch.records.server import CouchDatabase |
715 | +from desktopcouch.application.server import DesktopDatabase |
716 | from desktopcouch.records import ( |
717 | Record, RecordDict, MergeableList, record_factory, IllegalKeyException, |
718 | validate, NoRecordTypeSpecified, is_mergeable_list) |
719 | @@ -182,7 +182,7 @@ |
720 | self.assertRaises(AttributeError, set_rev, self.record) |
721 | |
722 | ctx = test_environment.test_context |
723 | - db = CouchDatabase('testing', create=True, ctx=ctx) |
724 | + db = DesktopDatabase('testing', create=True, ctx=ctx) |
725 | record_id = db.put_record(self.record) |
726 | |
727 | db.get_record(record_id) |
728 | @@ -325,7 +325,7 @@ |
729 | def test_run_doctests(self): |
730 | """Run all doc tests from here to set the proper context (ctx)""" |
731 | ctx = test_environment.test_context |
732 | - globs = {"db": CouchDatabase('testing', create=True, ctx=ctx)} |
733 | + globs = {"db": DesktopDatabase('testing', create=True, ctx=ctx)} |
734 | |
735 | records_tests_path = os.path.dirname( |
736 | desktopcouch.__file__) + '/records/doc/records.txt' |
737 | |
738 | === modified file 'desktopcouch/records/tests/test_server.py' |
739 | --- desktopcouch/records/tests/test_server.py 2010-11-22 20:33:58 +0000 |
740 | +++ desktopcouch/records/tests/test_server.py 2010-11-24 15:19:50 +0000 |
741 | @@ -25,9 +25,9 @@ |
742 | import time |
743 | |
744 | import desktopcouch.application.tests as test_environment |
745 | -from desktopcouch.records.server import CouchDatabase |
746 | -from desktopcouch.records.server_base import ( |
747 | - row_is_deleted, NoSuchDatabase, FieldsConflict, ResourceConflict) |
748 | +from desktopcouch.application.server import DesktopDatabase |
749 | +from desktopcouch.records.database import ( |
750 | + row_is_deleted, NoSuchDatabase, FieldsConflict, ResourceConflict, DCTRASH) |
751 | from desktopcouch.records import Record |
752 | from desktopcouch.application.stop_local_couchdb import stop_couchdb |
753 | from desktopcouch.application.platform import find_pid |
754 | @@ -40,8 +40,6 @@ |
755 | from cStringIO import StringIO as StringIO |
756 | # pylint: enable=F0401 |
757 | |
758 | -DCTRASH = 'dctrash' |
759 | - |
760 | |
761 | def get_test_context(): |
762 | """Return test context.""" |
763 | @@ -59,7 +57,7 @@ |
764 | super(TestCouchDatabaseDeprecated, self).setUp() |
765 | # Connect to CouchDB server |
766 | self.dbname = self._testMethodName |
767 | - self.database = CouchDatabase(self.dbname, create=True, |
768 | + self.database = DesktopDatabase(self.dbname, create=True, |
769 | ctx=get_test_context()) |
770 | #create some records to pull out and test |
771 | self.database.put_record(Record({ |
772 | @@ -159,15 +157,15 @@ |
773 | KeyError, self.database.get_records, create_view=None) |
774 | |
775 | |
776 | -class TestCouchDatabase(testtools.TestCase): |
777 | - """tests specific for CouchDatabase""" |
778 | +class TestDesktopDatabase(testtools.TestCase): |
779 | + """Test case for DesktopDatabase.""" |
780 | |
781 | def setUp(self): |
782 | """setup each test""" |
783 | - super(TestCouchDatabase, self).setUp() |
784 | + super(TestDesktopDatabase, self).setUp() |
785 | # Connect to CouchDB server |
786 | self.dbname = self._testMethodName |
787 | - self.database = CouchDatabase(self.dbname, create=True, |
788 | + self.database = DesktopDatabase(self.dbname, create=True, |
789 | ctx=get_test_context()) |
790 | #create some records to pull out and test |
791 | self.database.put_record(Record({ |
792 | @@ -186,7 +184,7 @@ |
793 | this_context = get_test_context() |
794 | if this_context != test_environment.test_context: |
795 | stop_couchdb(ctx=this_context) |
796 | - super(TestCouchDatabase, self).tearDown() |
797 | + super(TestDesktopDatabase, self).tearDown() |
798 | |
799 | def maybe_die(self): |
800 | """Method that could kill couchdb. Or could it? Or COULD it?""" |
801 | @@ -209,7 +207,8 @@ |
802 | def test_database_not_exists(self): |
803 | """Test that the database does not exist.""" |
804 | self.assertRaises( |
805 | - NoSuchDatabase, CouchDatabase, "this-must-not-exist", create=False) |
806 | + NoSuchDatabase, DesktopDatabase, "this-must-not-exist", |
807 | + create=False) |
808 | |
809 | def test_get_records_by_record_type_save_view(self): |
810 | """Test getting mutliple records by type""" |
811 | @@ -273,7 +272,7 @@ |
812 | record_id = self.database.put_record(record) |
813 | trash_record_id = self.database.delete_record(record_id) |
814 | self.assertIn(DCTRASH, self.database._server) |
815 | - dctrash = CouchDatabase(DCTRASH, create=False, |
816 | + dctrash = DesktopDatabase(DCTRASH, create=False, |
817 | ctx=get_test_context()) |
818 | deleted_record = dctrash.get_record(trash_record_id) |
819 | self.assertNotEqual(record_id, deleted_record.record_id) |
820 | |
821 | === modified file 'desktopcouch/recordtypes/contacts/__init__.py' |
822 | --- desktopcouch/recordtypes/contacts/__init__.py 2010-11-18 19:58:16 +0000 |
823 | +++ desktopcouch/recordtypes/contacts/__init__.py 2010-11-24 15:19:50 +0000 |
824 | @@ -54,4 +54,3 @@ |
825 | def __init__(self, data=None, record_id=None): |
826 | super(Contact, self).__init__( |
827 | record_id=record_id, data=data, record_type=CONTACT_RECORD_TYPE) |
828 | - |
829 | |
830 | === modified file 'desktopcouch/recordtypes/contacts/testing/create.py' |
831 | --- desktopcouch/recordtypes/contacts/testing/create.py 2010-11-19 00:45:03 +0000 |
832 | +++ desktopcouch/recordtypes/contacts/testing/create.py 2010-11-24 15:19:50 +0000 |
833 | @@ -24,7 +24,7 @@ |
834 | import uuid |
835 | |
836 | import desktopcouch.application.tests as test_environment |
837 | -from desktopcouch.records.server import OAuthCapableServer |
838 | +from desktopcouch.application.server import DesktopServer |
839 | from desktopcouch.application.platform import find_port |
840 | |
841 | CONTACT_DOCTYPE = \ |
842 | @@ -176,7 +176,7 @@ |
843 | |
844 | def create_many_contacts(num_contacts=10, host='localhost', port=None, |
845 | db_name='contacts', doctype=CONTACT_DOCTYPE, |
846 | - app_annots=None, server_class=OAuthCapableServer): |
847 | + app_annots=None, server_class=DesktopServer): |
848 | """Make many contacts and create their records""" |
849 | if port is None: |
850 | port = find_port(ctx=test_environment.test_context) |
851 | |
852 | === modified file 'desktopcouch/recordtypes/contacts/tests/test_record.py' |
853 | --- desktopcouch/recordtypes/contacts/tests/test_record.py 2010-11-18 19:58:16 +0000 |
854 | +++ desktopcouch/recordtypes/contacts/tests/test_record.py 2010-11-24 15:19:50 +0000 |
855 | @@ -31,6 +31,7 @@ |
856 | 'addresses', 'phone_numbers', 'email_addresses', 'urls', 'im_addresses')) |
857 | ALL_FIELDS = SINGLE_FIELDS | LIST_FIELDS |
858 | |
859 | + |
860 | class TestContactRecord(testtools.TestCase): |
861 | """Test the Contact Record object.""" |
862 | |
863 | @@ -47,4 +48,3 @@ |
864 | contact.first_name = first_name |
865 | self.assertEqual(first_name, contact.first_name) |
866 | self.assertEqual(set(['first_name']), set(contact.keys())) |
867 | - |
868 | |
869 | === modified file 'desktopcouch/recordtypes/contacts/tests/test_view.py' |
870 | --- desktopcouch/recordtypes/contacts/tests/test_view.py 2010-11-22 20:33:58 +0000 |
871 | +++ desktopcouch/recordtypes/contacts/tests/test_view.py 2010-11-24 15:19:50 +0000 |
872 | @@ -19,7 +19,7 @@ |
873 | """Test view.""" |
874 | |
875 | import desktopcouch.application.tests as test_environment |
876 | -from desktopcouch.records import server |
877 | +from desktopcouch.application import server |
878 | from desktopcouch.recordtypes.contacts import ( |
879 | CONTACT_RECORD_TYPE, view, Contact) |
880 | |
881 | @@ -151,7 +151,7 @@ |
882 | def setUp(self): |
883 | super(TestLocalFiles, self).setUp() |
884 | self.dbname = "contacts" |
885 | - self.db = server.CouchDatabase( |
886 | + self.db = server.DesktopDatabase( |
887 | self.dbname, create=True, ctx=test_environment.test_context) |
888 | self.db.put_record(Contact(data=FRANCES_RECORD_DATA)) |
889 | self.db.put_records_batch( |
890 | |
891 | === modified file 'desktopcouch/recordtypes/contacts/view.py' |
892 | --- desktopcouch/recordtypes/contacts/view.py 2010-11-22 20:33:58 +0000 |
893 | +++ desktopcouch/recordtypes/contacts/view.py 2010-11-24 15:19:50 +0000 |
894 | @@ -24,48 +24,53 @@ |
895 | |
896 | |
897 | VIEW_MAP_PREFIXED_FIELDS = """ |
898 | - function(doc) { |
899 | - function emit_dict(prefix, dict) { |
900 | - for (var k in dict) { |
901 | - var v = dict[k]; |
902 | - if (v == undefined) |
903 | - continue; |
904 | +function(doc) { |
905 | + function emit_dict(prefix, dict) { |
906 | + for (var k in dict) { |
907 | + var v = dict[k]; |
908 | + if (v == undefined) |
909 | + continue; |
910 | |
911 | - if (v.substring) { |
912 | - emit(prefix+k+":"+v, null); |
913 | - switch (prefix+k) { // Weird cases that may be useful. |
914 | - case "birth_date": |
915 | - case "wedding_date": |
916 | - emit(prefix+k+":"+v.substring(v.indexOf("-")), null); break; // drop year |
917 | - case "email_addressesaddress": |
918 | - if (v.lastIndexOf("@") > -1) { |
919 | - emit(prefix+k+":"+v.substring(v.lastIndexOf("@")+1), null); break; // drop user part |
920 | - } else if (v.indexOf("!") > -1) { |
921 | - emit(prefix+k+":"+v.substring(0, v.indexOf("!")-1), null); break; // drop user part |
922 | - } |
923 | - } |
924 | - } else { |
925 | - for (subk in v) |
926 | - emit_dict(prefix+k, v[subk]) |
927 | + if (v.substring) { |
928 | + emit(prefix+k+":"+v, null); |
929 | + switch (prefix+k) { // Weird cases that may be useful. |
930 | + case "birth_date": |
931 | + case "wedding_date": |
932 | + emit(prefix+k+":"+v.substring(v.indexOf("-")), null); |
933 | + break; // drop year |
934 | + case "email_addressesaddress": |
935 | + if (v.lastIndexOf("@") > -1) { |
936 | + emit(prefix+k+":"+v.substring( |
937 | + v.lastIndexOf("@")+1), null); |
938 | + break; // drop user part |
939 | + } else if (v.indexOf("!") > -1) { |
940 | + emit(prefix+k+":"+v.substring( |
941 | + 0, v.indexOf("!")-1), null); |
942 | + break; // drop user part |
943 | + } |
944 | } |
945 | + } else { |
946 | + for (subk in v) |
947 | + emit_dict(prefix+k, v[subk]) |
948 | } |
949 | } |
950 | - |
951 | - try { |
952 | - if (doc['application_annotations']['Ubuntu One'] |
953 | - ['private_application_annotations']['deleted']) |
954 | - return; |
955 | - } catch (e) { |
956 | - // nothing |
957 | - } |
958 | - |
959 | - if (doc['record_type'] != '%(CONTACT_RECORD_TYPE)s') |
960 | - { |
961 | + } |
962 | + |
963 | + try { |
964 | + if (doc['application_annotations']['Ubuntu One'] |
965 | + ['private_application_annotations']['deleted']) |
966 | return; |
967 | - } |
968 | - |
969 | - emit_dict("", doc); |
970 | - } |
971 | + } catch (e) { |
972 | + // nothing |
973 | + } |
974 | + |
975 | + if (doc['record_type'] != '%(CONTACT_RECORD_TYPE)s') |
976 | + { |
977 | + return; |
978 | + } |
979 | + |
980 | + emit_dict("", doc); |
981 | +} |
982 | """ % {'CONTACT_RECORD_TYPE': CONTACT_RECORD_TYPE} |
983 | |
984 | |
985 | |
986 | === modified file 'desktopcouch/recordtypes/notes.py' |
987 | --- desktopcouch/recordtypes/notes.py 2010-11-18 19:58:16 +0000 |
988 | +++ desktopcouch/recordtypes/notes.py 2010-11-24 15:19:50 +0000 |
989 | @@ -24,6 +24,7 @@ |
990 | NOTE_RECORD_TYPE = \ |
991 | 'http://www.freedesktop.org/wiki/Specifications/desktopcouch/note' |
992 | |
993 | + |
994 | class Note(Record): |
995 | """Note record """ |
996 | |
997 | |
998 | === modified file 'desktopcouch/recordtypes/tasks.py' |
999 | --- desktopcouch/recordtypes/tasks.py 2010-11-18 19:58:16 +0000 |
1000 | +++ desktopcouch/recordtypes/tasks.py 2010-11-24 15:19:50 +0000 |
1001 | @@ -25,6 +25,7 @@ |
1002 | TASK_RECORD_TYPE = \ |
1003 | 'http://www.freedesktop.org/wiki/Specifications/desktopcouch/task' |
1004 | |
1005 | + |
1006 | class Task(Record): |
1007 | """ Task records.""" |
1008 | |
1009 | @@ -33,4 +34,3 @@ |
1010 | def __init__(self, data=None, record_id=None): |
1011 | super(Task, self).__init__( |
1012 | record_id=record_id, data=data, record_type=TASK_RECORD_TYPE) |
1013 | - |
1014 | |
1015 | === modified file 'desktopcouch/recordtypes/tests/test_notes.py' |
1016 | --- desktopcouch/recordtypes/tests/test_notes.py 2010-11-18 19:58:16 +0000 |
1017 | +++ desktopcouch/recordtypes/tests/test_notes.py 2010-11-24 15:19:50 +0000 |
1018 | @@ -31,8 +31,8 @@ |
1019 | 'content': 'string', |
1020 | # Date fields |
1021 | 'last_change_date': 'date', |
1022 | - 'create_date': 'date' |
1023 | -} |
1024 | + 'create_date': 'date'} |
1025 | + |
1026 | |
1027 | class TestNoteRecord(testtools.TestCase): |
1028 | """Test the Note Record object.""" |
1029 | @@ -50,6 +50,3 @@ |
1030 | # different timezones so we remove the timezone value |
1031 | # before asserting equal |
1032 | self.assertEqual(now[0:-1], note.last_change_date[0:-1]) |
1033 | - |
1034 | - |
1035 | - |
1036 | |
1037 | === modified file 'desktopcouch/recordtypes/tests/test_tasks.py' |
1038 | --- desktopcouch/recordtypes/tests/test_tasks.py 2010-11-18 19:58:16 +0000 |
1039 | +++ desktopcouch/recordtypes/tests/test_tasks.py 2010-11-24 15:19:50 +0000 |
1040 | @@ -23,6 +23,7 @@ |
1041 | |
1042 | from desktopcouch.recordtypes.tasks import Task, TASK_RECORD_TYPE |
1043 | |
1044 | + |
1045 | class TestTaskRecord(testtools.TestCase): |
1046 | """Test the Task Record object.""" |
1047 | |
1048 | @@ -34,4 +35,3 @@ |
1049 | summary = "manuel" |
1050 | task.summary = summary |
1051 | self.assertEqual(summary, task.summary) |
1052 | - |
The attempt to merge lp:~thisfred/desktopcouch/cut-gordian-knot into lp:desktopcouch failed. Below is the output from the failed tests.
Apache CouchDB has started, time to relax. /tmp/tmp_ aNB1V/data/ couchdb. html application. tests.test_ start_local_ couchdb ignDocuments create_ databases_ and_design_ docs ... [OK] application. tests.test_ service start_desktopco uch_replication ... [OK] start_new_ desktopcouch_ extensions ... [OK] start_new_ desktopcouch_ no_extensions ... [OK] application. tests.test_ local_files tegration with_no_ auth ... [OK] all_files_ returned ... [OK] bind_address ... [OK] couch_chain_ ini_files ... [OK] xdg_overwrite_ works ... [OK] application. tests.test_ replication /tmp/tmpJFAsvR/ data/couchdb. html
[OK] Replication /tmp/tmpBXpLld/ data/couchdb. html
[OK] application. migration. tests.test_ migration migration_ script_ is_run ... [OK] migration_ script_ is_run_ and_can_ access_ view ... [OK] register_ migration_ add_view_ to_a_given_ db ... [OK] register_ migration_ add_view_ to_all_ the_dbs ... [OK] register_ migration_ is_added_ to_the_ registry ... [OK] application. pair.tests. test_couchdb_ io get_database_ names_replicata ble ... [OK] get_my_ host_unique_ id ... [OK] obsfuscation ... [OK] put_dynamic_ paired_ host ... [OK] put_static_ paired_ service ... [OK] application. pair.tests. test_ubuntuone_ pairing airing pair_with_ ubuntuone_ no_record ... [OK] pair_with_ ubuntuone_ no_view ... [OK] pair_with_ ubuntuone_ record_ present ... [OK] pair_with_ ubuntuone_ user_deleted_ record ... [...
Browse your desktop CouchDB at file://
desktopcouch.
TestUpdateDes
test_
desktopcouch.
TestService
test_
test_
test_
desktopcouch.
TestKeyringIn
test_with_auth ... [OK]
test_
TestLocalFiles
test_
test_
test_
test_
desktopcouch.
TestReplication
test_creation ... Apache CouchDB has started, time to relax.
Browse your desktop CouchDB at file://
TestUbuntuone
test_exclusion ... Apache CouchDB has started, time to relax.
Browse your desktop CouchDB at file://
desktopcouch.
TestMigration
test_
test_
TestRegistration
test_
test_
test_
desktopcouch.
TestCouchdbIo
test_
test_
test_mkuri ... [OK]
test_
test_
test_
desktopcouch.
TestUbuntoneP
test_
test_
test_
test_