diff MoinMoin/config/multiconfig.py @ 1118:156d160b1dd9

Load the IWID and the meta dict lazily.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Mon, 31 Jul 2006 12:01:57 +0200
parents 2aa53ed0afa0
children 84f94820d612
line wrap: on
line diff
--- a/MoinMoin/config/multiconfig.py	Mon Jul 31 11:20:22 2006 +0200
+++ b/MoinMoin/config/multiconfig.py	Mon Jul 31 12:01:57 2006 +0200
@@ -552,17 +552,33 @@
 
         # check if mail is possible and set flag:
         self.mail_enabled = (self.mail_smarthost is not None or self.mail_sendmail is not None) and self.mail_from
-        
-        self.meta_dict = wikiutil.MetaDict(os.path.join(data_dir, 'meta'), self.cache_dir)
 
-        # interwiki ID processing
-        self.load_IWID()
+        # Cache variables for the properties below
+        self._iwid = self._iwid_full = self._meta_dict = None
+
+    def load_meta_dict(self):
+        """ The meta_dict contains meta data about the wiki instance. """
+        if getattr(self, "_meta_dict", None) is None:
+            self._meta_dict = wikiutil.MetaDict(os.path.join(self.data_dir, 'meta'), self.cache_dir)
+        return self._meta_dict
+    meta_dict = property(load_meta_dict)
+
+    # lazily load iwid(_full)
+    def make_iwid_property(attr):
+        def getter(self):
+            if getattr(self, attr, None) is None:
+                self.load_IWID()
+            return getattr(self, attr)
+        return property(getter)
+    iwid = make_iwid_property("_iwid")
+    iwid_full = make_iwid_property("_iwid_full")
 
     def load_IWID(self):
         """ Loads the InterWikiID of this instance. It is used to identify the instance
             globally.
             The IWID is available as cfg.iwid
             The full IWID containing the interwiki name is available as cfg.iwid_full
+            This method is called by the property.
         """
 
         try:
@@ -572,11 +588,11 @@
             self.meta_dict['IWID'] = iwid
             self.meta_dict.sync()
 
-        self.iwid = iwid
+        self._iwid = iwid
         if self.interwikiname is not None:
-            self.iwid_full = packLine([iwid, self.interwikiname])
+            self._iwid_full = packLine([iwid, self.interwikiname])
         else:
-            self.iwid_full = packLine([iwid])
+            self._iwid_full = packLine([iwid])
 
     def _config_check(self):
         """ Check namespace and warn about unknown names