~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/xml5.py

  • Committer: Martin Pool
  • Date: 2005-10-04 02:54:54 UTC
  • mfrom: (1399.1.12)
  • mto: (1185.13.3)
  • mto: This revision was merged to the branch mainline in revision 1400.
  • Revision ID: mbp@sourcefrog.net-20051004025454-a8da093aebf1fb24
[merge] refactoring from robert to use different Entry classes
for files, directories, etc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
from bzrlib.xml import ElementTree, SubElement, Element, Serializer
19
19
from bzrlib.inventory import ROOT_ID, Inventory, InventoryEntry
 
20
import bzrlib.inventory as inventory
20
21
from bzrlib.revision import Revision        
21
22
from bzrlib.errors import BzrError
22
23
 
45
46
 
46
47
    def _pack_entry(self, ie):
47
48
        """Convert InventoryEntry to XML element"""
48
 
        assert ie.kind in ('directory', 'file', 'symlink')
 
49
        if not InventoryEntry.versionable_kind(ie.kind):
 
50
            raise AssertionError('unsupported entry kind %s' % ie.kind)
49
51
        e = Element(ie.kind)
50
52
        e.set('name', ie.name)
51
53
        e.set('file_id', ie.file_id)
117
119
 
118
120
    def _unpack_entry(self, elt):
119
121
        kind = elt.tag
120
 
        if not kind in ('directory', 'file', 'symlink'):
 
122
        if not InventoryEntry.versionable_kind(kind):
121
123
            raise AssertionError('unsupported entry kind %s' % kind)
122
124
 
123
125
        parent_id = elt.get('parent_id')
124
126
        if parent_id == None:
125
127
            parent_id = ROOT_ID
126
128
 
127
 
        ie = InventoryEntry(elt.get('file_id'),
128
 
                            elt.get('name'),
129
 
                            kind,
130
 
                            parent_id)
 
129
        if kind == 'directory':
 
130
            ie = inventory.InventoryDirectory(elt.get('file_id'),
 
131
                                              elt.get('name'),
 
132
                                              parent_id)
 
133
        elif kind == 'file':
 
134
            ie = inventory.InventoryFile(elt.get('file_id'),
 
135
                                         elt.get('name'),
 
136
                                         parent_id)
 
137
            ie.text_sha1 = elt.get('text_sha1')
 
138
            if elt.get('executable') == 'yes':
 
139
                ie.executable = True
 
140
            v = elt.get('text_size')
 
141
            ie.text_size = v and int(v)
 
142
        elif kind == 'symlink':
 
143
            ie = inventory.InventoryLink(elt.get('file_id'),
 
144
                                         elt.get('name'),
 
145
                                         parent_id)
 
146
            ie.symlink_target = elt.get('symlink_target')
 
147
        else:
 
148
            raise BzrError("unknown kind %r" % kind)
131
149
        ie.revision = elt.get('revision')
132
 
        ie.text_sha1 = elt.get('text_sha1')
133
 
        ie.symlink_target = elt.get('symlink_target')
134
 
        if elt.get('executable') == 'yes':
135
 
            ie.executable = True
136
 
        v = elt.get('text_size')
137
 
        ie.text_size = v and int(v)
138
150
 
139
151
        return ie
140
152