3
# Copyright (C) 2005 Canonical Ltd
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
# Author: Martin Pool <mbp@canonical.com>
24
"""Store and retrieve weaves in files.
27
# TODO: When extracting a single version it'd be enough to just pass
28
# an iterator returning the weave lines...
30
FORMAT_1 = '# bzr weave file v1'
35
def write_weave_v1(weave, f):
36
"""Write weave to file f."""
40
for version, verinfo in enumerate(weave._v):
41
print >>f, 'v', version
42
included = list(verinfo.included)
53
if isinstance(l, tuple):
56
print >>f, '%s %d' % l
65
from weave import Weave, VerInfo
68
assert f.readline() == FORMAT_1+'\n'
69
assert f.readline() == '\n'
78
included = map(int, l[2:].split(' '))
79
w._v.append(VerInfo(included))
81
w._v.append(VerInfo())
82
assert f.readline() == '\n'
95
assert l[0] in '{}[]', l
97
w._l.append((l[0], int(l[2:])))