/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
6379.6.3 by Jelmer Vernooij
Use absolute_import.
19
from __future__ import absolute_import
20
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
21
from breezy import hooks
22
from breezy.revision import (
4250.1.1 by Jelmer Vernooij
Fix version-info in empty branches.
23
    NULL_REVISION,
24
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
25
from breezy.rio import RioWriter, Stanza
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
26
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
27
from breezy.version_info_formats import (
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
28
    create_date_str,
29
    VersionInfoBuilder,
30
    )
31
32
33
class RioVersionInfoBuilder(VersionInfoBuilder):
34
    """This writes a rio stream out."""
35
36
    def generate(self, to_file):
37
        info = Stanza()
38
        revision_id = self._get_revision_id()
4250.1.1 by Jelmer Vernooij
Fix version-info in empty branches.
39
        if revision_id != NULL_REVISION:
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
40
            info.add('revision-id', revision_id)
41
            rev = self._branch.repository.get_revision(revision_id)
42
            info.add('date', create_date_str(rev.timestamp, rev.timezone))
5967.11.2 by Benoît Pierre
Update version-info formats to support dotted revnos.
43
            revno = self._get_revno_str(revision_id)
4216.4.1 by Jelmer Vernooij
Allow hooks to add new entries to version-info.
44
            for hook in RioVersionInfoBuilder.hooks['revision']:
45
                hook(rev, info)
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
46
        else:
47
            revno = '0'
48
49
        info.add('build-date', create_date_str())
50
        info.add('revno', revno)
51
52
        if self._branch.nick is not None:
53
            info.add('branch-nick', self._branch.nick)
54
55
        if self._check or self._include_file_revs:
56
            self._extract_file_revisions()
57
58
        if self._check:
59
            if self._clean:
60
                info.add('clean', 'True')
61
            else:
62
                info.add('clean', 'False')
63
64
        if self._include_history:
65
            log = Stanza()
66
            for (revision_id, message,
6165.4.30 by Jelmer Vernooij
Fix remaining tests.
67
                 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.
68
                log.add('id', revision_id)
69
                log.add('message', message)
70
                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
71
            info.add('revisions', log.to_unicode())
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
72
73
        if self._include_file_revs:
74
            files = Stanza()
75
            for path in sorted(self._file_revisions.keys()):
76
                files.add('path', path)
77
                files.add('revision', self._file_revisions[path])
2030.1.2 by John Arbash Meinel
Change the version-info --format=rio to support unicode messages
78
            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.
79
80
        writer = RioWriter(to_file=to_file)
81
        writer.write_stanza(info)
82
83
4216.4.1 by Jelmer Vernooij
Allow hooks to add new entries to version-info.
84
class RioVersionInfoBuilderHooks(hooks.Hooks):
85
    """Hooks for rio-formatted version-info output."""
86
5622.3.10 by Jelmer Vernooij
Don't require arguments to hooks.
87
    def __init__(self):
88
        super(RioVersionInfoBuilderHooks, self).__init__(
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
89
            "breezy.version_info_formats.format_rio", "RioVersionInfoBuilder.hooks")
5622.2.7 by Jelmer Vernooij
Use new hooks infrastructure for version info rio hooks.
90
        self.add_hook('revision',
4216.4.2 by Jelmer Vernooij
Register RioVersionInfoBuilderHooks in the hooks registry.
91
            "Invoked when adding information about a revision to the"
92
            " RIO stanza that is printed. revision is called with a"
5622.3.2 by Jelmer Vernooij
Add more lazily usable hook points.
93
            " revision object and a RIO stanza.", (1, 15))
94
95
5622.3.10 by Jelmer Vernooij
Don't require arguments to hooks.
96
RioVersionInfoBuilder.hooks = RioVersionInfoBuilderHooks()