bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1185.47.1
by Martin Pool
[broken] start converting basic_io to more rfc822-like format |
1 |
# \subsection{Example usage}
|
2 |
#
|
|
3 |
# \textbf{XXX:} Move these to object serialization code.
|
|
4 |
||
7195.5.1
by Martin
Fix remaining whitespace lint in codebase |
5 |
def write_revision(writer, revision): |
6 |
s = Stanza(revision=revision.revision_id, |
|
1185.47.1
by Martin Pool
[broken] start converting basic_io to more rfc822-like format |
7 |
committer=revision.committer, |
8 |
timezone=long(revision.timezone), |
|
9 |
timestamp=long(revision.timestamp), |
|
7195.5.1
by Martin
Fix remaining whitespace lint in codebase |
10 |
inventory_sha1=revision.inventory_sha1, |
1185.47.1
by Martin Pool
[broken] start converting basic_io to more rfc822-like format |
11 |
message=revision.message) |
12 |
for parent_id in revision.parent_ids: |
|
13 |
s.add('parent', parent_id) |
|
14 |
for prop_name, prop_value in revision.properties.items(): |
|
15 |
s.add(prop_name, prop_value) |
|
16 |
writer.write_stanza(s) |
|
17 |
||
18 |
||
19 |
def write_inventory(writer, inventory): |
|
20 |
s = Stanza(inventory_version=7) |
|
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
21 |
writer.write_stanza(s) |
1185.47.1
by Martin Pool
[broken] start converting basic_io to more rfc822-like format |
22 |
|
23 |
for path, ie in inventory.iter_entries(): |
|
24 |
s = Stanza() |
|
25 |
s.add(ie.kind, ie.file_id) |
|
26 |
for attr in ['name', 'parent_id', 'revision', \ |
|
27 |
'text_sha1', 'text_size', 'executable', \ |
|
28 |
'symlink_target', \ |
|
29 |
]:
|
|
30 |
attr_val = getattr(ie, attr, None) |
|
31 |
if attr == 'executable' and attr_val == 0: |
|
32 |
continue
|
|
33 |
if attr == 'parent_id' and attr_val == b'TREE_ROOT': |
|
34 |
continue
|
|
35 |
if attr_val is not None: |
|
6973.13.2
by Jelmer Vernooij
Fix some more tests. |
36 |
s.add(attr, attr_val) |
1185.47.1
by Martin Pool
[broken] start converting basic_io to more rfc822-like format |
37 |
writer.write_stanza(s) |
38 |
||
39 |
||
40 |
def read_inventory(inv_file): |
|
41 |
"""Read inventory object from rio formatted inventory file""" |
|
42 |
from breezy.bzr.inventory import Inventory, InventoryFile |
|
43 |
s = read_stanza(inv_file) |
|
44 |
assert s['inventory_version'] == 7 |
|
6670.4.1
by Jelmer Vernooij
Update imports. |
45 |
inv = Inventory() |
1185.47.1
by Martin Pool
[broken] start converting basic_io to more rfc822-like format |
46 |
for s in read_stanzas(inv_file): |
47 |
kind, file_id = s.items[0] |
|
48 |
parent_id = None |
|
49 |
if 'parent_id' in s: |
|
50 |
parent_id = s['parent_id'] |
|
51 |
if kind == 'file': |
|
52 |
ie = InventoryFile(file_id, s['name'], parent_id) |
|
53 |
ie.text_sha1 = s['text_sha1'] |
|
54 |
ie.text_size = s['text_size'] |
|
55 |
else: |
|
56 |
raise NotImplementedError() |
|
57 |
inv.add(ie) |
|
58 |
return inv |
|
59 |
||
60 |
||
61 |