comparison 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
comparison
equal deleted inserted replaced
1111:2aa53ed0afa0 1118:156d160b1dd9
550 # list to cache xapian searcher objects 550 # list to cache xapian searcher objects
551 self.xapian_searchers = [] 551 self.xapian_searchers = []
552 552
553 # check if mail is possible and set flag: 553 # check if mail is possible and set flag:
554 self.mail_enabled = (self.mail_smarthost is not None or self.mail_sendmail is not None) and self.mail_from 554 self.mail_enabled = (self.mail_smarthost is not None or self.mail_sendmail is not None) and self.mail_from
555 555
556 self.meta_dict = wikiutil.MetaDict(os.path.join(data_dir, 'meta'), self.cache_dir) 556 # Cache variables for the properties below
557 557 self._iwid = self._iwid_full = self._meta_dict = None
558 # interwiki ID processing 558
559 self.load_IWID() 559 def load_meta_dict(self):
560 """ The meta_dict contains meta data about the wiki instance. """
561 if getattr(self, "_meta_dict", None) is None:
562 self._meta_dict = wikiutil.MetaDict(os.path.join(self.data_dir, 'meta'), self.cache_dir)
563 return self._meta_dict
564 meta_dict = property(load_meta_dict)
565
566 # lazily load iwid(_full)
567 def make_iwid_property(attr):
568 def getter(self):
569 if getattr(self, attr, None) is None:
570 self.load_IWID()
571 return getattr(self, attr)
572 return property(getter)
573 iwid = make_iwid_property("_iwid")
574 iwid_full = make_iwid_property("_iwid_full")
560 575
561 def load_IWID(self): 576 def load_IWID(self):
562 """ Loads the InterWikiID of this instance. It is used to identify the instance 577 """ Loads the InterWikiID of this instance. It is used to identify the instance
563 globally. 578 globally.
564 The IWID is available as cfg.iwid 579 The IWID is available as cfg.iwid
565 The full IWID containing the interwiki name is available as cfg.iwid_full 580 The full IWID containing the interwiki name is available as cfg.iwid_full
581 This method is called by the property.
566 """ 582 """
567 583
568 try: 584 try:
569 iwid = self.meta_dict['IWID'] 585 iwid = self.meta_dict['IWID']
570 except KeyError: 586 except KeyError:
571 iwid = util.random_string(16).encode("hex") + "-" + str(int(time.time())) 587 iwid = util.random_string(16).encode("hex") + "-" + str(int(time.time()))
572 self.meta_dict['IWID'] = iwid 588 self.meta_dict['IWID'] = iwid
573 self.meta_dict.sync() 589 self.meta_dict.sync()
574 590
575 self.iwid = iwid 591 self._iwid = iwid
576 if self.interwikiname is not None: 592 if self.interwikiname is not None:
577 self.iwid_full = packLine([iwid, self.interwikiname]) 593 self._iwid_full = packLine([iwid, self.interwikiname])
578 else: 594 else:
579 self.iwid_full = packLine([iwid]) 595 self._iwid_full = packLine([iwid])
580 596
581 def _config_check(self): 597 def _config_check(self):
582 """ Check namespace and warn about unknown names 598 """ Check namespace and warn about unknown names
583 599
584 Warn about names which are not used by DefaultConfig, except 600 Warn about names which are not used by DefaultConfig, except