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
41 self._user = self._document = None
45 self._name = user + ':' + doc
48 raise ValueError("You must provide either name or doc and user.")
50 print "new cab:", self._name, self._user, self._document
57 return "Cabinet(%s)" % self._name
60 """Lists all documents and sub-documents in this cabinet."""
63 def retrieve(self, parts=None, shelve=None):
64 """Retrieve a document from a given shelve in the cabinet. If no
65 part is given, the main document is retrieved. If no shelve is given,
66 the top-most shelve is used.
68 If parts is a list, all the given parts are retrieved atomicly. Use None
69 as the name for the main document"""
72 def create(self, name, initial_data=''):
73 """Create a new sub-document in the cabinet with the given name."""
77 def maindoc_name(self):
88 def shelf(self, selector=None):
91 class Document(object):
92 def __init__(self, cabinet, name):
93 self._cabinet = cabinet
99 def write(self, data):
108 return self._cabinet.library
115 return self._cabinet.shelf()
119 raise NotImplemented()
123 raise NotImplemented()
128 def __init__(self, lib):
135 class LibraryException(Exception):
137 def __init__(self, msg, cause=None):
138 Exception.__init__(self, msg)
141 class CabinetNotFound(LibraryException):
142 def __init__(self, cabname):
143 LibraryException.__init__(self, "Cabinet '%s' not found." % cabname)
147 # import backends to local namespace
148 from backend_mercurial import MercurialLibrary