2
# -*- coding: UTF-8 -*-
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.
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.
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
21
from xml import XMLMixin
24
from cElementTree import Element, ElementTree, SubElement
26
from elementtree import Element, ElementTree, SubElement
29
class Revision(XMLMixin):
30
"""Single revision on a branch.
32
Revisions may know their revision_hash, but only once they've been
33
written out. This is not stored because you cannot write the hash
34
into the file it describes.
36
:todo: Perhaps make predecessor be a child element, not an attribute?
38
def __init__(self, **args):
39
self.inventory_id = None
40
self.revision_id = None
44
self.__dict__.update(args)
49
return "<Revision id %s>" % self.revision_id
53
root = Element('changeset',
54
committer = self.committer,
55
timestamp = '%.9f' % self.timestamp,
56
revision_id = self.revision_id,
57
inventory_id = self.inventory_id,
58
timezone = str(self.timezone))
60
root.set('precursor', self.precursor)
63
msg = SubElement(root, 'message')
64
msg.text = self.message
69
def from_element(cls, root):
70
cs = cls(committer = root.get('committer'),
71
timestamp = float(root.get('timestamp')),
72
precursor = root.get('precursor'),
73
revision_id = root.get('revision_id'),
74
inventory_id = root.get('inventory_id'))
76
v = root.get('timezone')
77
cs.timezone = v and int(v)
79
cs.message = root.findtext('message') # text of <message>
82
from_element = classmethod(from_element)