1
by mbp at sourcefrog
import from baz patch-364 |
1 |
#! /usr/bin/env python
|
2 |
# -*- coding: UTF-8 -*-
|
|
3 |
||
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
||
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
||
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17 |
||
18 |
||
19 |
||
20 |
from xml import XMLMixin |
|
21 |
from ElementTree import Element, ElementTree, SubElement |
|
22 |
||
23 |
class Revision(XMLMixin): |
|
24 |
"""Single revision on a branch.
|
|
25 |
||
26 |
Revisions may know their revision_hash, but only once they've been
|
|
27 |
written out. This is not stored because you cannot write the hash
|
|
28 |
into the file it describes.
|
|
29 |
||
30 |
:todo: Perhaps make predecessor be a child element, not an attribute?
|
|
31 |
"""
|
|
32 |
def __init__(self, **args): |
|
33 |
self.inventory_id = None |
|
34 |
self.revision_id = None |
|
35 |
self.timestamp = None |
|
36 |
self.message = None |
|
37 |
self.__dict__.update(args) |
|
38 |
||
39 |
||
40 |
def __repr__(self): |
|
41 |
if self.revision_id: |
|
42 |
return "<Revision id %s>" % self.revision_id |
|
43 |
||
44 |
||
45 |
def to_element(self): |
|
46 |
root = Element('changeset', |
|
47 |
committer = self.committer, |
|
48 |
timestamp = '%f' % self.timestamp, |
|
49 |
revision_id = self.revision_id, |
|
50 |
inventory_id = self.inventory_id) |
|
51 |
if self.precursor: |
|
52 |
root.set('precursor', self.precursor) |
|
53 |
root.text = '\n' |
|
54 |
||
55 |
msg = SubElement(root, 'message') |
|
56 |
msg.text = self.message |
|
57 |
msg.tail = '\n' |
|
58 |
||
59 |
return root |
|
60 |
||
61 |
def from_element(cls, root): |
|
62 |
cs = cls(committer = root.get('committer'), |
|
63 |
timestamp = float(root.get('timestamp')), |
|
64 |
precursor = root.get('precursor'), |
|
65 |
revision_id = root.get('revision_id'), |
|
66 |
inventory_id = root.get('inventory_id')) |
|
67 |
||
68 |
cs.message = root.findtext('message') # text of <message> |
|
69 |
return cs |
|
70 |
||
71 |
from_element = classmethod(from_element) |
|
72 |