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 class Cabinet(object):
36 def __init__(self, library, name=None, doc=None, user=None):
37 self._library = library
42 self._name = user + ':' + doc
45 raise ValueError("You must provide either name or doc and user.")
49 return "Cabinet(%s)" % self._name
52 """Lists all documents and sub-documents in this cabinet."""
55 def retrieve(self, parts=None, shelve=None):
56 """Retrieve a document from a given shelve in the cabinet. If no
57 part is given, the main document is retrieved. If no shelve is given,
58 the top-most shelve is used.
60 If parts is a list, all the given parts are retrieved atomicly. Use None
61 as the name for the main document"""
64 def create(self, name, initial_data=''):
65 """Create a new sub-document in the cabinet with the given name."""
68 def maindoc_name(self):
79 def shelf(self, selector=None):
82 class Document(object):
83 def __init__(self, cabinet, name):
84 self._cabinet = cabinet
90 def write(self, data):
99 return self._cabinet.library
106 return self._cabinet.shelf()
110 raise NotImplemented()
114 raise NotImplemented()
119 def __init__(self, cabinet):
120 self._cabinet = cabinet
127 class LibraryException(Exception):
129 def __init__(self, msg, cause=None):
130 Exception.__init__(self, msg)
133 class CabinetNotFound(LibraryException):
134 def __init__(self, cabname):
135 LibraryException.__init__(self, "Cabinet '%s' not found." % cabname)
139 # import backends to local namespace
140 from backend_mercurial import MercurialLibrary