/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/newinventory.py

  • Committer: mbp at sourcefrog
  • Date: 2005-04-07 05:57:33 UTC
  • Revision ID: mbp@sourcefrog.net-20050407055732-18515720cd651e14646d6656
64 bits of randomness in file/revision ids

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# (C) 2005 Canonical Ltd
2
 
#
 
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
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
from bzrlib.xml import ElementTree, Element
 
17
from cElementTree import Element, ElementTree, SubElement
18
18
 
19
19
 
20
20
def write_inventory(inv, f):
21
21
    el = Element('inventory', {'version': '2'})
22
22
    el.text = '\n'
23
 
 
 
23
    
24
24
    root = Element('root_directory', {'id': inv.root.file_id})
25
25
    root.tail = root.text = '\n'
26
26
    el.append(root)
35
35
                el.set('text_id', ie.text_id)
36
36
            if ie.text_sha1:
37
37
                el.set('text_sha1', ie.text_sha1)
38
 
            if ie.text_size is not None:
 
38
            if ie.text_size != None:
39
39
                el.set('text_size', ('%d' % ie.text_size))
40
40
        elif kind != 'directory':
41
 
            raise BzrError('unknown InventoryEntry kind %r' % kind)
 
41
            bailout('unknown InventoryEntry kind %r' % kind)
42
42
 
43
43
        el.tail = '\n'
44
44
        parent_el.append(el)
62
62
    f.write('\n')
63
63
 
64
64
 
65
 
 
66
 
def escape_attr(text):
67
 
    return text.replace("&", "&") \
68
 
           .replace("'", "'") \
69
 
           .replace('"', """) \
70
 
           .replace("<", "&lt;") \
71
 
           .replace(">", "&gt;")
72
 
 
73
 
 
74
65
# This writes out an inventory without building an XML tree first,
75
66
# just to see if it's faster.  Not currently used.
76
67
def write_slacker_inventory(inv, f):
77
68
    def descend(ie):
78
69
        kind = ie.kind
79
 
        f.write('<%s name="%s" id="%s" ' % (kind, escape_attr(ie.name),
80
 
                                            escape_attr(ie.file_id)))
 
70
        f.write('<%s name="%s" id="%s" ' % (kind, ie.name, ie.file_id))
81
71
 
82
72
        if kind == 'file':
83
73
            if ie.text_id:
84
74
                f.write('text_id="%s" ' % ie.text_id)
85
75
            if ie.text_sha1:
86
76
                f.write('text_sha1="%s" ' % ie.text_sha1)
87
 
            if ie.text_size is not None:
 
77
            if ie.text_size != None:
88
78
                f.write('text_size="%d" ' % ie.text_size)
89
79
            f.write('/>\n')
90
80
        elif kind == 'directory':
97
87
 
98
88
            f.write('</directory>\n')
99
89
        else:
100
 
            raise BzrError('unknown InventoryEntry kind %r' % kind)
 
90
            bailout('unknown InventoryEntry kind %r' % kind)
101
91
 
102
92
    f.write('<inventory>\n')
103
 
    f.write('<root_directory id="%s">\n' % escape_attr(inv.root.file_id))
 
93
    f.write('<root_directory id="bogus-root-id">\n')
104
94
 
105
95
    l = inv.root.children.items()
106
96
    l.sort()
132
122
            ie.text_size = v and int(v)
133
123
            ie.text_sha1 = el.get('text_sha1')
134
124
        else:
135
 
            raise BzrError("unknown inventory entry %r" % kind)
 
125
            bailout("unknown inventory entry %r" % kind)
136
126
 
137
127
    inv_el = ElementTree().parse(f)
138
128
    assert inv_el.tag == 'inventory'
139
129
    root_el = inv_el[0]
140
130
    assert root_el.tag == 'root_directory'
141
131
 
142
 
    inv = Inventory(inv_el.get('file_id'))
 
132
    inv = Inventory()
143
133
    for el in root_el:
144
134
        descend(inv.root, el)