~jameinel/bzr/fix-push2

« back to all changes in this revision

Viewing changes to bzrlib/version_info_formats/format_rio.py

  • Committer: Aaron Bentley
  • Date: 2006-09-22 04:52:17 UTC
  • mfrom: (2029 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2078.
  • Revision ID: aaron.bentley@utoronto.ca-20060922045217-4e775bf2fc6d0b3b
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 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
"""A generator which creates a rio stanza of the current tree info"""
 
18
 
 
19
from cStringIO import StringIO
 
20
 
 
21
from bzrlib.rio import RioWriter, Stanza
 
22
 
 
23
from bzrlib.version_info_formats import (
 
24
    create_date_str,
 
25
    VersionInfoBuilder,
 
26
    )
 
27
 
 
28
 
 
29
class RioVersionInfoBuilder(VersionInfoBuilder):
 
30
    """This writes a rio stream out."""
 
31
 
 
32
    def generate(self, to_file):
 
33
        info = Stanza()
 
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))
 
40
        else:
 
41
            revno = '0'
 
42
 
 
43
        info.add('build-date', create_date_str())
 
44
        info.add('revno', revno)
 
45
 
 
46
        if self._branch.nick is not None:
 
47
            info.add('branch-nick', self._branch.nick)
 
48
 
 
49
        if self._check or self._include_file_revs:
 
50
            self._extract_file_revisions()
 
51
 
 
52
        if self._check:
 
53
            if self._clean:
 
54
                info.add('clean', 'True')
 
55
            else:
 
56
                info.add('clean', 'False')
 
57
 
 
58
        if self._include_history:
 
59
            self._extract_revision_history()
 
60
            log = Stanza()
 
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))
 
66
            sio = StringIO()
 
67
            log_writer = RioWriter(to_file=sio)
 
68
            log_writer.write_stanza(log)
 
69
            info.add('revisions', sio.getvalue())
 
70
 
 
71
        if self._include_file_revs:
 
72
            files = Stanza()
 
73
            for path in sorted(self._file_revisions.keys()):
 
74
                files.add('path', path)
 
75
                files.add('revision', self._file_revisions[path])
 
76
            sio = StringIO()
 
77
            file_writer = RioWriter(to_file=sio)
 
78
            file_writer.write_stanza(files)
 
79
            info.add('file-revisions', sio.getvalue())
 
80
 
 
81
        writer = RioWriter(to_file=to_file)
 
82
        writer.write_stanza(info)
 
83
 
 
84