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 has_parent_from(self, other):
77 return self._revision.has_parent_from(other._revision)
79 def ancestorof(self, other):
80 return self._revision.ancestorof(other._revision)
83 class Revision(object):
85 def __init__(self, lib):
88 def parentof(self, other):
91 def ancestorof(self, other):
95 def document_name(self):
106 class LibraryException(Exception):
107 def __init__(self, msg, cause=None):
108 Exception.__init__(self, msg)
111 class UpdateException(LibraryException):
114 class RevisionNotFound(LibraryException):
115 def __init__(self, rev):
116 LibraryException.__init__(self, "Revision %r not found." % rev)
118 class RevisionMismatch(LibraryException):
119 def __init__(self, fdi, rev):
120 LibraryException.__init__(self, "No revision %r for document %r." % (rev, fdi))
122 class EntryNotFound(LibraryException):
123 def __init__(self, rev, entry, guesses=[]):
124 LibraryException.__init__(self, \
125 u"Entry '%s' at revision %r not found. %s" % (entry, rev, \
126 (u"Posible values:\n" + u',\n'.join(guesses)) if len(guesses) else u'') )
128 class DocumentAlreadyExists(LibraryException):
131 # import backends to local namespace
133 def open_library(path, proto, *args, **kwargs):
135 import wlrepo.mercurial_backend.library
136 return wlrepo.mercurial_backend.library.MercurialLibrary(path, *args, **kwargs)
138 raise NotImplemented()