Redmine locale fix. Some RAL tweaks. Added line numbers to code-mirror.
[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     def document(self, docid, user, part=None, shelve=None):
35         pass
36
37
38 class Cabinet(object):
39
40     def __init__(self, library, name=None, doc=None, user=None):
41         self._library = library
42         if name:
43             self._name = name
44             self._maindoc = ''
45             self._user = self._document = None
46         elif doc and user:
47             self._user = user
48             self._document = doc
49             self._name = user + ':' + doc
50             self._maindoc = doc
51         else:
52             raise ValueError("You must provide either name or doc and user.")
53
54         print "new cab:", self._name, self._user, self._document
55
56     @property
57     def username(self):
58         return self._user
59
60     def __str__(self):
61         return "Cabinet(%s)" % self._name
62
63     def parts(self):
64         """Lists all parts in this cabinet."""
65         pass
66     
67     def retrieve(self, part='xml', shelve=None):
68         """Retrieve a document from a given shelve in the cabinet. If no
69         part is given, the main document is retrieved. If no shelve is given,
70         the top-most shelve is used.
71
72         If parts is a list, all the given parts are retrieved atomicly. Use None
73         as the name for the main document"""
74         pass
75
76     def create(self, name, initial_data=''):
77         """Create a new part in the cabinet with the given name."""
78         pass
79
80     @property
81     def maindoc_name(self):
82         return self._maindoc
83
84     @property
85     def library(self):
86         return self._library
87
88     @property
89     def name(self):
90         return self._name
91
92     def shelf(self, selector=None):
93         pass
94
95 class Document(object):
96     def __init__(self, cabinet, name):
97         self._cabinet = cabinet
98         self._name = name
99
100     def read(self):
101         pass
102
103     def write(self, data):
104         pass
105
106     @property
107     def cabinet(self):
108         return self._cabinet
109
110     @property
111     def library(self):
112         return self._cabinet.library
113
114     @property
115     def name(self):
116         return self._name
117
118     def shelf(self):
119         return self._cabinet.shelf()
120
121     @property
122     def size(self):
123         raise NotImplemented()
124
125     @property
126     def parts(self):
127         raise NotImplemented()
128     
129     def parentof(self, other):
130         return self.shelf().parentof(other.shelf())
131
132     def ancestorof(self, other):
133         return self.shelf().ancestorof(other.shelf())
134
135
136 class Shelf(object):
137
138     def __init__(self, lib):
139         self._library = lib
140
141
142     def parentof(self, other):
143         return False
144
145     def ancestorof(self, other):
146         return False
147     
148 #
149 # Exception classes
150 #
151
152 class LibraryException(Exception):
153     
154     def __init__(self, msg, cause=None):
155         Exception.__init__(self, msg)
156         self.cause = cause
157
158 class CabinetNotFound(LibraryException):
159     def __init__(self, cabname):
160         LibraryException.__init__(self, "Cabinet '%s' not found." % cabname)
161     pass
162
163
164 # import backends to local namespace
165 from backend_mercurial import MercurialLibrary