def __init__(self, archive, sessionname, readonly=False, fsSurrogate=None):
     "construct a mapping corresponding to self session name"
     if fsSurrogate is None:
         fsSurrogate = fileSystemSurrogate.chooseSurrogate()
     self.fsSurrogate = fsSurrogate
     self.archive = archive
     self.sessionname = sessionname
     self.readonly = readonly
     # building the shadow stack from the bottom up:
     # get the base/active mapping
     result = archive.baseMapping()
     # shadow with the Transient Active if present
     transient = archive.transientMapping()
     if transient is not None:
         if self.verbose:
             print "transient found", transient.lastIndex(), transient.filename
         result = shadowTree(transient, result)
     else:
         if self.verbose:
             print "no transient found"
     # shadow with the union of all recent/active
     #  and any recent/waiting for self transaction if present.
     recent = archive.recentMapping(sessionname)
     if recent is not None:
         if self.verbose:
             print "recent found", recent.filename
         result = shadowTree(recent, result)
     # shadow with undecided/active for self transaction (create it unless readonly)
     self.undecided = undecided = archive.undecidedTree(sessionname, readonly)
     if undecided is not None:
         if self.verbose:
             print "undecided found", undecided.filename
         result = shadowTree(undecided, result)
     self.tree = result
 def __init__(self, path, create=False, check=True, fsSurrogate=None):
     "Open or create archive."
     #pr "opening archive", (path, create, check)
     if fsSurrogate is None:
         fsSurrogate = fileSystemSurrogate.chooseSurrogate()
     self.fsSurrogate = fsSurrogate
     self.path = path
     if not fsSurrogate.isdir(path):
         if create:
             fsSurrogate.mkdir(path)
         else:
             raise ValueError, "no such archive directory "+repr(path)
     # check or create file system layout
     if create:
         self.tryDestroy()
         for (level, collections) in FSLAYOUT.items():
             lpath = fsSurrogate.join(path, level)
             try:
                 fsSurrogate.mkdir(lpath)
             except OSError:
                 pass
             for collection in collections:
                 cpath = fsSurrogate.join(lpath, collection)
                 ##pr "making", cpath
                 try:
                     fsSurrogate.mkdir(cpath)
                     ##pr "made"
                 except OSError:
                     pass
         # insert empty active base mapping
         timestamp = self.newTimeStamp()
         # "NEW TIMESTAMP", timestamp
         bname = self.baseName(timestamp)
         kt = fTree.makeEmptyTree(bname)
     if check:
         for (level, collections) in FSLAYOUT.items():
             lpath = fsSurrogate.join(path, level)
             if not fsSurrogate.exists(lpath):
                 raise ValueError, "no such archive/level directory "+repr(lpath)
             for collection in collections:
                 cpath = fsSurrogate.join(lpath, collection)
                 if not fsSurrogate.exists(cpath):
                     raise ValueError, "no such archive/level/collection dir"+(
                         repr(cpath))
         # check for active transient and base mappings
         currentBaseName = self.currentBaseName()
         if currentBaseName is None:
             raise ValueError, "can't find current base mapping file on init"
         #currentTransientName = self.currentTransientName()
     # create these when needed
     self.Base = None
     self.Transient = None
     self.TransientIsEmpty = False
     self.Recent = None
     self.RecentIsEmpty = False