Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Private Member Functions
MoinMoin.wikiutil.MetaDict Class Reference

List of all members.

Public Member Functions

def __init__
def sync
def __getitem__
def __setitem__

Public Attributes

 metafilename
 dirty
 rlock
 wlock

Private Member Functions

def _get_meta
def _put_meta

Detailed Description

store meta informations as a dict.

Definition at line 337 of file wikiutil.py.


Constructor & Destructor Documentation

def MoinMoin.wikiutil.MetaDict.__init__ (   self,
  metafilename,
  cache_directory 
)
create a MetaDict from metafilename 

Definition at line 340 of file wikiutil.py.

00340 
00341     def __init__(self, metafilename, cache_directory):
00342         """ create a MetaDict from metafilename """
00343         dict.__init__(self)
00344         self.metafilename = metafilename
00345         self.dirty = False
00346         lock_dir = os.path.join(cache_directory, '__metalock__')
00347         self.rlock = lock.ReadLock(lock_dir, 60.0)
00348         self.wlock = lock.WriteLock(lock_dir, 60.0)
00349 
00350         if not self.rlock.acquire(3.0):
00351             raise EnvironmentError("Could not lock in MetaDict")
00352         try:
00353             self._get_meta()
00354         finally:
00355             self.rlock.release()


Member Function Documentation

def MoinMoin.wikiutil.MetaDict.__getitem__ (   self,
  key 
)
We don't care for cache coherency here. 

Definition at line 400 of file wikiutil.py.

00400 
00401     def __getitem__(self, key):
00402         """ We don't care for cache coherency here. """
00403         return dict.__getitem__(self, key)

def MoinMoin.wikiutil.MetaDict.__setitem__ (   self,
  key,
  value 
)
Sets a dictionary entry. 

Definition at line 404 of file wikiutil.py.

00404 
00405     def __setitem__(self, key, value):
00406         """ Sets a dictionary entry. """
00407         if not self.wlock.acquire(5.0):
00408             raise EnvironmentError("Could not lock in MetaDict")
00409         try:
00410             self._get_meta() # refresh cache
00411             try:
00412                 oldvalue = dict.__getitem__(self, key)
00413             except KeyError:
00414                 oldvalue = None
00415             if value != oldvalue:
00416                 dict.__setitem__(self, key, value)
00417                 self._put_meta() # sync cache
00418         finally:
00419             self.wlock.release()
00420 
00421 
00422 # Quoting of wiki names, file names, etc. (in the wiki markup) -----------------------------------
00423 
# don't ever change this - DEPRECATED, only needed for 1.5 > 1.6 migration conversion

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.wikiutil.MetaDict._get_meta (   self) [private]
get the meta dict from an arbitrary filename.
    does not keep state, does uncached, direct disk access.
    @param metafilename: the name of the file to read
    @return: dict with all values or {} if empty or error

Definition at line 356 of file wikiutil.py.

00356 
00357     def _get_meta(self):
00358         """ get the meta dict from an arbitrary filename.
00359             does not keep state, does uncached, direct disk access.
00360             @param metafilename: the name of the file to read
00361             @return: dict with all values or {} if empty or error
00362         """
00363 
00364         try:
00365             metafile = codecs.open(self.metafilename, "r", "utf-8")
00366             meta = metafile.read() # this is much faster than the file's line-by-line iterator
00367             metafile.close()
00368         except IOError:
00369             meta = u''
00370         for line in meta.splitlines():
00371             key, value = line.split(':', 1)
00372             value = value.strip()
00373             if key in INTEGER_METAS:
00374                 value = int(value)
00375             dict.__setitem__(self, key, value)

Here is the caller graph for this function:

def MoinMoin.wikiutil.MetaDict._put_meta (   self) [private]
put the meta dict into an arbitrary filename.
    does not keep or modify state, does uncached, direct disk access.
    @param metafilename: the name of the file to write
    @param metadata: dict of the data to write to the file

Definition at line 376 of file wikiutil.py.

00376 
00377     def _put_meta(self):
00378         """ put the meta dict into an arbitrary filename.
00379             does not keep or modify state, does uncached, direct disk access.
00380             @param metafilename: the name of the file to write
00381             @param metadata: dict of the data to write to the file
00382         """
00383         meta = []
00384         for key, value in self.items():
00385             if key in INTEGER_METAS:
00386                 value = str(value)
00387             meta.append("%s: %s" % (key, value))
00388         meta = '\r\n'.join(meta)
00389 
00390         metafile = codecs.open(self.metafilename, "w", "utf-8")
00391         metafile.write(meta)
00392         metafile.close()
00393         self.dirty = False

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.wikiutil.MetaDict.sync (   self,
  mtime_usecs = None 
)
No-Op except for that parameter 

Definition at line 394 of file wikiutil.py.

00394 
00395     def sync(self, mtime_usecs=None):
00396         """ No-Op except for that parameter """
00397         if not mtime_usecs is None:
00398             self.__setitem__('mtime', str(mtime_usecs))
00399         # otherwise no-op

Here is the call graph for this function:


Member Data Documentation

Definition at line 344 of file wikiutil.py.

Definition at line 343 of file wikiutil.py.

Definition at line 346 of file wikiutil.py.

Definition at line 347 of file wikiutil.py.


The documentation for this class was generated from the following file: