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.")
48 """Lists all documents and sub-documents in this cabinet."""
51 def retrieve(self, parts=None, shelve=None):
52 """Retrieve a document from a given shelve in the cabinet. If no
53 part is given, the main document is retrieved. If no shelve is given,
54 the top-most shelve is used.
56 If parts is a list, all the given parts are retrieved atomicly. Use None
57 as the name for the main document"""
60 def create(self, name):
61 """Create a new sub-document in the cabinet with the given name."""
64 def maindoc_name(self):
76 class Document(object):
77 def __init__(self, cabinet, name):
78 self._cabinet = cabinet
84 def write(self, data):
93 return self._cabinet.library
100 class LibraryException(Exception):
102 def __init__(self, msg, cause=None):
103 Exception.__init__(self, msg)
106 class CabinetNotFound(LibraryException):
110 # import backends to local namespace
111 from backend_mercurial import MercurialLibrary