/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
7 by mbp at sourcefrog
depend only on regular ElementTree installation
21
22
try:
23
    from cElementTree import Element, ElementTree, SubElement
24
except ImportError:
25
    from elementtree import Element, ElementTree, SubElement
26
1 by mbp at sourcefrog
import from baz patch-364
27
28
class Revision(XMLMixin):
29
    """Single revision on a branch.
30
31
    Revisions may know their revision_hash, but only once they've been
32
    written out.  This is not stored because you cannot write the hash
33
    into the file it describes.
34
35
    :todo: Perhaps make predecessor be a child element, not an attribute?
36
    """
37
    def __init__(self, **args):
38
        self.inventory_id = None
39
        self.revision_id = None
40
        self.timestamp = None
41
        self.message = None
42
        self.__dict__.update(args)
43
44
45
    def __repr__(self):
46
        if self.revision_id:
47
            return "<Revision id %s>" % self.revision_id
48
49
        
50
    def to_element(self):
51
        root = Element('changeset',
52
                       committer = self.committer,
53
                       timestamp = '%f' % self.timestamp,
54
                       revision_id = self.revision_id,
55
                       inventory_id = self.inventory_id)
56
        if self.precursor:
57
            root.set('precursor', self.precursor)
58
        root.text = '\n'
59
        
60
        msg = SubElement(root, 'message')
61
        msg.text = self.message
62
        msg.tail = '\n'
63
64
        return root
65
66
    def from_element(cls, root):
67
        cs = cls(committer = root.get('committer'),
68
                 timestamp = float(root.get('timestamp')),
69
                 precursor = root.get('precursor'),
70
                 revision_id = root.get('revision_id'),
71
                 inventory_id = root.get('inventory_id'))
72
73
        cs.message = root.findtext('message') # text of <message>
74
        return cs
75
76
    from_element = classmethod(from_element)
77