~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/xml4.py

  • Committer: Martin Pool
  • Date: 2005-09-30 05:56:05 UTC
  • mto: (1185.14.2)
  • mto: This revision was merged to the branch mainline in revision 1396.
  • Revision ID: mbp@sourcefrog.net-20050930055605-a2c534529b392a7d
- fix upgrade for transport changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
2
 
#
 
1
#! /usr/bin/env python
 
2
 
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
#
 
7
 
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
#
 
12
 
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
from bzrlib.xml_serializer import ElementTree, SubElement, Element, Serializer
 
17
 
 
18
from bzrlib.xml import ElementTree, SubElement, Element, Serializer
18
19
from bzrlib.inventory import ROOT_ID, Inventory, InventoryEntry
19
 
import bzrlib.inventory as inventory
20
20
from bzrlib.revision import Revision        
21
21
from bzrlib.errors import BzrError
22
22
 
23
23
 
 
24
 
 
25
 
 
26
 
 
27
 
24
28
class _Serializer_v4(Serializer):
25
29
    """Version 0.0.4 serializer
26
30
 
27
 
    You should use the serializer_v4 singleton."""
 
31
    You should use the serialzer_v4 singleton."""
28
32
    
29
33
    __slots__ = []
30
34
    
31
35
    def _pack_inventory(self, inv):
32
36
        """Convert to XML Element"""
33
 
        # v4 serialization is not used any more.
34
 
        raise NotImplementedError(self._pack_inventory)
35
37
        e = Element('inventory')
36
38
        e.text = '\n'
37
39
        if inv.root.file_id not in (None, ROOT_ID):
48
50
        e.set('file_id', ie.file_id)
49
51
        e.set('kind', ie.kind)
50
52
 
51
 
        if ie.text_size is not None:
 
53
        if ie.text_size != None:
52
54
            e.set('text_size', '%d' % ie.text_size)
53
55
 
54
 
        for f in ['text_id', 'text_sha1', 'symlink_target']:
 
56
        for f in ['text_id', 'text_sha1']:
55
57
            v = getattr(ie, f)
56
 
            if v is not None:
 
58
            if v != None:
57
59
                e.set(f, v)
58
60
 
59
61
        # to be conservative, we don't externalize the root pointers
89
91
        ## nodes in the root directory, but it's cleaner to use one
90
92
        ## internally.
91
93
        parent_id = elt.get('parent_id')
92
 
        if parent_id is None:
 
94
        if parent_id == None:
93
95
            parent_id = ROOT_ID
94
96
 
95
 
        kind = elt.get('kind')
96
 
        if kind == 'directory':
97
 
            ie = inventory.InventoryDirectory(elt.get('file_id'),
98
 
                                              elt.get('name'),
99
 
                                              parent_id)
100
 
        elif kind == 'file':
101
 
            ie = inventory.InventoryFile(elt.get('file_id'),
102
 
                                         elt.get('name'),
103
 
                                         parent_id)
104
 
            ie.text_id = elt.get('text_id')
105
 
            ie.text_sha1 = elt.get('text_sha1')
106
 
            v = elt.get('text_size')
107
 
            ie.text_size = v and int(v)
108
 
        elif kind == 'symlink':
109
 
            ie = inventory.InventoryLink(elt.get('file_id'),
110
 
                                         elt.get('name'),
111
 
                                         parent_id)
112
 
            ie.symlink_target = elt.get('symlink_target')
113
 
        else:
114
 
            raise BzrError("unknown kind %r" % kind)
115
 
 
116
 
        ## mutter("read inventoryentry: %r", elt.attrib)
 
97
        ie = InventoryEntry(elt.get('file_id'),
 
98
                            elt.get('name'),
 
99
                            elt.get('kind'),
 
100
                            parent_id)
 
101
        ie.text_id = elt.get('text_id')
 
102
        ie.text_sha1 = elt.get('text_sha1')
 
103
 
 
104
        ## mutter("read inventoryentry: %r" % (elt.attrib))
 
105
 
 
106
        v = elt.get('text_size')
 
107
        ie.text_size = v and int(v)
117
108
 
118
109
        return ie
119
110