Author: tack
Date: Wed Oct 4 19:48:00 2006
New Revision: 1912
Modified:
trunk/base/src/db.py
trunk/base/src/notifier/callback.py
trunk/base/test/callbacks.py
Log:
Support weakref for functions; don't update types table if type hasn't
really changed; support the case when modifying an existing type attribute;
commit after registering object type attr, just to be safe; reload object
types after updating attributes of an existing object type.
Modified: trunk/base/src/db.py
==============================================================================
--- trunk/base/src/db.py (original)
+++ trunk/base/src/db.py Wed Oct 4 19:48:00 2006
@@ -64,7 +64,7 @@
STOP_WORDS = (
"about", "and", "are", "but", "com", "for", "from", "how", "not",
"some", "that", "the", "this", "was", "what", "when", "where", "who",
- "will", "with", "the", "www", "http", "org", "of"
+ "will", "with", "the", "www", "http", "org", "of", "on"
)
WORDS_DELIM = re.compile("[\W_\d]+", re.U)
@@ -246,15 +246,18 @@
cur_type_id, cur_type_attrs, cur_type_idx =
self._object_types[type_name]
new_attrs = {}
table_needs_rebuild = False
+ changed = False
for attr_name, (attr_type, attr_flags) in attrs.items():
- # FIXME: if attribute type or flags have changed, the table
- # won't get updated.
- if attr_name not in cur_type_attrs:
+ if attr_name not in cur_type_attrs or
cur_type_attrs[attr_name] != (attr_type, attr_flags):
new_attrs[attr_name] = attr_type, attr_flags
+ changed = True
if attr_flags:
# New attribute isn't simple, needs to alter table.
table_needs_rebuild = True
+ if not changed:
+ return
+
# Update the attr list to merge both existing and new attributes.
attrs = cur_type_attrs.copy()
attrs.update(new_attrs)
@@ -275,6 +278,8 @@
self._db_query("UPDATE types SET idx_pickle=? WHERE id=?",
(buffer(cPickle.dumps(indexes, 2)),
cur_type_id))
+ self.commit()
+ self._load_object_types()
return
# We need to update the database now ...
@@ -322,6 +327,10 @@
if new_attrs:
# Migrate rows from old table to new one.
+ # FIXME: this does not migrate data in the case of an attribute
+ # being changed from simple to searchable or vice versa. In the
+ # simple->searchable case, the data will stay in the pickle; in
+ # the searchable->simple case, the data will be lost.
columns = filter(lambda x: cur_type_attrs[x][1],
cur_type_attrs.keys())
columns = string.join(columns, ",")
self._db_query("INSERT INTO %s_tmp (%s) SELECT %s FROM %s" % \
@@ -354,6 +363,7 @@
# Create multi-column indexes; indexes value has already been verified.
self._register_create_multi_indexes(indexes, table_name)
+ self.commit()
def _load_object_types(self):
Modified: trunk/base/src/notifier/callback.py
==============================================================================
--- trunk/base/src/notifier/callback.py (original)
+++ trunk/base/src/notifier/callback.py Wed Oct 4 19:48:00 2006
@@ -52,7 +52,7 @@
def weakref_data(data, destroy_cb = None):
- if type(data) in (str, int, long, types.NoneType):
+ if type(data) in (str, int, long, types.NoneType, types.FunctionType):
# Naive optimization for common immutable cases.
return data
elif type(data) == types.MethodType:
@@ -73,7 +73,7 @@
for key, val in data.items():
d[weakref_data(key)] = weakref_data(val, destroy_cb)
return d
- elif type(data) != types.FunctionType:
+ else:
try:
if destroy_cb:
return _weakref.ref(data, destroy_cb)
Modified: trunk/base/test/callbacks.py
==============================================================================
--- trunk/base/test/callbacks.py (original)
+++ trunk/base/test/callbacks.py Wed Oct 4 19:48:00 2006
@@ -172,6 +172,8 @@
del cb
# XXX: with the new code this will fail until emit() is called.
test(sig.count(), 0)
+sig.emit()
+test(sig.count(), 0)
result = []
sig.emit()
@@ -181,6 +183,7 @@
cb = Cls().meth
sig.connect_weak(cb, Cls())
test(sig.count(), 0)
-
+sig.emit()
+test(sig.count(), 0)
# TODO: test threads too.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog