|
1 | | -# $Id: rdbms_common.py,v 1.164 2006-01-30 00:36:26 richard Exp $ |
| 1 | +# $Id: rdbms_common.py,v 1.165 2006-02-06 21:00:47 richard Exp $ |
2 | 2 | ''' Relational database (SQL) backend common code. |
3 | 3 |
|
4 | 4 | Basics: |
|
32 | 32 | import sys, os, time, re, errno, weakref, copy, logging |
33 | 33 |
|
34 | 34 | # roundup modules |
35 | | -from roundup import hyperdb, date, password, roundupdb, security |
| 35 | +from roundup import hyperdb, date, password, roundupdb, security, support |
36 | 36 | from roundup.hyperdb import String, Password, Date, Interval, Link, \ |
37 | 37 | Multilink, DatabaseError, Boolean, Number, Node |
38 | 38 | from roundup.backends import locking |
39 | 39 |
|
40 | 40 | # support |
41 | 41 | from blobfiles import FileStorage |
42 | 42 | try: |
43 | | - # re-enable once Xapian is fixed |
44 | | - from indexer_xapian import Indexer_disabled |
| 43 | + from indexer_xapian import Indexer |
45 | 44 | except ImportError: |
46 | 45 | from indexer_rdbms import Indexer |
47 | 46 | from sessions_rdbms import Sessions, OneTimeKeys |
@@ -317,14 +316,19 @@ def refresh_database(self): |
317 | 316 | self.post_init() |
318 | 317 |
|
319 | 318 |
|
320 | | - def reindex(self, classname=None): |
| 319 | + def reindex(self, classname=None, show_progress=False): |
321 | 320 | if classname: |
322 | 321 | classes = [self.getclass(classname)] |
323 | 322 | else: |
324 | 323 | classes = self.classes.values() |
325 | 324 | for klass in classes: |
326 | | - for nodeid in klass.list(): |
327 | | - klass.index(nodeid) |
| 325 | + if show_progress: |
| 326 | + for nodeid in support.Progress('Reindex %s'%klass.classname, |
| 327 | + klass.list()): |
| 328 | + klass.index(nodeid) |
| 329 | + else: |
| 330 | + for nodeid in klass.list(): |
| 331 | + klass.index(nodeid) |
328 | 332 | self.indexer.save_index() |
329 | 333 |
|
330 | 334 | hyperdb_to_sql_datatypes = { |
@@ -2371,15 +2375,17 @@ def import_list(self, propnames, proplist): |
2371 | 2375 | pwd = password.Password() |
2372 | 2376 | pwd.unpack(value) |
2373 | 2377 | value = pwd |
2374 | | - d[propname] = value |
2375 | | - if isinstance(prop, String): |
2376 | | - if type(value) != type('') and type(value) != type(u''): |
| 2378 | + elif isinstance(prop, String): |
| 2379 | + if isinstance(value, unicode): |
| 2380 | + value = value.encode('utf8') |
| 2381 | + if not isinstance(value, str): |
2377 | 2382 | raise TypeError, \ |
2378 | 2383 | 'new property "%(propname)s" not a string: %(value)r' \ |
2379 | 2384 | % locals() |
2380 | 2385 | if prop.indexme: |
2381 | 2386 | self.db.indexer.add_text((self.classname, newid, propname), |
2382 | 2387 | value) |
| 2388 | + d[propname] = value |
2383 | 2389 |
|
2384 | 2390 | # get a new id if necessary |
2385 | 2391 | if newid is None: |
|
0 commit comments