Added default to settings_object.versioned_property's change_hook_property.
authorW. Trevor King <wking@drexel.edu>
Mon, 27 Jul 2009 11:47:35 +0000 (07:47 -0400)
committerW. Trevor King <wking@drexel.edu>
Mon, 27 Jul 2009 11:47:35 +0000 (07:47 -0400)
Now change_hook properties handle defaults, which allows them to avoid
an initial
  None -> default
save hook trigger.

Removed the now-redundant read-only mode business in
becommands/diff.py.

becommands/diff.py
libbe/properties.py
libbe/settings_object.py

index b0ef907ef73982ed509aad68f516ee7ea10eb9d7..1ab21357ade8c9f0adfb26865dfe0643389fba1e 100644 (file)
@@ -65,12 +65,6 @@ def execute(args, manipulate_encodings=True):
     else:
         if revision == None: # get the most recent revision
             revision = bd.rcs.revision_id(-1)
-        # move bd into memory-only mode to avoid altering disk version.
-        bd.load_all_bugs()
-        for bug in bd:
-            bug.load_settings()
-            bug.load_comments()
-        bd.set_sync_with_disk(False)
         old_bd = bd.duplicate_bugdir(revision)
         d = diff.Diff(old_bd, bd)
         tree = d.report_tree()
index 144220b181d0d06df08062d773da1a6c7687df39..09dd20e0417de099434d038f6ba254a2ba457323 100644 (file)
@@ -160,10 +160,10 @@ def _get_cached_mutable_property(self, cacher_name, property_name, default=None)
     if (cacher_name, property_name) not in self._mutable_property_cache_copy:
         return default
     return self._mutable_property_cache_copy[(cacher_name, property_name)]
-def _cmp_cached_mutable_property(self, cacher_name, property_name, value):
+def _cmp_cached_mutable_property(self, cacher_name, property_name, value, default=None):
     _init_mutable_property_cache(self)
     if (cacher_name, property_name) not in self._mutable_property_cache_hash:
-        return 1 # any value > non-existant old hash
+        _set_cached_mutable_property(self, cacher_name, property_name, default)
     old_hash = self._mutable_property_cache_hash[(cacher_name, property_name)]
     return cmp(_hash_mutable_value(value), old_hash)
 
@@ -327,7 +327,7 @@ def primed_property(primer, initVal=None):
         return funcs
     return decorator
 
-def change_hook_property(hook, mutable=False):
+def change_hook_property(hook, mutable=False, default=None):
     """
     Call the function hook(instance, old_value, new_value) whenever a
     value different from the current value is set (instance is a a
@@ -359,9 +359,9 @@ def change_hook_property(hook, mutable=False):
                 value = new_value # compare new value with cached
             else:
                 value = fget(self) # compare current value with cached
-            if _cmp_cached_mutable_property(self, "change hook property", name, value) != 0:
+            if _cmp_cached_mutable_property(self, "change hook property", name, value, default) != 0:
                 # there has been a change, cache new value
-                old_value = _get_cached_mutable_property(self, "change hook property", name)
+                old_value = _get_cached_mutable_property(self, "change hook property", name, default)
                 _set_cached_mutable_property(self, "change hook property", name, value)
                 if from_fset == True: # return previously cached value
                     value = old_value
index dde247fb65c399eac52c455fa82cfa0f1410ee2e..ceea9d551e831b0b4d8b19719bcd7fad3ce75c42 100644 (file)
@@ -148,7 +148,8 @@ def versioned_property(name, doc,
             checked = checked_property(allowed=allowed)
             fulldoc += "\n\nThe allowed values for this property are: %s." \
                        % (', '.join(allowed))
-        hooked      = change_hook_property(hook=change_hook, mutable=mutable)
+        hooked      = change_hook_property(hook=change_hook, mutable=mutable,
+                                           default=EMPTY)
         primed      = primed_property(primer=primer, initVal=UNPRIMED)
         settings    = settings_property(name=name, null=UNPRIMED)
         docp        = doc_property(doc=fulldoc)
@@ -385,30 +386,24 @@ class SavedSettingsObjectTests(unittest.TestCase):
         self.failUnless(SAVES == [], SAVES)
         self.failUnless(t._settings_loaded == True, t._settings_loaded)
         self.failUnless(t.list_type == None, t.list_type)
-        self.failUnless(SAVES == [
-                "'None' -> '<class 'libbe.settings_object.EMPTY'>'"
-                ], SAVES)
+        self.failUnless(SAVES == [], SAVES)
         self.failUnless(t.settings["List-type"]==EMPTY,t.settings["List-type"])
         t.list_type = []
         self.failUnless(t.settings["List-type"] == [], t.settings["List-type"])
         self.failUnless(SAVES == [
-                "'None' -> '<class 'libbe.settings_object.EMPTY'>'",
                 "'<class 'libbe.settings_object.EMPTY'>' -> '[]'"
                 ], SAVES)
         t.list_type.append(5)
         self.failUnless(SAVES == [
-                "'None' -> '<class 'libbe.settings_object.EMPTY'>'",
                 "'<class 'libbe.settings_object.EMPTY'>' -> '[]'",
                 ], SAVES)
         self.failUnless(t.settings["List-type"] == [5],t.settings["List-type"])
         self.failUnless(SAVES == [ # the append(5) has not yet been saved
-                "'None' -> '<class 'libbe.settings_object.EMPTY'>'",
                 "'<class 'libbe.settings_object.EMPTY'>' -> '[]'",
                 ], SAVES)
         self.failUnless(t.list_type == [5], t.list_type) # <-get triggers saved
 
         self.failUnless(SAVES == [ # now the append(5) has been saved.
-                "'None' -> '<class 'libbe.settings_object.EMPTY'>'",
                 "'<class 'libbe.settings_object.EMPTY'>' -> '[]'",
                 "'[]' -> '[5]'"
                 ], SAVES)