~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/info.py

  • Committer: Daniel Watkins
  • Date: 2008-07-03 07:06:24 UTC
  • mto: (3519.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 3521.
  • Revision ID: d.m.watkins@warwick.ac.uk-20080703070624-ec2e2wpettstd7vu
Further tweaks as requested on-list.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
2
 
#
 
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
2
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
__all__ = ['show_bzrdir_info']
18
18
 
19
 
from cStringIO import StringIO
20
19
import os
21
20
import time
22
21
import sys
25
24
    bzrdir,
26
25
    diff,
27
26
    errors,
28
 
    hooks as _mod_hooks,
29
27
    osutils,
30
28
    urlutils,
31
29
    )
143
141
    locs.add_url('push branch', branch.get_push_location())
144
142
    locs.add_url('parent branch', branch.get_parent())
145
143
    locs.add_url('submit branch', branch.get_submit_branch())
146
 
    try:
147
 
        locs.add_url('stacked on', branch.get_stacked_on_url())
148
 
    except (errors.UnstackableBranchFormat, errors.UnstackableRepositoryFormat,
149
 
        errors.NotStacked):
150
 
        pass
151
144
    return locs
152
145
 
153
146
 
263
256
 
264
257
    dir_cnt = 0
265
258
    for file_id in work_inv:
266
 
        if (work_inv.get_file_kind(file_id) == 'directory' and
 
259
        if (work_inv.get_file_kind(file_id) == 'directory' and 
267
260
            not work_inv.is_root(file_id)):
268
261
            dir_cnt += 1
269
262
    outfile.write('  %8d versioned %s\n' % (dir_cnt,
301
294
            'the repository.\n')
302
295
 
303
296
 
304
 
def _show_repository_stats(repository, stats, outfile):
 
297
def _show_repository_stats(stats, outfile):
305
298
    """Show statistics about a repository."""
306
 
    f = StringIO()
 
299
    if 'revisions' in stats or 'size' in stats:
 
300
        outfile.write('\n')
 
301
        outfile.write('Repository:\n')
307
302
    if 'revisions' in stats:
308
303
        revisions = stats['revisions']
309
 
        f.write('  %8d revision%s\n' % (revisions, plural(revisions)))
 
304
        outfile.write('  %8d revision%s\n' % (revisions, plural(revisions)))
310
305
    if 'size' in stats:
311
 
        f.write('  %8d KiB\n' % (stats['size']/1024))
312
 
    for hook in hooks['repository']:
313
 
        hook(repository, stats, f)
314
 
    if f.getvalue() != "":
315
 
        outfile.write('\n')
316
 
        outfile.write('Repository:\n')
317
 
        outfile.write(f.getvalue())
 
306
        outfile.write('  %8d KiB\n' % (stats['size']/1024))
318
307
 
319
308
 
320
309
def show_bzrdir_info(a_bzrdir, verbose=False, outfile=None):
382
371
    elif branch is not None:
383
372
        _show_missing_revisions_branch(branch, outfile)
384
373
    if branch is not None:
385
 
        show_committers = verbose >= 2
386
 
        stats = _show_branch_stats(branch, show_committers, outfile)
 
374
        stats = _show_branch_stats(branch, verbose==2, outfile)
387
375
    else:
388
376
        stats = repository.gather_stats()
389
377
    if branch is None and working is None:
390
378
        _show_repository_info(repository, outfile)
391
 
    _show_repository_stats(repository, stats, outfile)
 
379
    _show_repository_stats(stats, outfile)
392
380
 
393
381
 
394
382
def describe_layout(repository=None, branch=None, tree=None):
478
466
        # do.
479
467
        candidates = new_candidates
480
468
    return ' or '.join(candidates)
481
 
 
482
 
 
483
 
class InfoHooks(_mod_hooks.Hooks):
484
 
    """Hooks for the info command."""
485
 
 
486
 
    def __init__(self):
487
 
        super(InfoHooks, self).__init__()
488
 
        self.create_hook(_mod_hooks.HookPoint('repository',
489
 
            "Invoked when displaying the statistics for a repository. "
490
 
            "repository is called with a statistics dictionary as returned "
491
 
            "by the repository and a file-like object to write to.", (1, 15), 
492
 
            None))
493
 
 
494
 
 
495
 
hooks = InfoHooks()