/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/shellcomplete.py

  • Committer: wang
  • Date: 2006-10-29 13:41:32 UTC
  • mto: (2104.4.1 wang_65714)
  • mto: This revision was merged to the branch mainline in revision 2109.
  • Revision ID: wang@ubuntu-20061029134132-3d7f4216f20c4aef
Replace python's difflib by patiencediff because the worst case 
performance is cubic for difflib and people commiting large data 
files are often hurt by this. The worst case performance of patience is 
quadratic. Fix bug 65714.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
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
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
import sys
18
18
 
25
25
    else:
26
26
        shellcomplete_on_command(context, outfile = outfile)
27
27
 
28
 
 
29
 
def shellcomplete_on_command(cmdname, outfile=None):
 
28
def shellcomplete_on_command(cmdname, outfile = None):
30
29
    cmdname = str(cmdname)
31
30
 
32
31
    if outfile is None:
40
39
    if doc is None:
41
40
        raise NotImplementedError("sorry, no detailed shellcomplete yet for %r" % cmdname)
42
41
 
43
 
    shellcomplete_on_options(cmdobj.options().values(), outfile=outfile)
 
42
    shellcomplete_on_option(cmdobj.takes_options, outfile = None)
44
43
    for aname in cmdobj.takes_args:
45
44
        outfile.write(aname + '\n')
46
45
 
47
46
 
48
 
def shellcomplete_on_options(options, outfile=None):
49
 
    for opt in options:
50
 
        short_name = opt.short_name()
51
 
        if short_name:
52
 
            outfile.write('"(--%s -%s)"{--%s,-%s}\n'
53
 
                    % (opt.name, short_name, opt.name, short_name))
54
 
        else:
55
 
            outfile.write('--%s\n' % opt.name)
 
47
def shellcomplete_on_option(options, outfile=None):
 
48
    from bzrlib.option import Option
 
49
    if not options:
 
50
        return
 
51
    if outfile is None:
 
52
        outfile = sys.stdout
 
53
    for on in options:
 
54
        for shortname, longname in Option.SHORT_OPTIONS.items():
 
55
            if longname == on:
 
56
                l = '"(--' + on + ' -' + shortname + ')"{--' + on + ',-' + shortname + '}'
 
57
                break
 
58
            else:
 
59
                l = '--' + on
 
60
        outfile.write(l + '\n')
56
61
 
57
62
 
58
63
def shellcomplete_commands(outfile = None):
60
65
    import inspect
61
66
    import commands
62
67
    from inspect import getdoc
63
 
 
64
 
    commands.install_bzr_command_hooks()
65
 
 
 
68
    
66
69
    if outfile is None:
67
70
        outfile = sys.stdout
68
 
 
 
71
    
69
72
    cmds = []
70
 
    for cmdname in commands.all_command_names():
71
 
        cmd = commands.get_cmd_object(cmdname)
72
 
        cmds.append((cmdname, cmd))
73
 
        for alias in cmd.aliases:
74
 
            cmds.append((alias, cmd))
 
73
    for cmdname, cmdclass in commands.get_all_cmds():
 
74
        cmds.append((cmdname, cmdclass))
 
75
        for alias in cmdclass.aliases:
 
76
            cmds.append((alias, cmdclass))
75
77
    cmds.sort()
76
 
    for cmdname, cmd in cmds:
77
 
        if cmd.hidden:
 
78
    for cmdname, cmdclass in cmds:
 
79
        if cmdclass.hidden:
78
80
            continue
79
 
        doc = getdoc(cmd)
 
81
        doc = getdoc(cmdclass)
80
82
        if doc is None:
81
 
            outfile.write(cmdname + '\n')
 
83
            outfile.write(cmdname + '\n')
82
84
        else:
83
 
            doclines = doc.splitlines()
84
 
            firstline = doclines[0].lower()
85
 
            outfile.write(cmdname + ':' + firstline[0:-1] + '\n')
 
85
            doclines = doc.splitlines()
 
86
            firstline = doclines[0].lower()
 
87
            outfile.write(cmdname + ':' + firstline[0:-1] + '\n')