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_revision(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)
77 return self._library.document_for_revision(self._revision.parent())
79 def has_parent_from(self, other):
80 return self._revision.has_parent_from(other._revision)
82 def ancestorof(self, other):
83 return self._revision.ancestorof(other._revision)
86 class Revision(object):
88 def __init__(self, lib):
91 def parentof(self, other):
94 def ancestorof(self, other):
98 def document_name(self):
109 class LibraryException(Exception):
110 def __init__(self, msg, cause=None):
111 Exception.__init__(self, msg)
114 class UpdateException(LibraryException):
117 class RevisionNotFound(LibraryException):
118 def __init__(self, rev):
119 LibraryException.__init__(self, "Revision %r not found." % rev)
121 class RevisionMismatch(LibraryException):
122 def __init__(self, fdi, rev):
123 LibraryException.__init__(self, "No revision %r for document %r." % (rev, fdi))
125 class EntryNotFound(LibraryException):
126 def __init__(self, rev, entry, guesses=[]):
127 LibraryException.__init__(self, \
128 u"Entry '%s' at revision %r not found. %s" % (entry, rev, \
129 (u"Posible values:\n" + u',\n'.join(guesses)) if len(guesses) else u'') )
131 class DocumentAlreadyExists(LibraryException):
134 # import backends to local namespace
136 def open_library(path, proto, *args, **kwargs):
138 import wlrepo.mercurial_backend.library
139 return wlrepo.mercurial_backend.library.MercurialLibrary(path, *args, **kwargs)
141 raise NotImplemented()