Back to index

plone3  3.1.7
EventLog.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
00004 # 
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE
00011 # 
00012 ##############################################################################
00013 
00014 from Globals import InitializeClass, Persistent
00015 from AccessControl import ClassSecurityInfo
00016 from BTrees.IOBTree import IOBTree
00017 from Utility import _findUserId
00018 import sys, time
00019 
00020 
00021 class EventLog(Persistent):
00022     """An EventLog encapsulates a collection of log entries."""
00023 
00024     def __init__(self):
00025         self._data = IOBTree()
00026 
00027     security = ClassSecurityInfo()
00028 
00029     security.declarePrivate('addEntry')
00030     def addEntry(self, entry):
00031         """Add a new log entry."""
00032         if len(self._data):
00033             key = self._data.minKey() - 1
00034         else:
00035             key = sys.maxint
00036         self._data[key] = entry
00037 
00038     security.declarePrivate('getEntries')
00039     def getEntries(self):
00040         """Return a sequence of log entries."""
00041         return self._data.values()
00042 
00043     def __len__(self):
00044         return len(self._data)
00045     
00046     def __nonzero__(self):
00047         return len(self._data) > 0
00048 
00049 InitializeClass(EventLog)
00050 
00051 
00052 class LogEntry(Persistent):
00053     """A LogEntry contains audit information about a version control
00054        operation. Actions that cause audit records to be created include 
00055        checkout and checkin. Log entry information can be read (but
00056        not changed) by restricted code."""
00057 
00058     # These action constants represent the possible auditable actions.
00059     ACTION_CHECKOUT = 0
00060     ACTION_CHECKIN = 1
00061     ACTION_UNCHECKOUT = 2
00062     ACTION_UPDATE = 3
00063 
00064     def __init__(self, version_id, action, path=None, message=''):
00065         self.timestamp = time.time()
00066         self.version_id = version_id
00067         self.action = action
00068         self.message = message
00069         self.user_id = _findUserId()
00070         self.path = path
00071 
00072 InitializeClass(LogEntry)