~bzr-pqm/bzr/bzr.dev

0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
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
2022.1.3 by John Arbash Meinel
Remove unused imports
19
from bzrlib.rio import RioWriter, Stanza
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
20
2022.1.1 by John Arbash Meinel
[merge] version-info plugin, and cleanup for layout in bzr
21
from bzrlib.version_info_formats import (
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
22
    create_date_str,
23
    VersionInfoBuilder,
24
    )
25
26
27
class RioVersionInfoBuilder(VersionInfoBuilder):
28
    """This writes a rio stream out."""
29
30
    def generate(self, to_file):
31
        info = Stanza()
32
        revision_id = self._get_revision_id()
33
        if revision_id is not None:
34
            info.add('revision-id', revision_id)
35
            rev = self._branch.repository.get_revision(revision_id)
36
            info.add('date', create_date_str(rev.timestamp, rev.timezone))
37
            revno = str(self._branch.revision_id_to_revno(revision_id))
38
        else:
39
            revno = '0'
40
41
        info.add('build-date', create_date_str())
42
        info.add('revno', revno)
43
44
        if self._branch.nick is not None:
45
            info.add('branch-nick', self._branch.nick)
46
47
        if self._check or self._include_file_revs:
48
            self._extract_file_revisions()
49
50
        if self._check:
51
            if self._clean:
52
                info.add('clean', 'True')
53
            else:
54
                info.add('clean', 'False')
55
56
        if self._include_history:
57
            self._extract_revision_history()
58
            log = Stanza()
59
            for (revision_id, message,
60
                 timestamp, timezone) in self._revision_history_info:
61
                log.add('id', revision_id)
62
                log.add('message', message)
63
                log.add('date', create_date_str(timestamp, timezone))
2030.1.2 by John Arbash Meinel
Change the version-info --format=rio to support unicode messages
64
            info.add('revisions', log.to_unicode())
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
65
66
        if self._include_file_revs:
67
            files = Stanza()
68
            for path in sorted(self._file_revisions.keys()):
69
                files.add('path', path)
70
                files.add('revision', self._file_revisions[path])
2030.1.2 by John Arbash Meinel
Change the version-info --format=rio to support unicode messages
71
            info.add('file-revisions', files.to_unicode())
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
72
73
        writer = RioWriter(to_file=to_file)
74
        writer.write_stanza(info)
75
76