/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4763.2.4 by John Arbash Meinel
merge bzr.2.1 in preparation for NEWS entry.
1
# Copyright (C) 2006, 2009, 2010 Canonical Ltd
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
16
6379.6.7 by Jelmer Vernooij
Move importing from future until after doc string, otherwise the doc string will disappear.
17
"""A generator which creates a rio stanza of the current tree info"""
18
6968.1.1 by Jelmer Vernooij
Support 'bzr version-info' in horizon branches.
19
from breezy import (
20
    errors,
21
    hooks,
22
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
23
from breezy.revision import (
4250.1.1 by Jelmer Vernooij
Fix version-info in empty branches.
24
    NULL_REVISION,
25
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
26
from breezy.rio import RioWriter, Stanza
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
27
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
28
from breezy.version_info_formats import (
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
29
    create_date_str,
30
    VersionInfoBuilder,
31
    )
32
33
34
class RioVersionInfoBuilder(VersionInfoBuilder):
35
    """This writes a rio stream out."""
36
37
    def generate(self, to_file):
38
        info = Stanza()
39
        revision_id = self._get_revision_id()
4250.1.1 by Jelmer Vernooij
Fix version-info in empty branches.
40
        if revision_id != NULL_REVISION:
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
41
            info.add('revision-id', revision_id)
42
            rev = self._branch.repository.get_revision(revision_id)
43
            info.add('date', create_date_str(rev.timestamp, rev.timezone))
6968.1.1 by Jelmer Vernooij
Support 'bzr version-info' in horizon branches.
44
            try:
45
                revno = self._get_revno_str(revision_id)
46
            except errors.GhostRevisionsHaveNoRevno:
47
                revno = None
4216.4.1 by Jelmer Vernooij
Allow hooks to add new entries to version-info.
48
            for hook in RioVersionInfoBuilder.hooks['revision']:
49
                hook(rev, info)
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
50
        else:
51
            revno = '0'
52
53
        info.add('build-date', create_date_str())
6968.1.1 by Jelmer Vernooij
Support 'bzr version-info' in horizon branches.
54
        if revno is not None:
55
            info.add('revno', revno)
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
56
57
        if self._branch.nick is not None:
58
            info.add('branch-nick', self._branch.nick)
59
60
        if self._check or self._include_file_revs:
61
            self._extract_file_revisions()
62
63
        if self._check:
64
            if self._clean:
65
                info.add('clean', 'True')
66
            else:
67
                info.add('clean', 'False')
68
69
        if self._include_history:
70
            log = Stanza()
71
            for (revision_id, message,
6165.4.30 by Jelmer Vernooij
Fix remaining tests.
72
                 timestamp, timezone) in self._iter_revision_history():
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
73
                log.add('id', revision_id)
74
                log.add('message', message)
75
                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
76
            info.add('revisions', log.to_unicode())
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
77
78
        if self._include_file_revs:
79
            files = Stanza()
80
            for path in sorted(self._file_revisions.keys()):
81
                files.add('path', path)
82
                files.add('revision', self._file_revisions[path])
2030.1.2 by John Arbash Meinel
Change the version-info --format=rio to support unicode messages
83
            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.
84
7045.1.15 by Jelmer Vernooij
fix version info tests
85
        to_file.write(info.to_unicode())
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
86
87
4216.4.1 by Jelmer Vernooij
Allow hooks to add new entries to version-info.
88
class RioVersionInfoBuilderHooks(hooks.Hooks):
89
    """Hooks for rio-formatted version-info output."""
90
5622.3.10 by Jelmer Vernooij
Don't require arguments to hooks.
91
    def __init__(self):
92
        super(RioVersionInfoBuilderHooks, self).__init__(
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
93
            "breezy.version_info_formats.format_rio", "RioVersionInfoBuilder.hooks")
5622.2.7 by Jelmer Vernooij
Use new hooks infrastructure for version info rio hooks.
94
        self.add_hook('revision',
7143.15.2 by Jelmer Vernooij
Run autopep8.
95
                      "Invoked when adding information about a revision to the"
96
                      " RIO stanza that is printed. revision is called with a"
97
                      " revision object and a RIO stanza.", (1, 15))
5622.3.2 by Jelmer Vernooij
Add more lazily usable hook points.
98
99
5622.3.10 by Jelmer Vernooij
Don't require arguments to hooks.
100
RioVersionInfoBuilder.hooks = RioVersionInfoBuilderHooks()