~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/newinventory.py

  • Committer: mbp at sourcefrog
  • Date: 2005-03-30 23:01:29 UTC
  • Revision ID: mbp@sourcefrog.net-20050330230129-8c4a1f77e7d534d9
experiment in writing XML by hand, not through ElementTree

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
                el.set('text_size', ('%d' % ie.text_size))
38
38
        elif kind != 'directory':
39
39
            bailout('unknown InventoryEntry kind %r' % kind)
40
 
            
 
40
 
 
41
        el.tail = '\n'
41
42
        parent_el.append(el)
42
43
 
43
44
        if kind == 'directory':
56
57
    
57
58
    ElementTree(el).write(f, 'utf-8')
58
59
    f.write('\n')
 
60
 
 
61
 
 
62
 
 
63
def write_slacker_inventory(inv, f):
 
64
    def descend(ie):
 
65
        kind = ie.kind
 
66
        f.write('<%s name="%s" id="%s" ' % (kind, ie.name, ie.file_id))
 
67
 
 
68
        if kind == 'file':
 
69
            if ie.text_id:
 
70
                f.write('text_id="%s" ' % ie.text_id)
 
71
            if ie.text_sha1:
 
72
                f.write('text_sha1="%s" ' % ie.text_sha1)
 
73
            if ie.text_size != None:
 
74
                f.write('text_size="%d" ' % ie.text_size)
 
75
            f.write('/>\n')
 
76
        elif kind == 'directory':
 
77
            f.write('>\n')
 
78
            
 
79
            l = ie.children.items()
 
80
            l.sort()
 
81
            for child_name, child_ie in l:
 
82
                descend(child_ie)
 
83
 
 
84
            f.write('</directory>\n')
 
85
        else:
 
86
            bailout('unknown InventoryEntry kind %r' % kind)
 
87
 
 
88
    f.write('<inventory>\n')
 
89
    f.write('<root_directory id="bogus-root-id">\n')
 
90
 
 
91
    l = inv._root.children.items()
 
92
    l.sort()
 
93
    for entry_name, ie in l:
 
94
        descend(ie)
 
95
 
 
96
    f.write('</root-directory>\n')
 
97
    f.write('</inventory>\n')
 
98
    
 
99
 
 
100