~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/info.py

  • Committer: Aaron Bentley
  • Date: 2007-07-06 21:20:10 UTC
  • mto: (1551.19.24 Aaron's mergeable stuff)
  • mto: This revision was merged to the branch mainline in revision 2600.
  • Revision ID: abentley@panoramicfeedback.com-20070706212010-yesdnjys9484lftu
Provide ways of getting at unicode-clean output

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import os
20
20
import time
21
 
 
 
21
import sys
22
22
 
23
23
from bzrlib import (
24
24
    bzrdir,
46
46
class LocationList(object):
47
47
 
48
48
    def __init__(self, base_path):
49
 
        self.urls = []
 
49
        self.locs = []
50
50
        self.base_path = base_path
51
51
 
52
52
    def add_url(self, label, url):
 
53
        """Add a URL to the list, converting it to a path if possible"""
53
54
        if url is None:
54
55
            return
55
 
        path = urlutils.unescape_for_display(url, 'ascii')
56
 
        if path != url:
 
56
        try:
 
57
            path = urlutils.local_path_from_url(url)
 
58
        except errors.InvalidURL:
 
59
            self.locs.append((label, url))
 
60
        else:
57
61
            self.add_path(label, path)
58
 
        else:
59
 
            self.urls.append((label, url))
60
62
 
61
63
    def add_path(self, label, path):
 
64
        """Add a path, converting it to a relative path if possible"""
62
65
        try:
63
66
            path = osutils.relpath(self.base_path, path)
64
67
        except errors.PathNotChild:
68
71
                path = '.'
69
72
        if path != '/':
70
73
            path = path.rstrip('/')
71
 
        self.urls.append((label, path))
 
74
        self.locs.append((label, path))
72
75
 
73
 
    def print_lines(self):
74
 
        max_len = max(len(l) for l, u in self.urls)
75
 
        for label, url in self.urls:
76
 
            print "  %*s: %s" % (max_len, label, url)
 
76
    def get_lines(self):
 
77
        max_len = max(len(l) for l, u in self.locs)
 
78
        return ["  %*s: %s\n" % (max_len, l, u) for l, u in self.locs ]
77
79
 
78
80
 
79
81
def gather_location_info(repository, branch=None, working=None):
132
134
    path_list = LocationList(os.getcwd())
133
135
    for name, loc in locs:
134
136
        path_list.add_url(name, loc)
135
 
    path_list.print_lines()
 
137
    sys.stdout.writelines(path_list.get_lines())
136
138
 
137
139
def _gather_related_branches(branch):
138
140
    locs = LocationList(os.getcwd())
142
144
    locs.add_url('submit branch', branch.get_submit_branch())
143
145
    return locs
144
146
 
145
 
def _show_related_info(branch):
 
147
def _show_related_info(branch, outfile):
146
148
    """Show parent and push location of branch."""
147
149
    locs = _gather_related_branches(branch)
148
 
    if len(locs.urls) > 0:
149
 
        print
150
 
        print 'Related branches:'
151
 
        locs.print_lines()
 
150
    if len(locs.locs) > 0:
 
151
        print >> outfile
 
152
        print >> outfile, 'Related branches:'
 
153
        outfile.writelines(locs.get_lines())
152
154
 
153
155
 
154
156
def _show_format_info(control=None, repository=None, branch=None, working=None):
342
344
    print "%s (format: %s)" % (layout, format)
343
345
    _show_location_info(gather_location_info(repository, branch, working))
344
346
    if branch is not None:
345
 
        _show_related_info(branch)
 
347
        _show_related_info(branch, sys.stdout)
346
348
    if verbose == 0:
347
349
        return
348
350
    _show_format_info(control, repository, branch, working)