Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes | Private Attributes
CMFEditions.tests.DummyTools.DummyArchivist Class Reference
Inheritance diagram for CMFEditions.tests.DummyTools.DummyArchivist:
Inheritance graph
[legend]
Collaboration diagram for CMFEditions.tests.DummyTools.DummyArchivist:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def getId
def __init__
def log
def get_log
def reset_log
def prepare
def register
def save
def retrieve
def getHistory
def queryHistory
def isUpToDate

Public Attributes

 alog_indent

Static Public Attributes

string id = 'portal_archivist'

Private Attributes

 _archive
 _counter

Detailed Description

Archivist simulating modifiers and history storage.

Definition at line 55 of file DummyTools.py.


Constructor & Destructor Documentation

Definition at line 63 of file DummyTools.py.

00063 
00064     def __init__(self):
00065         self._archive = {}
00066         self._counter = 0
00067         self.reset_log()
00068         self.alog_indent = ''


Member Function Documentation

Definition at line 72 of file DummyTools.py.

00072 
00073     def get_log(self):
00074         return "\n".join(alog)

def CMFEditions.tests.DummyTools.DummyArchivist.getHistory (   self,
  obj = None,
  history_id = None,
  preserve = () 
)

Definition at line 223 of file DummyTools.py.

00223 
00224     def getHistory(self, obj=None, history_id=None, preserve=()):
00225         obj, history_id = dereference(obj, history_id, self)
00226         return [deepCopy(obj) for obj in self._archive[history_id]]

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 60 of file DummyTools.py.

00060 
00061     def getId(self):
00062         return self.id

def CMFEditions.tests.DummyTools.DummyArchivist.isUpToDate (   self,
  obj = None,
  history_id = None,
  selector = None 
)

Definition at line 237 of file DummyTools.py.

00237 
00238     def isUpToDate(self, obj=None, history_id=None, selector=None):
00239         obj = dereference(obj=obj, history_id=history_id, zodb_hook=self)[0]
00240         mem = self.retrieve(obj=obj, history_id=history_id, selector=selector)
00241         return mem.data.object.modified() == obj.modified()
00242 

Here is the call graph for this function:

Definition at line 69 of file DummyTools.py.

00069 
00070     def log(self, msg):
00071         alog.append(msg)

Here is the caller graph for this function:

def CMFEditions.tests.DummyTools.DummyArchivist.prepare (   self,
  obj,
  app_metadata = None,
  sys_metadata = {} 
)

Definition at line 79 of file DummyTools.py.

00079 
00080     def prepare(self, obj, app_metadata=None, sys_metadata={}):
00081         obj, history_id = dereference(obj)
00082         if history_id is None:
00083             # object isn't under version control yet
00084             # An working copy beeing under version control needs to have
00085             # a history_id, version_id (starts with 0) and a location_id
00086             # (the current implementation isn't able yet to handle multiple
00087             # locations. Nevertheless lets set the location id to a well
00088             # known default value)
00089             portal_hidhandler = getToolByName(obj, 'portal_historyidhandler')
00090             history_id = portal_hidhandler.register(obj)
00091             version_id = obj.version_id = 0
00092             obj.location_id = 0
00093             is_registered = False
00094         else:
00095             version_id = len(self.queryHistory(obj))
00096             is_registered = True
00097 
00098         base_obj = aq_base(obj)
00099         doc1_inside = getattr(base_obj, 'doc1_inside', None)
00100         doc2_inside = getattr(base_obj, 'doc2_inside', None)
00101         doc3_outside = getattr(base_obj, 'doc3_outside', None)
00102 
00103         # simulate clone modifiers
00104         icrefs = []
00105         ocrefs = []
00106         clone = deepCopy(base_obj)
00107         if doc1_inside is not None:
00108             icrefs.append(AttributeAdapter(clone, 'doc1_inside'))
00109         if doc2_inside is not None:
00110             icrefs.append(AttributeAdapter(clone, 'doc2_inside'))
00111         if doc3_outside is not None:
00112             ocrefs.append(AttributeAdapter(clone, 'doc3_outside'))
00113         crefs = icrefs + ocrefs
00114 
00115         # simulate before save modifier
00116         iorefs = []
00117         oorefs = []
00118         if doc1_inside is not None:
00119             iorefs.append(getattr(obj, 'doc1_inside'))
00120         if doc2_inside is not None:
00121             iorefs.append(getattr(obj, 'doc2_inside'))
00122         if doc3_outside is not None:
00123             oorefs.append(getattr(obj, 'doc3_outside'))
00124         orefs = iorefs + oorefs
00125         for cref in crefs:
00126             cref.setAttribute(VersionAwareReference())
00127 
00128         # log
00129         if sys_metadata['originator'] is None:
00130             self.log("")
00131         if orefs:
00132             self.log("%sprepare %s: hid=%s, refs=(%s)"
00133                         % (self.alog_indent,
00134                            obj.getId(),
00135                            history_id,
00136                            ', '.join([ref.getId() for ref in orefs])))
00137         else:
00138             self.log("%sprepare %s: hid=%s"
00139                         % (self.alog_indent, obj.getId(), history_id))
00140         self.alog_indent += '  '
00141 
00142         # prepare object structure
00143         original_info = ObjectData(obj, iorefs, oorefs)
00144         clone_info = ObjectData(clone, icrefs, ocrefs)
00145 
00146         approxSize = None
00147 
00148         return PreparedObject(history_id, original_info, clone_info, (),
00149                               app_metadata, sys_metadata, is_registered, approxSize)

