1 # -*- encoding: utf-8 -*-
2 __author__="Ćukasz Rekucki"
3 __date__ ="$2009-09-18 10:49:24$"
5 __doc__ = """Main module for the Repository Abstraction Layer"""
9 def __init__(self, create=False):
10 """Open an existing library, or create a new one. By default, fails if
11 the library doesn't exist."""
14 def main_cabinet(self):
15 """Return the "main" cabinet of the library."""
19 """List all cabinets in the library."""
22 def cabinet(self, document, user, create=False):
23 """Open a cabinet belonging to the _user_ for a given _document_.
24 If the _document_ is actually a sub-document, it's parent's cabinet is
27 If the cabinet doesn't exists and create is False (the default), a
28 CabinetNotFound exception is raised.
30 If create is True, a new cabinet is created if it doesn't exist yet."""
34 def document(self, docid, user, part=None, shelve=None):
38 class Cabinet(object):
40 def __init__(self, library, name=None, doc=None, user=None):
41 self._library = library
45 self._user = self._document = None
49 self._name = user + ':' + doc
52 raise ValueError("You must provide either name or doc and user.")
54 print "new cab:", self._name, self._user, self._document
61 return "Cabinet(%s)" % self._name
64 """Lists all parts in this cabinet."""
67 def retrieve(self, part='xml', shelve=None):
68 """Retrieve a document from a given shelve in the cabinet. If no
69 part is given, the main document is retrieved. If no shelve is given,
70 the top-most shelve is used.
72 If parts is a list, all the given parts are retrieved atomicly. Use None
73 as the name for the main document"""
76 def create(self, name, initial_data=''):
77 """Create a new part in the cabinet with the given name."""
81 def maindoc_name(self):
92 def shelf(self, selector=None):
95 class Document(object):
96 def __init__(self, cabinet, name):
97 self._cabinet = cabinet
103 def write(self, data):
112 return self._cabinet.library
119 return self._cabinet.shelf()
123 raise NotImplemented()
127 raise NotImplemented()
129 def parentof(self, other):
130 return self.shelf().parentof(other.shelf())
132 def ancestorof(self, other):
133 return self.shelf().ancestorof(other.shelf())
138 def __init__(self, lib):
142 def parentof(self, other):
145 def ancestorof(self, other):
152 class LibraryException(Exception):
154 def __init__(self, msg, cause=None):
155 Exception.__init__(self, msg)
158 class CabinetNotFound(LibraryException):
159 def __init__(self, cabname):
160 LibraryException.__init__(self, "Cabinet '%s' not found." % cabname)
164 # import backends to local namespace
165 from backend_mercurial import MercurialLibrary