/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to backend/info.py

  • Committer: Szilveszter Farkas (Phanatic)
  • Date: 2006-06-21 20:14:00 UTC
  • mto: (0.14.1 main) (93.1.1 win32.bialix)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: Szilveszter.Farkas@gmail.com-20060621201400-ef7ddfe95b6687a0
2006-06-20  Szilveszter Farkas <Szilveszter.Farkas@gmail.com>

    * backend/init.py: moved pull() to backend/update.py
    * backend/update.py: implemented update() and missing()
        
2006-06-19  Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
        
    * backend/errors.py: renamed NoPushLocationKnown to NoLocationKnown
    * backend/init.py: implemented pull()

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic)
 
2
# Some parts of the code are:
 
3
# Copyright (C) 2005, 2006 by Canonical Ltd
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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
 
18
 
 
19
import bzrlib
 
20
import bzrlib.errors as errors
 
21
 
 
22
from bzrlib.branch import Branch
 
23
 
 
24
from errors import (NotBranchError)
 
25
 
 
26
def nick(branch, nickname=None):
 
27
    """ Get or set nickname.
 
28
    
 
29
    :param branch: path to the branch
 
30
    
 
31
    :param nickname: if specified, the nickname will be set
 
32
    
 
33
    :return: nickname
 
34
    """
 
35
    try:
 
36
        branch = Branch.open_containing(branch)[0]
 
37
    except errors.NotBranchError:
 
38
        raise NotBranchError
 
39
    
 
40
    if nickname is not None:
 
41
        branch.nick = nickname
 
42
 
 
43
    return branch.nick    
 
44
 
 
45
def revno(branch):
 
46
    """ Get current revision number for specified branch
 
47
    
 
48
    :param branch: path to the branch
 
49
    
 
50
    :return: revision number
 
51
    """
 
52
    try:
 
53
        revno = Branch.open_containing(branch)[0].revno()
 
54
    except errors.NotBranchError:
 
55
        raise NotBranchError
 
56
    else:
 
57
        return revno
 
58
 
 
59
def version():
 
60
    """ Get version information from bzr
 
61
    
 
62
    :return: bzrlib version
 
63
    """
 
64
    return bzrlib.__version__
 
65
 
 
66
def whoami(branch=None, email=False):
 
67
    """ Get user's data (name and email address)
 
68
    
 
69
    :param branch: if specified, the user's data will be looked up in the branch's config
 
70
    
 
71
    :param email: if True, only the email address will be returned
 
72
    
 
73
    :return: user info (only email address if email is True)
 
74
    """
 
75
    from bzrlib.workingtree import WorkingTree
 
76
    
 
77
    if branch is not None:
 
78
        try:
 
79
            b = WorkingTree.open_containing(u'.')[0].branch
 
80
            config = bzrlib.config.BranchConfig(b)
 
81
        except NotBranchError:
 
82
            config = bzrlib.config.GlobalConfig()
 
83
    else:
 
84
        config = bzrlib.config.GlobalConfig()
 
85
        
 
86
    if email:
 
87
        return config.user_email()
 
88
    else:
 
89
        return config.username()
 
90
 
 
91
def info(location):
 
92
    """ Get info about branch, working tree, and repository
 
93
    
 
94
    :param location: the location of the branch/working tree/repository
 
95
    
 
96
    :return: the information in dictionary format
 
97
    
 
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
 
132
    """
 
133
    import bzrlib.bzrdir as bzrdir
 
134
    
 
135
    import info_helper
 
136
    
 
137
    ret = {}
 
138
    a_bzrdir = bzrdir.BzrDir.open_containing(location)[0]
 
139
    try:
 
140
        working = a_bzrdir.open_workingtree()
 
141
        working.lock_read()
 
142
        try:
 
143
            branch = working.branch
 
144
            repository = branch.repository
 
145
            control = working.bzrdir
 
146
 
 
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)
 
156
        finally:
 
157
            working.unlock()
 
158
            return ret
 
159
        return
 
160
    except (errors.NoWorkingTree, errors.NotLocalUrl):
 
161
        pass
 
162
 
 
163
    try:
 
164
        branch = a_bzrdir.open_branch()
 
165
        branch.lock_read()
 
166
        try:
 
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)
 
174
        finally:
 
175
            branch.unlock()
 
176
            return ret
 
177
        return
 
178
    except errors.NotBranchError:
 
179
        pass
 
180
 
 
181
    try:
 
182
        repository = a_bzrdir.open_repository()
 
183
        repository.lock_read()
 
184
        try:
 
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)
 
189
        finally:
 
190
            repository.unlock()
 
191
            return ret
 
192
        return
 
193
    except errors.NoRepositoryPresent:
 
194
        pass