1 # -*- encoding: utf-8 -*-
2 __author__="Łukasz Rekucki"
3 __date__ ="$2009-09-18 10:49:24$"
4 __doc__ = """Main module for the Repository Abstraction Layer"""
8 def __init__(self, create=False):
9 """Open an existing library, or create a new one. By default, fails if
10 the library doesn't exist."""
14 """List all documents in the library."""
17 def document_for_rev(self, rev):
18 """Retrieve a document in the specified revision."""
21 def document(self, docid, user=None, rev='latest'):
22 """Retrieve a document from a library."""
25 def get_revision(self, revid):
26 """Retrieve a handle to a specified revision."""
29 def document_create(self, docid):
30 """Create a new document. The document will have it's own branch."""
33 class Document(object):
34 """A class representing a document package boundled with a revision."""
36 def __init__(self, library, revision):
37 """_library_ should be an instance of a Library."""
38 self._library = library
39 if isinstance(revision, Revision):
40 self._revision = revision
42 self._revision = library.get_revision(revision)
46 """Make a user copy of the document. This is persistant."""
50 """Informs the library, that the user no longer needs this document.
51 Should be called on the user version of document. If not, it doesn nothing."""
53 def data(self, entry):
54 """Returns the specified entry as a unicode data."""
67 return self._revision.document_name
71 return self._revision.user_name
73 def parentof(self, other):
74 return self._revision.parentof(other._revision)
76 def ancestorof(self, other):
77 return self._revision.ancestorof(other._revision)
80 class Revision(object):
82 def __init__(self, lib):
85 def parentof(self, other):
88 def ancestorof(self, other):
92 def document_name(self):
103 class LibraryException(Exception):
104 def __init__(self, msg, cause=None):
105 Exception.__init__(self, msg)
108 class UpdateException(LibraryException):
111 class RevisionNotFound(LibraryException):
112 def __init__(self, rev):
113 LibraryException.__init__(self, "Revision %r not found." % rev)
115 class RevisionMismatch(LibraryException):
116 def __init__(self, fdi, rev):
117 LibraryException.__init__(self, "No revision %r for document %r." % (rev, fdi))
119 class EntryNotFound(LibraryException):
120 def __init__(self, rev, entry, guesses=[]):
121 LibraryException.__init__(self, \
122 u"Entry '%s' at revision %r not found. %s" % (entry, rev, \
123 (u"Posible values:\n" + u',\n'.join(guesses)) if len(guesses) else u'') )
125 class DocumentAlreadyExists(LibraryException):
128 # import backends to local namespace
130 def open_library(path, proto, *args, **kwargs):
132 import wlrepo.mercurial_backend
133 return wlrepo.mercurial_backend.MercurialLibrary(path, *args, **kwargs)
135 raise NotImplemented()