1
# Copyright (C) 2006 Canonical Ltd
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.
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.
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
17
"""A generator which creates a rio stanza of the current tree info"""
19
from cStringIO import StringIO
21
from bzrlib.rio import RioWriter, Stanza
23
from bzrlib.version_info_formats import (
29
class RioVersionInfoBuilder(VersionInfoBuilder):
30
"""This writes a rio stream out."""
32
def generate(self, to_file):
34
revision_id = self._get_revision_id()
35
if revision_id is not None:
36
info.add('revision-id', revision_id)
37
rev = self._branch.repository.get_revision(revision_id)
38
info.add('date', create_date_str(rev.timestamp, rev.timezone))
39
revno = str(self._branch.revision_id_to_revno(revision_id))
43
info.add('build-date', create_date_str())
44
info.add('revno', revno)
46
if self._branch.nick is not None:
47
info.add('branch-nick', self._branch.nick)
49
if self._check or self._include_file_revs:
50
self._extract_file_revisions()
54
info.add('clean', 'True')
56
info.add('clean', 'False')
58
if self._include_history:
59
self._extract_revision_history()
61
for (revision_id, message,
62
timestamp, timezone) in self._revision_history_info:
63
log.add('id', revision_id)
64
log.add('message', message)
65
log.add('date', create_date_str(timestamp, timezone))
67
log_writer = RioWriter(to_file=sio)
68
log_writer.write_stanza(log)
69
info.add('revisions', sio.getvalue())
71
if self._include_file_revs:
73
for path in sorted(self._file_revisions.keys()):
74
files.add('path', path)
75
files.add('revision', self._file_revisions[path])
77
file_writer = RioWriter(to_file=sio)
78
file_writer.write_stanza(files)
79
info.add('file-revisions', sio.getvalue())
81
writer = RioWriter(to_file=to_file)
82
writer.write_stanza(info)