Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
CMFEditions.ZVCStorageTool.ShadowHistory Class Reference
Inheritance diagram for CMFEditions.ZVCStorageTool.ShadowHistory:
Inheritance graph
[legend]
Collaboration diagram for CMFEditions.ZVCStorageTool.ShadowHistory:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def save
def retrieve
def purge
def getLength
def getSize
def getVersionId

Public Attributes

 nextVersionId

Private Member Functions

def _getVersionPos

Private Attributes

 _full
 _available
 _approxSize
 _sizeInaccurate

Detailed Description

Purge Aware History for Storage Related Metadata

Definition at line 764 of file ZVCStorageTool.py.


Constructor & Destructor Documentation

Definition at line 767 of file ZVCStorageTool.py.

00767 
00768     def __init__(self):
00769         # Using a IOBtree as we know the selectors are integers.
00770         # The full history contains shadow data for every saved version. 
00771         # A counter is needed as IOBTree doesn't have a list like append.
00772         self._full = IOBTree()
00773         self.nextVersionId = 0
00774         
00775         # Indexes to the full histories versions
00776         self._available = []
00777         
00778         # aproximative size of the history
00779         self._approxSize = 0
00780         self._sizeInaccurate = False


Member Function Documentation

def CMFEditions.ZVCStorageTool.ShadowHistory._getVersionPos (   self,
  selector,
  countPurged 
) [private]
Returns the Position in the Version History 

The position returned does not count purged versions.

Definition at line 887 of file ZVCStorageTool.py.

00887 
00888     def _getVersionPos(self, selector, countPurged):
00889         """Returns the Position in the Version History 
00890         
00891         The position returned does not count purged versions.
00892         """
00893         if not countPurged:
00894             if selector is None:
00895                 # version counting starts with 0
00896                 selector = self.getLength(countPurged=False) - 1
00897             return int(selector)
00898         
00899         # Lets search from the end of the available list as it is more 
00900         # likely that a younger versions position has to be returned.
00901         # Let's work on a copy to not trigger an unecessary ZODB store
00902         # operations.
00903         history = self._available[:]
00904         history.reverse()
00905         try:
00906             selector = len(history) - 1 - history.index(selector)
00907         except ValueError:
00908             selector = None
00909         return selector
00910 
00911 InitializeClass(ShadowHistory)
00912 

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFEditions.ZVCStorageTool.ShadowHistory.getLength (   self,
  countPurged 
)
Length of the History Either Counting Purged Versions or Not

Definition at line 838 of file ZVCStorageTool.py.

00838 
00839     def getLength(self, countPurged):
00840         """Length of the History Either Counting Purged Versions or Not
00841         """
00842         if countPurged:
00843             return self.nextVersionId
00844         else:
00845             return len(self._available)

Here is the caller graph for this function:

Returns the size including the quality of the size

Definition at line 846 of file ZVCStorageTool.py.

00846 
00847     def getSize(self):
00848         """Returns the size including the quality of the size
00849         """
00850         # don't like exceptions taking down CMFEditions
00851         if getattr(self, "_sizeInaccurate", None) is None:
00852             return 0, "not available"
00853         if self._sizeInaccurate:
00854             return self._approxSize, "inaccurate"
00855         else:
00856             return self._approxSize, "approximate"

def CMFEditions.ZVCStorageTool.ShadowHistory.getVersionId (   self,
  selector,
  countPurged 
)
Returns the Effective Version id depending the selector type

Returns ``None`` if the selected version does not exist.

Definition at line 857 of file ZVCStorageTool.py.

00857 
00858     def getVersionId(self, selector, countPurged):
00859         """Returns the Effective Version id depending the selector type
00860         
00861         Returns ``None`` if the selected version does not exist.
00862         """
00863         if selector is not None:
00864             selector = int(selector)
00865         
00866         ##### looking at special selectors first (None, negative)
00867         length = self.getLength(countPurged)
00868         # checking for ``None`` selector (youngest version)
00869         if selector is None:
00870             return length - 1
00871         # checking if positive selector tries to look into future
00872         if selector >= length:
00873             return None
00874         # check if negative selector and if it looks to far into past
00875         if selector < 0:
00876             selector = length - selector
00877             if selector < 0:
00878                 return None
00879         
00880         #### normal cases (0 <= selectors < length)
00881         if countPurged:
00882             # selector is a normal selector
00883             return selector
00884         else:
00885             # selector is a positional selector
00886             return self._available[selector]

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFEditions.ZVCStorageTool.ShadowHistory.purge (   self,
  selector,
  data,
  countPurged 
)
Purge selected version from the history

Definition at line 815 of file ZVCStorageTool.py.

00815 
00816     def purge(self, selector, data, countPurged):
00817         """Purge selected version from the history
00818         """
00819         # find the position to purge
00820         version_pos = self._getVersionPos(selector, countPurged)
00821         version_id = self._available[version_pos]
00822         
00823         # update the histories size
00824         sys_metadata = self._full[version_id]["metadata"]["sys_metadata"]
00825         size = sys_metadata.get("approxSize", None)
00826         if size is None:
00827             self._sizeInaccurate = True
00828         else:
00829             self._approxSize -= size
00830             if self._approxSize < 0:
00831                 self._approxSize = 0
00832                 self._sizeInaccurate = True
00833         
00834         # update the metadata
00835         self._full[version_id]["metadata"] = deepCopy(data)
00836         # purge the reference
00837         del self._available[version_pos]

Here is the call graph for this function:

def CMFEditions.ZVCStorageTool.ShadowHistory.retrieve (   self,
  selector,
  countPurged 
)
Retrieves the Selected Data From the History

The caller has to make a copy if he passed the data to another 
caller.

Returns None if the selected version does not exist.

Definition at line 802 of file ZVCStorageTool.py.

00802 
00803     def retrieve(self, selector, countPurged):
00804         """Retrieves the Selected Data From the History
00805         
00806         The caller has to make a copy if he passed the data to another 
00807         caller.
00808         
00809         Returns None if the selected version does not exist.
00810         """
00811         version_id = self.getVersionId(selector, countPurged)
00812         if version_id is None:
00813             return None
00814         return self._full[version_id]

Here is the call graph for this function:

Saves data in the history

Returns the version id of the saved version.

Definition at line 781 of file ZVCStorageTool.py.

00781 
00782     def save(self, data):
00783         """Saves data in the history
00784         
00785         Returns the version id of the saved version.
00786         """
00787         version_id = self.nextVersionId
00788         self._full[version_id] = deepCopy(data)
00789         self._available.append(version_id)
00790         # Provokes a write conflict if two saves happen the same
00791         # time. That's exactly what's desired.
00792         self.nextVersionId += 1
00793         
00794         # update the histories size:
00795         size = data["metadata"]["sys_metadata"].get("approxSize", None)
00796         if size is None:
00797             self._sizeInaccurate = True
00798         else:
00799             self._approxSize += size
00800         
00801         return version_id

Here is the call graph for this function:


Member Data Documentation

Definition at line 778 of file ZVCStorageTool.py.

Definition at line 775 of file ZVCStorageTool.py.

Definition at line 771 of file ZVCStorageTool.py.

Definition at line 779 of file ZVCStorageTool.py.

Definition at line 772 of file ZVCStorageTool.py.


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