Here is the call graph for this function:

def CMFEditions.tests.DummyTools.DummyArchivist.queryHistory (   self,
  obj = None,
  history_id = None,
  preserve = (),
  default = [] 
)

Definition at line 228 of file DummyTools.py.

00228 
00229                      preserve=(), default=[]):
00230         try:
00231             history = self.getHistory(obj=obj, history_id=history_id, preserve=preserve)
00232         except KeyError:
00233             return default
00234         if history:
00235             return history
00236         return default

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFEditions.tests.DummyTools.DummyArchivist.register (   self,
  prepared_obj 
)

Definition at line 150 of file DummyTools.py.

00150 
00151     def register(self, prepared_obj):
00152         # log
00153         self.log("%sregister %s: hid=%s, is_registered=%s"
00154                     % (self.alog_indent,
00155                        prepared_obj.original.object.getId(),
00156                        prepared_obj.history_id,
00157                        prepared_obj.is_registered))
00158 
00159         if not prepared_obj.is_registered:
00160             # new empty history
00161             self._archive[prepared_obj.history_id] = []
00162             self.save(prepared_obj)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 75 of file DummyTools.py.

00075 
00076     def reset_log(self):
00077         global alog
00078         alog = []

def CMFEditions.tests.DummyTools.DummyArchivist.retrieve (   self,
  obj = None,
  history_id = None,
  selector = None,
  preserve = (),
  countPurged = True 
)

Definition at line 203 of file DummyTools.py.

00203 
00204                  countPurged=True):
00205         obj, history_id = dereference(obj, history_id, self)
00206         if selector is None:
00207             selector = len(self._archive[history_id]) - 1  #HEAD
00208 
00209         self.log("%sretrieve %s: hid=%s, selector=%s"
00210                     % (self.alog_indent, obj.getId(), history_id, selector))
00211 
00212         data = self._archive[history_id][selector]
00213         attr_handling_references = ['_objects']
00214         attr_handling_references.extend(data['clone'].object.objectIds())
00215         attr_handling_references.extend(obj.objectIds())
00216         vdata = VersionData(data['clone'],
00217                     [],
00218                     attr_handling_references,
00219                     data['referenced_data'],
00220                     data['metadata'])
00221 
00222         return deepCopy(vdata)

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFEditions.tests.DummyTools.DummyArchivist.save (   self,
  prepared_obj,
  autoregister = False 
)

Definition at line 163 of file DummyTools.py.

00163 
00164     def save(self, prepared_obj, autoregister=False):
00165         if not prepared_obj.is_registered:
00166             if not autoregister:
00167                 raise ArchivistError("not registered: %s " % prepared_obj.original.object)
00168             self._archive[prepared_obj.history_id] = []
00169 
00170         # log
00171         self.alog_indent = self.alog_indent[0:-2]
00172 
00173         irefs = [ref.getAttribute() for ref in prepared_obj.clone.inside_refs]
00174         orefs = [ref.getAttribute() for ref in prepared_obj.clone.outside_refs]
00175         irefs_prep = ['{hid:%s, vid:%s}' % (r.history_id, r.version_id)
00176                       for r in irefs]
00177         orefs_prep = ['{hid:%s, vid:%s}' % (r.history_id, r.version_id)
00178                       for r in orefs]
00179         irefs = ', '.join(irefs_prep)
00180         orefs = ', '.join(orefs_prep)
00181         if irefs:
00182             irefs = "irefs=(%s), " % irefs
00183         if orefs:
00184             orefs = "orefs=(%s), " % orefs
00185         refs = irefs + orefs
00186         self.log("%ssave    %s: hid=%s, %sisreg=%s, auto=%s"
00187                     % (self.alog_indent,
00188                        prepared_obj.original.object.getId(),
00189                        prepared_obj.history_id,
00190                        refs,
00191                        prepared_obj.is_registered,
00192                        autoregister))
00193 
00194         # save in the format the data needs to be retrieved
00195         svdata = {
00196             'clone': prepared_obj.clone,
00197             'referenced_data': prepared_obj.referenced_data,
00198             'metadata': prepared_obj.metadata,
00199         }
00200         # storage simulation
00201         self._archive[prepared_obj.history_id].append(svdata)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 64 of file DummyTools.py.

Definition at line 65 of file DummyTools.py.

Definition at line 67 of file DummyTools.py.

string CMFEditions.tests.DummyTools.DummyArchivist.id = 'portal_archivist' [static]

Definition at line 58 of file DummyTools.py.


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