5c27dc9728e3f3f3f6224565a06c25f90b4bc714
[redakcja.git] / lib / wlrepo / __init__.py
1 # -*- encoding: utf-8 -*-
2 __author__="Ɓukasz Rekucki"
3 __date__ ="$2009-09-18 10:49:24$"
4
5 __doc__ = """Main module for the Repository Abstraction Layer"""
6
7 class Library(object):
8
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."""
12         self.create = create     
13         
14     def main_cabinet(self):
15         """Return the "main" cabinet of the library."""
16         pass
17
18     def cabinets(self):
19         """List all cabinets in the library."""
20         pass
21
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
25         opened istead.
26         
27         If the cabinet doesn't exists and create is False (the default), a 
28         CabinetNotFound exception is raised.
29         
30         If create is True, a new cabinet is created if it doesn't exist yet."""
31         pass
32
33
34 class Cabinet(object):
35
36     def __init__(self, library, name=None, doc=None, user=None):
37         self._library = library
38         if name:
39             self._name = name
40             self._maindoc = ''
41         elif doc and user:
42             self._name = user + ':' + doc
43             self._maindoc = doc
44         else:
45             raise ValueError("You must provide either name or doc and user.")
46
47     def documents(self):
48         """Lists all documents and sub-documents in this cabinet."""
49         pass
50     
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.
55
56         If parts is a list, all the given parts are retrieved atomicly. Use None
57         as the name for the main document"""
58         pass
59
60     def create(self, name):
61         """Create a new sub-document in the cabinet with the given name."""
62         pass
63     
64     def maindoc_name(self):
65         return self._maindoc
66
67
68     @property
69     def library(self):
70         return self._library
71
72     @property
73     def name(self):
74         return self._name
75
76 class Document(object):
77     def __init__(self, cabinet, name):
78         self._cabinet = cabinet
79         self._name = name
80
81     def read(self):
82         pass
83
84     def write(self, data):
85         pass
86
87     @property
88     def cabinet(self):
89         return self._cabinet
90
91     @property
92     def library(self):
93         return self._cabinet.library
94
95
96 #
97 # Exception classes
98 #
99
100 class LibraryException(Exception):
101     
102     def __init__(self, msg, cause=None):
103         Exception.__init__(self, msg)
104         self.cause = cause
105
106 class CabinetNotFound(LibraryException):
107     pass
108
109
110 # import backends to local namespace
111 from backend_mercurial import MercurialLibrary