]> jfr.im git - irc/rizon/acid.git/commitdiff
Do not commit collection attributes that begin with an underscore. Rename dirty ...
authorAdam <redacted>
Wed, 15 Oct 2014 22:07:55 +0000 (18:07 -0400)
committerAdam <redacted>
Wed, 15 Oct 2014 22:07:55 +0000 (18:07 -0400)
pyva/pyva/src/main/python/pseudoclient/collection.py

index 13de0bad427a4edaa3ece3d47ff67ba59bc5ac6f..dd53e38bbcab77bee8d90f64964f700d7199e9ff 100644 (file)
@@ -2,7 +2,6 @@ from datetime import datetime
 from utils import *
 from istring import *
 import traceback
-import inspect
 
 class InvariantCollection(object):
        def __init__(self):
@@ -50,7 +49,7 @@ class CollectionEntity(object):
                self.ban_reason = ban_reason
                self.ban_date = ban_date
                self.ban_expiry = ban_expiry
-               self.dirty = False
+               self._dirty = False
                self.registered = self.banned = False
 
        def unserialize(self, key, value):
@@ -94,8 +93,7 @@ class CollectionManager(InvariantCollection):
                                e.unserialize(row2[0], row2[1])
 
        def __get_attributes(self, obj):
-               boring = dir(type('dummy', (object,), {}))
-               return [item for item in inspect.getmembers(obj) if item[0] not in boring]
+               return [item for item in dir(obj) if not item.startswith('_')]
 
        def commit(self):
                try:
@@ -114,8 +112,7 @@ class CollectionManager(InvariantCollection):
                                else: # delete options as we are aboue to re-flush them
                                        self.cursor.execute("DELETE FROM " + self.module.name + "_" + self.name + "_options WHERE `id` = %s", (e.id,))
 
-                               for a in self.__get_attributes(e):
-                                       attr_name = a[0]
+                               for attr_name in self.__get_attributes(e):
                                        attr = getattr(e, attr_name)
                                        if attr:
                                                self.cursor.execute("INSERT INTO " + self.module.name + "_" + self.name + "_options (id, name, value) VALUES (%s, %s, %s)", (e.id, attr_name, attr))
@@ -125,7 +122,7 @@ class CollectionManager(InvariantCollection):
                        self.clear_deleted()
 
                        for e in self.list_all():
-                               e.dirty = False
+                               e._dirty = False
                except Exception, err:
                        traceback.print_exc()
                        self.module.elog.error(self.name + ' commit failed: @b%s@b' % err)
@@ -142,7 +139,7 @@ class CollectionManager(InvariantCollection):
        def is_dirty(self, item):
                self.check(item)
 
-               return item in self and self[item].dirty
+               return item in self and self[item]._dirty
 
        def is_valid(self, item):
                self.check(item)
@@ -166,12 +163,12 @@ class CollectionManager(InvariantCollection):
 
                if old_value != value:
                        setattr(entity, attribute, value)
-                       entity.dirty = True
+                       entity._dirty = True
 
        def add(self, item):
                if not item in self:
                        entity = self.__type(-1, item)
-                       entity.dirty = True
+                       entity._dirty = True
                        entity.registered = True
                        self[item] = entity
 
@@ -188,7 +185,7 @@ class CollectionManager(InvariantCollection):
                if entity.banned and entity.registered:
                        entity.registered = False
                        entity.clear()
-                       entity.dirty = True
+                       entity._dirty = True
                elif not entity.banned:
                        if not item.lower() in self.__deleted_items:
                                self.__deleted_items.append(entity)
@@ -204,7 +201,7 @@ class CollectionManager(InvariantCollection):
                entity.ban_reason = reason
                entity.ban_date = date
                entity.ban_expiry = expiry
-               entity.dirty = True
+               entity._dirty = True
 
                self.on_banned(item)
 
@@ -222,7 +219,7 @@ class CollectionManager(InvariantCollection):
                if not entity.registered:
                        self.remove(item)
                else:
-                       entity.dirty = True
+                       entity._dirty = True
 
                self.on_unbanned(item)