~bzr-pqm/bzr/bzr.dev

184 by mbp at sourcefrog
pychecker fixups
1
# (C) 2005 Canonical
1 by mbp at sourcefrog
import from baz patch-364
2
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
18
8 by mbp at sourcefrog
store committer's timezone in revision and show
19
1 by mbp at sourcefrog
import from baz patch-364
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:
27 by mbp at sourcefrog
- fix up use of ElementTree without cElementTree
25
    from elementtree.ElementTree import Element, ElementTree, SubElement
7 by mbp at sourcefrog
depend only on regular ElementTree installation
26
184 by mbp at sourcefrog
pychecker fixups
27
from errors import BzrError
28
1 by mbp at sourcefrog
import from baz patch-364
29
30
class Revision(XMLMixin):
31
    """Single revision on a branch.
32
33
    Revisions may know their revision_hash, but only once they've been
34
    written out.  This is not stored because you cannot write the hash
35
    into the file it describes.
36
254 by Martin Pool
- Doc cleanups from Magnus Therning
37
    TODO: Perhaps make predecessor be a child element, not an attribute?
1 by mbp at sourcefrog
import from baz patch-364
38
    """
39
    def __init__(self, **args):
40
        self.inventory_id = None
41
        self.revision_id = None
42
        self.timestamp = None
43
        self.message = None
8 by mbp at sourcefrog
store committer's timezone in revision and show
44
        self.timezone = None
184 by mbp at sourcefrog
pychecker fixups
45
        self.committer = None
46
        self.precursor = None
1 by mbp at sourcefrog
import from baz patch-364
47
        self.__dict__.update(args)
48
49
50
    def __repr__(self):
184 by mbp at sourcefrog
pychecker fixups
51
        return "<Revision id %s>" % self.revision_id
1 by mbp at sourcefrog
import from baz patch-364
52
53
        
54
    def to_element(self):
11 by mbp at sourcefrog
- change revision XML to <revision>
55
        root = Element('revision',
1 by mbp at sourcefrog
import from baz patch-364
56
                       committer = self.committer,
8 by mbp at sourcefrog
store committer's timezone in revision and show
57
                       timestamp = '%.9f' % self.timestamp,
1 by mbp at sourcefrog
import from baz patch-364
58
                       revision_id = self.revision_id,
8 by mbp at sourcefrog
store committer's timezone in revision and show
59
                       inventory_id = self.inventory_id,
60
                       timezone = str(self.timezone))
1 by mbp at sourcefrog
import from baz patch-364
61
        if self.precursor:
62
            root.set('precursor', self.precursor)
63
        root.text = '\n'
64
        
65
        msg = SubElement(root, 'message')
66
        msg.text = self.message
67
        msg.tail = '\n'
68
69
        return root
70
11 by mbp at sourcefrog
- change revision XML to <revision>
71
72
    def from_element(cls, elt):
73
        # <changeset> is deprecated...
74
        if elt.tag not in ('revision', 'changeset'):
184 by mbp at sourcefrog
pychecker fixups
75
            raise BzrError("unexpected tag in revision file: %r" % elt)
11 by mbp at sourcefrog
- change revision XML to <revision>
76
77
        cs = cls(committer = elt.get('committer'),
78
                 timestamp = float(elt.get('timestamp')),
79
                 precursor = elt.get('precursor'),
80
                 revision_id = elt.get('revision_id'),
81
                 inventory_id = elt.get('inventory_id'))
82
83
        v = elt.get('timezone')
8 by mbp at sourcefrog
store committer's timezone in revision and show
84
        cs.timezone = v and int(v)
85
11 by mbp at sourcefrog
- change revision XML to <revision>
86
        cs.message = elt.findtext('message') # text of <message>
1 by mbp at sourcefrog
import from baz patch-364
87
        return cs
88
89
    from_element = classmethod(from_element)
90