Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Private Member Functions
MoinMoin.script.migration.wikiutil160a.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 380 of file wikiutil160a.py.


Constructor & Destructor Documentation

def MoinMoin.script.migration.wikiutil160a.MetaDict.__init__ (   self,
  metafilename,
  cache_directory 
)
create a MetaDict from metafilename 

Definition at line 383 of file wikiutil160a.py.

00383 
00384     def __init__(self, metafilename, cache_directory):
00385         """ create a MetaDict from metafilename """
00386         dict.__init__(self)
00387         self.metafilename = metafilename
00388         self.dirty = False
00389         lock_dir = os.path.join(cache_directory, '__metalock__')
00390         self.rlock = lock.ReadLock(lock_dir, 60.0)
00391         self.wlock = lock.WriteLock(lock_dir, 60.0)
00392 
00393         if not self.rlock.acquire(3.0):
00394             raise EnvironmentError("Could not lock in MetaDict")
00395         try:
00396             self._get_meta()
00397         finally:
00398             self.rlock.release()


Member Function Documentation

We don't care for cache coherency here. 

Definition at line 443 of file wikiutil160a.py.

00443 
00444     def __getitem__(self, key):
00445         """ We don't care for cache coherency here. """
00446         return dict.__getitem__(self, key)

Here is the caller graph for this function:

Sets a dictionary entry. 

Definition at line 447 of file wikiutil160a.py.

00447 
00448     def __setitem__(self, key, value):
00449         """ Sets a dictionary entry. """
00450         if not self.wlock.acquire(5.0):
00451             raise EnvironmentError("Could not lock in MetaDict")
00452         try:
00453             self._get_meta() # refresh cache
00454             try:
00455                 oldvalue = dict.__getitem__(self, key)
00456             except KeyError:
00457                 oldvalue = None
00458             if value != oldvalue:
00459                 dict.__setitem__(self, key, value)
00460                 self._put_meta() # sync cache
00461         finally:
00462             self.wlock.release()
00463 
00464 
00465 # Quoting of wiki names, file names, etc. (in the wiki markup) -----------------------------------

Here is the call graph for this function:

Here is the caller graph for this function:

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 399 of file wikiutil160a.py.

00399 
00400     def _get_meta(self):
00401         """ get the meta dict from an arbitrary filename.
00402             does not keep state, does uncached, direct disk access.
00403             @param metafilename: the name of the file to read
00404             @return: dict with all values or {} if empty or error
00405         """
00406 
00407         try:
00408             metafile = codecs.open(self.metafilename, "r", "utf-8")
00409             meta = metafile.read() # this is much faster than the file's line-by-line iterator
00410             metafile.close()
00411         except IOError:
00412             meta = u''
00413         for line in meta.splitlines():
00414             key, value = line.split(':', 1)
00415             value = value.strip()
00416             if key in INTEGER_METAS:
00417                 value = int(value)
00418             dict.__setitem__(self, key, value)

Here is the caller graph for this function:

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 419 of file wikiutil160a.py.

00419 
00420     def _put_meta(self):
00421         """ put the meta dict into an arbitrary filename.
00422             does not keep or modify state, does uncached, direct disk access.
00423             @param metafilename: the name of the file to write
00424             @param metadata: dict of the data to write to the file
00425         """
00426         meta = []
00427         for key, value in self.items():
00428             if key in INTEGER_METAS:
00429                 value = str(value)
00430             meta.append("%s: %s" % (key, value))
00431         meta = '\r\n'.join(meta)
00432 
00433         metafile = codecs.open(self.metafilename, "w", "utf-8")
00434         metafile.write(meta)
00435         metafile.close()
00436         self.dirty = False

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 437 of file wikiutil160a.py.

00437 
00438     def sync(self, mtime_usecs=None):
00439         """ No-Op except for that parameter """
00440         if not mtime_usecs is None:
00441             self.__setitem__('mtime', str(mtime_usecs))
00442         # otherwise no-op

Here is the call graph for this function:


Member Data Documentation

Definition at line 387 of file wikiutil160a.py.

Definition at line 386 of file wikiutil160a.py.

Definition at line 389 of file wikiutil160a.py.

Definition at line 390 of file wikiutil160a.py.


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