Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
MoinMoin.PageEditor.PageLock Class Reference

List of all members.

Public Member Functions

def __init__
def acquire
def release

Public Attributes

 pageobj
 page_name
 request
 cfg
 now
 uid
 locktype
 timeout
 owner
 owner_html
 timestamp

Private Member Functions

def _filename
def _readLockFile
def _writeLockFile
def _deleteLockFile

Private Attributes

 _

Detailed Description

PageLock - Lock pages 

Definition at line 1157 of file PageEditor.py.


Constructor & Destructor Documentation

def MoinMoin.PageEditor.PageLock.__init__ (   self,
  pageobj 
)

Definition at line 1160 of file PageEditor.py.

01160 
01161     def __init__(self, pageobj):
01162         """
01163         """
01164         self.pageobj = pageobj
01165         self.page_name = pageobj.page_name
01166         request = pageobj.request
01167         self.request = request
01168         self._ = self.request.getText
01169         self.cfg = self.request.cfg
01170 
01171         # current time and user for later checks
01172         self.now = int(time.time())
01173         self.uid = request.user.valid and request.user.id or request.remote_addr
01174 
01175         # get details of the locking preference, i.e. warning or lock, and timeout
01176         self.locktype = None
01177         self.timeout = 10 * 60 # default timeout in minutes
01178 
01179         if self.cfg.edit_locking:
01180             lockinfo = self.cfg.edit_locking.split()
01181             if 1 <= len(lockinfo) <= 2:
01182                 self.locktype = lockinfo[0].lower()
01183                 if len(lockinfo) > 1:
01184                     try:
01185                         self.timeout = int(lockinfo[1]) * 60
01186                     except ValueError:
01187                         pass
01188 


Member Function Documentation

Delete the lock file unconditionally. 

Definition at line 1301 of file PageEditor.py.

01301 
01302     def _deleteLockFile(self):
01303         """ Delete the lock file unconditionally. """
01304         try:
01305             os.remove(self._filename())
01306         except OSError:
01307             pass
01308 

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.PageEditor.PageLock._filename (   self) [private]
Get path and filename for edit-lock file. 

Definition at line 1268 of file PageEditor.py.

01268 
01269     def _filename(self):
01270         """ Get path and filename for edit-lock file. """
01271         return self.pageobj.getPagePath('edit-lock', isfile=1)
01272 

Here is the caller graph for this function:

Load lock info if not yet loaded. 

Definition at line 1273 of file PageEditor.py.

01273 
01274     def _readLockFile(self):
01275         """ Load lock info if not yet loaded. """
01276         _ = self._
01277         self.owner = None
01278         self.owner_html = wikiutil.escape(_("<unknown>"))
01279         self.timestamp = 0
01280 
01281         if self.locktype:
01282             try:
01283                 entry = editlog.EditLog(self.request, filename=self._filename()).next()
01284             except StopIteration:
01285                 entry = None
01286 
01287             if entry:
01288                 self.owner = entry.userid or entry.addr
01289                 self.owner_html = entry.getEditor(self.request)
01290                 self.timestamp = wikiutil.version2timestamp(entry.ed_time_usecs)
01291 

Here is the caller graph for this function:

Write new lock file. 

Definition at line 1292 of file PageEditor.py.

01292 
01293     def _writeLockFile(self):
01294         """ Write new lock file. """
01295         self._deleteLockFile()
01296         try:
01297             editlog.EditLog(self.request, filename=self._filename()).add(
01298                self.request, wikiutil.timestamp2version(self.now), 0, "LOCK", self.page_name)
01299         except IOError:
01300             pass

Here is the call graph for this function:

Here is the caller graph for this function:

Begin an edit lock depending on the mode chosen in the config.

@rtype: tuple
@return: tuple is returned containing 2 values:
      * a bool indicating successful acquiry
      * a string giving a reason for failure or an informational msg

Definition at line 1189 of file PageEditor.py.

