Interaktywne błędy, gdy nie udało się wczytać HTML'a.
[redakcja.git] / lib / wlrepo / mercurial_backend / __init__.py
1 # -*- encoding: utf-8 -*-
2
3 __author__= "Łukasz Rekucki"
4 __date__ = "$2009-09-25 09:20:22$"
5 __doc__ = "Module documentation."
6
7 import wlrepo
8 from mercurial.node import nullid
9
10 from mercurial import encoding
11 encoding.encoding = 'utf-8'
12
13 class MercurialRevision(wlrepo.Revision):
14
15     def __init__(self, lib, changectx):
16         super(MercurialRevision, self).__init__(lib)
17         self._changectx = changectx
18         
19         branchname = self._changectx.branch()
20         if branchname.startswith("$doc:"):
21             self._docname = branchname[5:]
22             self._username = None
23         elif branchname.startswith("$user:"):
24             idx = branchname.find("$doc:")
25             if(idx < 0):
26                 raise ValueError("Revision %s is not a valid document revision." % changectx.hex());
27             self._username = branchname[6:idx]
28             self._docname = branchname[idx+5:]
29         else:
30             raise ValueError("Revision %s is not a valid document revision." % changectx.hex());
31         
32     @property
33     def document_name(self):
34         return self._docname and self._docname.decode('utf-8')
35
36     @property
37     def user_name(self):
38         return self._username and self._username.decode('utf-8')
39
40     def hgrev(self):
41         return self._changectx.node()
42         
43     def hgcontext(self):
44         return self._changectx
45
46     def hgbranch(self):
47         return self._changectx.branch()
48
49     @property
50     def timestamp(self):
51         return self._changectx.date()[0]
52
53     def __unicode__(self):
54         return u"%s" % self._changectx.hex()
55
56     def __str__(self):
57         return self.__unicode__().encode('utf-8')
58
59     def __repr__(self):
60         return "%s" % self._changectx.hex()
61
62     def ancestorof(self, other):
63         nodes = list(other._changectx._parents)
64         while nodes[0].node() != nullid:
65             v = nodes.pop(0)
66             if v == self._changectx:
67                 return True
68             nodes.extend( v._parents )
69         return False
70
71     def parentof(self, other):
72         return self._changectx in other._changectx._parents
73
74     def has_common_ancestor(self, other):
75         a = self._changectx.ancestor(other._changectx)       
76         return (a.branch() == self._changectx.branch())
77
78     def has_children(self):
79         return bool(self._library._hgrepo.changelog.children(self.hgrev()))
80
81     def merge_with(self, other, user, message):
82         message = self._library._sanitize_string(message)
83         lock = self._library.lock(True)
84         try:
85             self._library._checkout(self._changectx.node())
86             status = self._library._merge(other._changectx.node())
87             if status.isclean():
88                 self._library._commit(user=user, message=message)
89                 return (True, True)
90             else:
91                 return (False, False)
92         finally:
93             lock.release()
94
95     def __eq__(self, other):
96         return self._changectx.node() == other._changectx.node()
97
98
99 from wlrepo.mercurial_backend.library import MercurialLibrary
100
101