~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-02-17 08:59:19 UTC
  • mfrom: (5037.2.1 doc)
  • Revision ID: pqm@pqm.ubuntu.com-20100217085919-23vc62bvq8848q65
(mbp) rest markup fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2008, 2009 Canonical Ltd
 
1
# Copyright (C) 2005-2010 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
59
59
    deprecated_function,
60
60
    deprecated_in,
61
61
    deprecated_method,
62
 
    suppress_deprecation_warnings,
63
62
    )
64
63
 
65
64
 
186
185
    return plugin_cmds.keys()
187
186
 
188
187
 
189
 
@deprecated_function(deprecated_in((1, 17, 0)))
190
 
def get_all_cmds(plugins_override=False):
191
 
    """Return canonical name and class for most commands.
192
 
    
193
 
    NB: This does not return all commands since the introduction of
194
 
    command hooks, and returning the class is not sufficient to 
195
 
    get correctly setup commands, which is why it is deprecated.
196
 
 
197
 
    Use 'all_command_names' + 'get_cmd_object' instead.
198
 
    """
199
 
    d = _builtin_commands()
200
 
    if plugins_override:
201
 
        d.update(plugin_cmds.iteritems())
202
 
    for k, v in d.iteritems():
203
 
        yield k,v
204
 
 
205
 
 
206
188
def get_cmd_object(cmd_name, plugins_override=True):
207
189
    """Return the command object for a command.
208
190
 
624
606
 
625
607
    def run_argv_aliases(self, argv, alias_argv=None):
626
608
        """Parse the command line and run with extra aliases in alias_argv."""
627
 
        if argv is None:
628
 
            warn("Passing None for [] is deprecated from bzrlib 0.10",
629
 
                 DeprecationWarning, stacklevel=2)
630
 
            argv = []
631
609
        args, opts = parse_args(self, argv, alias_argv)
632
610
 
633
611
        # Process the standard options
1099
1077
        "bzr plugin-provider-db check")
1100
1078
 
1101
1079
 
1102
 
def main(argv=None):
1103
 
    """Main entry point of command-line interface.
1104
 
 
1105
 
    :param argv: list of unicode command-line arguments similar to sys.argv.
1106
 
        argv[0] is script name usually, it will be ignored.
1107
 
        Don't pass here sys.argv because this list contains plain strings
1108
 
        and not unicode; pass None instead.
1109
 
 
1110
 
    :return: exit code of bzr command.
1111
 
    """
1112
 
    import bzrlib.ui
1113
 
    bzrlib.ui.ui_factory = bzrlib.ui.make_ui_for_terminal(
1114
 
        sys.stdin, sys.stdout, sys.stderr)
1115
 
 
1116
 
    # Is this a final release version? If so, we should suppress warnings
1117
 
    if bzrlib.version_info[3] == 'final':
1118
 
        suppress_deprecation_warnings(override=True)
 
1080
 
 
1081
def _specified_or_unicode_argv(argv):
 
1082
    # For internal or testing use, argv can be passed.  Otherwise, get it from
 
1083
    # the process arguments in a unicode-safe way.
1119
1084
    if argv is None:
1120
 
        argv = osutils.get_unicode_argv()
 
1085
        return osutils.get_unicode_argv()
1121
1086
    else:
1122
1087
        new_argv = []
1123
1088
        try:
1129
1094
                    new_argv.append(a.decode('ascii'))
1130
1095
        except UnicodeDecodeError:
1131
1096
            raise errors.BzrError("argv should be list of unicode strings.")
1132
 
        argv = new_argv
 
1097
        return new_argv
 
1098
 
 
1099
 
 
1100
def main(argv=None):
 
1101
    """Main entry point of command-line interface.
 
1102
 
 
1103
    Typically `bzrlib.initialize` should be called first.
 
1104
 
 
1105
    :param argv: list of unicode command-line arguments similar to sys.argv.
 
1106
        argv[0] is script name usually, it will be ignored.
 
1107
        Don't pass here sys.argv because this list contains plain strings
 
1108
        and not unicode; pass None instead.
 
1109
 
 
1110
    :return: exit code of bzr command.
 
1111
    """
 
1112
    argv = _specified_or_unicode_argv(argv)
1133
1113
    ret = run_bzr_catch_errors(argv)
1134
1114
    bzrlib.ui.ui_factory.log_transport_activity(
1135
1115
        display=('bytes' in debug.debug_flags))
1136
1116
    trace.mutter("return code %d", ret)
1137
 
    osutils.report_extension_load_failures()
1138
1117
    return ret
1139
1118
 
1140
1119
 
1144
1123
    This function assumed that that UI layer is setup, that symbol deprecations
1145
1124
    are already applied, and that unicode decoding has already been performed on argv.
1146
1125
    """
 
1126
    # done here so that they're covered for every test run
1147
1127
    install_bzr_command_hooks()
1148
1128
    return exception_to_return_code(run_bzr, argv)
1149
1129
 
1154
1134
    This is used for the test suite, and might be useful for other programs
1155
1135
    that want to wrap the commandline interface.
1156
1136
    """
 
1137
    # done here so that they're covered for every test run
1157
1138
    install_bzr_command_hooks()
1158
1139
    try:
1159
1140
        return run_bzr(argv)
1209
1190
            yield provider
1210
1191
 
1211
1192
command_providers_registry = ProvidersRegistry()
1212
 
 
1213
 
 
1214
 
if __name__ == '__main__':
1215
 
    sys.exit(main(sys.argv))