1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic)
2
# Some parts of the code are:
3
# Copyright (C) 2005, 2006 by Canonical Ltd
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
import bzrlib.errors as errors
22
from bzrlib.branch import Branch
24
from errors import (NotBranchError)
26
def nick(branch, nickname=None):
27
""" Get or set nickname.
29
:param branch: path to the branch
31
:param nickname: if specified, the nickname will be set
36
branch = Branch.open_containing(branch)[0]
37
except errors.NotBranchError:
40
if nickname is not None:
41
branch.nick = nickname
46
""" Get current revision number for specified branch
48
:param branch: path to the branch
50
:return: revision number
53
revno = Branch.open_containing(branch)[0].revno()
54
except errors.NotBranchError:
60
""" Get version information from bzr
62
:return: bzrlib version
64
return bzrlib.__version__
66
def whoami(branch=None, email=False):
67
""" Get user's data (name and email address)
69
:param branch: if specified, the user's data will be looked up in the branch's config
71
:param email: if True, only the email address will be returned
73
:return: user info (only email address if email is True)
75
from bzrlib.workingtree import WorkingTree
77
if branch is not None:
79
b = WorkingTree.open_containing(u'.')[0].branch
80
config = bzrlib.config.BranchConfig(b)
81
except NotBranchError:
82
config = bzrlib.config.GlobalConfig()
84
config = bzrlib.config.GlobalConfig()
87
return config.user_email()
89
return config.username()
92
""" Get info about branch, working tree, and repository
94
:param location: the location of the branch/working tree/repository
96
:return: the information in dictionary format
98
The following informations are delivered (if available):
99
ret['location']['lightcoroot']: Light checkout root
100
ret['location']['sharedrepo']: Shared repository
101
ret['location']['repobranch']: Repository branch
102
ret['location']['cobranch']: Checkout of branch
103
ret['location']['repoco']: Repository checkout
104
ret['location']['coroot']: Checkout root
105
ret['location']['branchroot']: Branch root
106
ret['related']['parentbranch']: Parent branch
107
ret['related']['publishbranch']: Publish to branch
108
ret['format']['control']: Control format
109
ret['format']['workingtree']: Working tree format
110
ret['format']['branch']: Branch format
111
ret['format']['repository']: Repository format
112
ret['locking']['workingtree']: Working tree lock status
113
ret['locking']['branch']: Branch lock status
114
ret['locking']['repository']: Repository lock status
115
ret['mrevbranch']['missing']: Missing revisions in branch
116
ret['mrevworking']['missing']: Missing revisions in working tree
117
ret['wtstats']['unchanged']: Unchanged files
118
ret['wtstats']['modified']: Modified files
119
ret['wtstats']['added']: Added files
120
ret['wtstats']['removed']: Removed files
121
ret['wtstats']['renamed']: Renamed files
122
ret['wtstats']['unknown']: Unknown files
123
ret['wtstats']['ignored']: Ingnored files
124
ret['wtstats']['subdirs']: Versioned subdirectories
125
ret['brstats']['revno']: Revisions in branch
126
ret['brstats']['commiters']: Number of commiters
127
ret['brstats']['age']: Age of branch in days
128
ret['brstats']['firstrev']: Time of first revision
129
ret['brstats']['lastrev']: Time of last revision
130
ret['repstats']['revisions']: Revisions in repository
131
ret['repstats']['size']: Size of repository in bytes
133
import bzrlib.bzrdir as bzrdir
138
a_bzrdir = bzrdir.BzrDir.open_containing(location)[0]
140
working = a_bzrdir.open_workingtree()
143
branch = working.branch
144
repository = branch.repository
145
control = working.bzrdir
147
ret['location'] = info_helper.get_location_info(repository, branch, working)
148
ret['related'] = info_helper.get_related_info(branch)
149
ret['format'] = info_helper.get_format_info(control, repository, branch, working)
150
ret['locking'] = info_helper.get_locking_info(repository, branch, working)
151
ret['mrevbranch'] = info_helper.get_missing_revisions_branch(branch)
152
ret['mrevworking'] = info_helper.get_missing_revisions_working(working)
153
ret['wtstats'] = info_helper.get_working_stats(working)
154
ret['brstats'] = info_helper.get_branch_stats(branch)
155
ret['repstats'] = info_helper.get_repository_stats(repository)
160
except (errors.NoWorkingTree, errors.NotLocalUrl):
164
branch = a_bzrdir.open_branch()
167
ret['location'] = info_helper.get_location_info(repository, branch)
168
ret['related'] = info_helper.get_related_info(branch)
169
ret['format'] = info_helper.get_format_info(control, repository, branch)
170
ret['locking'] = info_helper.get_locking_info(repository, branch)
171
ret['mrevbranch'] = info_helper.get_missing_revisions_branch(branch)
172
ret['brstats'] = info_helper.get_branch_stats(branch)
173
ret['repstats'] = info_helper.get_repository_stats(repository)
178
except errors.NotBranchError:
182
repository = a_bzrdir.open_repository()
183
repository.lock_read()
185
ret['location'] = info_helper.get_location_info(repository)
186
ret['format'] = info_helper.get_format_info(control, repository)
187
ret['locking'] = info_helper.get_locking_info(repository)
188
ret['repstats'] = info_helper.get_repository_stats(repository)
193
except errors.NoRepositoryPresent: