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):
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 file-like object."""
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 RevisionNotFound(LibraryException):
109 def __init__(self, rev):
110 LibraryException.__init__(self, "Revision %r not found." % rev)
112 class EntryNotFound(LibraryException):
113 def __init__(self, rev, entry, guesses=[]):
114 LibraryException.__init__(self, \
115 u"Entry '%s' at revision %r not found. %s" % (entry, rev, \
116 (u"Posible values:\n" + u',\n'.join(guesses)) if len(guesses) else u'') )
118 class DocumentAlreadyExists(LibraryException):
121 # import backends to local namespace
123 def open_library(path, proto, *args, **kwargs):
125 import wlrepo.mercurial_backend
126 return wlrepo.mercurial_backend.MercurialLibrary(path, *args, **kwargs)
128 raise NotImplemented()