Głupi git!
[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
48     def __str__(self):
49         return "Cabinet(%s)" % self._name
50
51     def documents(self):
52         """Lists all documents and sub-documents in this cabinet."""
53         pass
54     
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.
59
60         If parts is a list, all the given parts are retrieved atomicly. Use None
61         as the name for the main document"""
62         pass
63
64     def create(self, name, initial_data=''):
65         """Create a new sub-document in the cabinet with the given name."""
66         pass
67     
68     def maindoc_name(self):
69         return self._maindoc
70
71     @property
72     def library(self):
73         return self._library
74
75     @property
76     def name(self):
77         return self._name
78
79     def shelf(self, selector=None):
80         pass
81
82 class Document(object):
83     def __init__(self, cabinet, name):
84         self._cabinet = cabinet
85         self._name = name
86
87     def read(self):
88         pass
89
90     def write(self, data):
91         pass
92
93     @property
94     def cabinet(self):
95         return self._cabinet
96
97     @property
98     def library(self):
99         return self._cabinet.library
100
101     @property
102     def name(self):
103         return self._name
104
105     def shelf(self):
106         return self._cabinet.shelf()
107
108     @property
109     def size(self):
110         raise NotImplemented()
111
112     @property
113     def parts(self):
114         raise NotImplemented()
115
116
117 class Shelf(object):
118
119     def __init__(self, cabinet):
120         self._cabinet = cabinet
121         
122     
123 #
124 # Exception classes
125 #
126
127 class LibraryException(Exception):
128     
129     def __init__(self, msg, cause=None):
130         Exception.__init__(self, msg)
131         self.cause = cause
132
133 class CabinetNotFound(LibraryException):
134     def __init__(self, cabname):
135         LibraryException.__init__(self, "Cabinet '%s' not found." % cabname)
136     pass
137
138
139 # import backends to local namespace
140 from backend_mercurial import MercurialLibrary