bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
1 |
# Copyright (C) 2005 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 |
"""\
|
|
18 |
Routines for extracting all version information from a bzr branch.
|
|
19 |
"""
|
|
20 |
||
21 |
import time |
|
22 |
||
23 |
from bzrlib.rio import RioReader, RioWriter, Stanza |
|
24 |
from bzrlib.errors import NoWorkingTree |
|
25 |
from errors import UncleanError |
|
26 |
||
27 |
def is_clean(branch): |
|
28 |
""" |
|
29 |
Raise an UncleanError if there is anything unclean about this
|
|
30 |
branch.
|
|
31 |
||
32 |
:param branch: The branch to check for changes
|
|
33 |
TODO: jam 20051228 This might be better to ask for a WorkingTree
|
|
34 |
instead of a Branch.
|
|
35 |
"""
|
|
36 |
try: |
|
37 |
new_tree = branch.working_tree() |
|
38 |
except NoWorkingTree: |
|
39 |
# Trees without a working tree can't be dirty :)
|
|
40 |
return
|
|
41 |
||
42 |
# Look for unknown files in the new tree
|
|
43 |
for info in new_tree.list_files(): |
|
44 |
path = info[0] |
|
45 |
file_class = info[1] |
|
46 |
if file_class == '?': |
|
47 |
raise UncleanError(branch, 'path %s is unknown' % (path,)) |
|
48 |
||
49 |
from bzrlib.diff import compare_trees |
|
50 |
# See if there is anything that has been changed
|
|
51 |
old_tree = branch.basis_tree() |
|
52 |
delta = compare_trees(old_tree, new_tree, want_unchanged=False) |
|
53 |
if len(delta.added) > 0: |
|
54 |
raise UncleanError(branch, 'have added files: %r' % (delta.added,)) |
|
55 |
if len(delta.removed) > 0: |
|
56 |
raise UncleanError(branch, 'have removed files: %r' % (delta.removed,)) |
|
57 |
if len(delta.modified) > 0: |
|
58 |
raise UncleanError(branch, 'have modified files: %r' % (delta.modified,)) |
|
59 |
if len(delta.renamed) > 0: |
|
60 |
raise UncleanError(branch, 'have renamed files: %r' % (delta.renamed,)) |
|
61 |
||
62 |
||
|
0.8.2
by John Arbash Meinel
Have working rio output |
63 |
def generate_rio_version(branch, to_file, |
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
64 |
check_for_clean=False, |
65 |
include_revision_history=False, |
|
66 |
include_log_info=False, |
|
67 |
include_log_deltas=False): |
|
68 |
"""Create the version file for this project. |
|
69 |
||
70 |
:param branch: The branch to write information about
|
|
71 |
:param to_file: The file to write the information
|
|
72 |
:param check_for_clean: If true, check if the branch is clean.
|
|
73 |
This can be expensive for large trees. This is also only
|
|
74 |
valid for branches with working trees.
|
|
75 |
:param include_revision_history: Write out the list of revisions
|
|
76 |
:param include_log_info: Include log information (log summary, etc),
|
|
77 |
only valid if include_revision_history is also True
|
|
78 |
:param include_log_deltas: Include information about what changed in
|
|
79 |
each revision. Only valid if include_log_info is also True
|
|
80 |
"""
|
|
81 |
info = Stanza() |
|
82 |
# TODO: jam 20051228 This might be better as the datestamp
|
|
83 |
# of the last commit
|
|
84 |
info.add('date', time.strftime('%Y-%m-%d %H:%M:%S (%A, %B %d, %Y, %Z)')) |
|
|
0.8.2
by John Arbash Meinel
Have working rio output |
85 |
info.add('revno', str(branch.revno())) |
86 |
last_rev = branch.last_revision() |
|
87 |
if last_rev is not None: |
|
88 |
info.add('revision_id', last_rev) |
|
89 |
if branch.nick is not None: |
|
90 |
info.add('branch_nick', branch.nick) |
|
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
91 |
if check_for_clean: |
92 |
try: |
|
|
0.8.2
by John Arbash Meinel
Have working rio output |
93 |
is_clean(branch) |
94 |
except UncleanError: |
|
95 |
info.add('clean', 'False') |
|
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
96 |
else: |
|
0.8.2
by John Arbash Meinel
Have working rio output |
97 |
info.add('clean', 'True') |
98 |
writer = RioWriter(to_file=to_file) |
|
99 |
writer.write_stanza(info) |
|
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
100 |
|
|
0.8.2
by John Arbash Meinel
Have working rio output |
101 |
version_formats = {None:generate_rio_version, 'rio':generate_rio_version} |
|
0.8.1
by John Arbash Meinel
Creating a plugin to ease generating version information from a tree. |
102 |