bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
149
by mbp at sourcefrog
experiment with new nested inventory file format |
1 |
# (C) 2005 Canonical Ltd
|
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 |
from cElementTree import Element, ElementTree, SubElement |
|
18 |
||
19 |
||
20 |
def write_inventory(inv, f): |
|
21 |
el = Element('inventory', {'version': '2'}) |
|
22 |
||
23 |
root = Element('root_directory', {'id': 'bogus-root-id'}) |
|
24 |
el.append(root) |
|
25 |
||
26 |
def descend(parent_el, ie): |
|
27 |
kind = ie.kind |
|
28 |
el = Element(kind, {'name': ie.name, |
|
29 |
'id': ie.file_id,}) |
|
30 |
||
31 |
if kind == 'file': |
|
32 |
if ie.text_id: |
|
33 |
el.set('text_id', ie.text_id) |
|
34 |
if ie.text_sha1: |
|
35 |
el.set('text_sha1', ie.text_sha1) |
|
36 |
if ie.text_size != None: |
|
37 |
el.set('text_size', ('%d' % ie.text_size)) |
|
38 |
elif kind != 'directory': |
|
39 |
bailout('unknown InventoryEntry kind %r' % kind) |
|
40 |
||
41 |
parent_el.append(el) |
|
42 |
||
43 |
if kind == 'directory': |
|
44 |
l = ie.children.items() |
|
45 |
l.sort() |
|
46 |
for child_name, child_ie in l: |
|
47 |
descend(el, child_ie) |
|
48 |
||
49 |
||
50 |
# walk down through inventory, adding all directories
|
|
51 |
||
52 |
l = inv._root.children.items() |
|
53 |
l.sort() |
|
54 |
for entry_name, ie in l: |
|
55 |
descend(root, ie) |
|
56 |
||
57 |
ElementTree(el).write(f, 'utf-8') |
|
58 |
f.write('\n') |