01189 
01190     def acquire(self):
01191         """ Begin an edit lock depending on the mode chosen in the config.
01192 
01193         @rtype: tuple
01194         @return: tuple is returned containing 2 values:
01195               * a bool indicating successful acquiry
01196               * a string giving a reason for failure or an informational msg
01197         """
01198         if not self.locktype:
01199             # we are not using edit locking, so always succeed
01200             return 1, ''
01201 
01202         _ = self._
01203         #!!! race conditions, need to lock file during queries & update
01204         self._readLockFile()
01205         bumptime = self.request.user.getFormattedDateTime(self.now + self.timeout)
01206         timestamp = self.request.user.getFormattedDateTime(self.timestamp)
01207         owner = self.owner_html
01208         secs_valid = self.timestamp + self.timeout - self.now
01209 
01210         # do we own the lock, or is it stale?
01211         if self.owner is None or self.uid == self.owner or secs_valid < 0:
01212             # create or bump the lock
01213             self._writeLockFile()
01214 
01215             msg = []
01216             if self.owner is not None and -10800 < secs_valid < 0:
01217                 mins_ago = secs_valid / -60
01218                 msg.append(_(
01219                     "The lock of %(owner)s timed out %(mins_ago)d minute(s) ago,"
01220                     " and you were granted the lock for this page."
01221                     ) % {'owner': owner, 'mins_ago': mins_ago})
01222 
01223             if self.locktype == 'lock':
01224                 msg.append(_(
01225                     "Other users will be ''blocked'' from editing this page until %(bumptime)s.",
01226                     wiki=True) % {'bumptime': bumptime})
01227             else:
01228                 msg.append(_(
01229                     "Other users will be ''warned'' until %(bumptime)s that you are editing this page.",
01230                     wiki=True) % {'bumptime': bumptime})
01231             msg.append(_(
01232                 "Use the Preview button to extend the locking period."
01233                 ))
01234             result = 1, '\n'.join(msg)
01235         else:
01236             mins_valid = (secs_valid+59) / 60
01237             if self.locktype == 'lock':
01238                 # lout out user
01239                 result = 0, _(
01240                     "This page is currently ''locked'' for editing by %(owner)s until %(timestamp)s,"
01241                     " i.e. for %(mins_valid)d minute(s).",
01242                     wiki=True) % {'owner': owner, 'timestamp': timestamp, 'mins_valid': mins_valid}
01243             else:
01244                 # warn user about existing lock
01245 
01246                 result = 1, _(
01247 """This page was opened for editing or last previewed at %(timestamp)s by %(owner)s.<<BR>>
01248 '''You should ''refrain from editing'' this page for at least another %(mins_valid)d minute(s),
01249 to avoid editing conflicts.'''<<BR>>
01250 To leave the editor, press the Cancel button.""", wiki=True) % {
01251                     'timestamp': timestamp, 'owner': owner, 'mins_valid': mins_valid}
01252 
01253         return result
01254 

Here is the call graph for this function:

def MoinMoin.PageEditor.PageLock.release (   self,
  force = 0 
)
Release lock, if we own it.

@param force: if 1, unconditionally release the lock.

Definition at line 1255 of file PageEditor.py.

01255 
01256     def release(self, force=0):
01257         """ Release lock, if we own it.
01258 
01259         @param force: if 1, unconditionally release the lock.
01260         """
01261         if self.locktype:
01262             # check that we own the lock in order to delete it
01263             #!!! race conditions, need to lock file during queries & update
01264             self._readLockFile()
01265             if force or self.uid == self.owner:
01266                 self._deleteLockFile()
01267 

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 1167 of file PageEditor.py.

Definition at line 1168 of file PageEditor.py.

Definition at line 1175 of file PageEditor.py.

Definition at line 1171 of file PageEditor.py.

Definition at line 1276 of file PageEditor.py.

Definition at line 1277 of file PageEditor.py.

Definition at line 1164 of file PageEditor.py.

Definition at line 1163 of file PageEditor.py.

Definition at line 1166 of file PageEditor.py.

Definition at line 1176 of file PageEditor.py.

Definition at line 1278 of file PageEditor.py.

Definition at line 1172 of file PageEditor.py.


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