/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 breezy/commands.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-07-28 02:47:10 UTC
  • mfrom: (7519.1.1 merge-3.1)
  • Revision ID: breezy.the.bot@gmail.com-20200728024710-a2ylds219f1lsl62
Merge lp:brz/3.1.

Merged from https://code.launchpad.net/~jelmer/brz/merge-3.1/+merge/388173

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
from __future__ import absolute_import
18
 
 
19
17
# TODO: Define arguments by objects, rather than just using names.
20
18
# Those objects can specify the expected type of the argument, which
21
19
# would help with validation and shell completion.  They could also provide
23
21
 
24
22
# TODO: Specific "examples" property on commands for consistent formatting.
25
23
 
 
24
import contextlib
26
25
import os
27
26
import sys
28
27
 
38
37
 
39
38
import breezy
40
39
from breezy import (
41
 
    cleanup,
42
40
    cmdline,
43
41
    debug,
44
42
    trace,
52
50
from .option import Option
53
51
from .plugin import disable_plugins, load_plugins, plugin_name
54
52
from . import errors, registry
55
 
from .sixish import (
56
 
    string_types,
57
 
    )
58
 
 
59
 
 
60
 
class BzrOptionError(errors.BzrCommandError):
 
53
 
 
54
 
 
55
class BzrOptionError(errors.CommandError):
61
56
 
62
57
    _fmt = "Error in command line options"
63
58
 
303
298
        # No command found, see if this was a typo
304
299
        candidate = guess_command(cmd_name)
305
300
        if candidate is not None:
306
 
            raise errors.BzrCommandError(
 
301
            raise errors.CommandError(
307
302
                gettext('unknown command "%s". Perhaps you meant "%s"')
308
303
                % (cmd_name, candidate))
309
 
        raise errors.BzrCommandError(gettext('unknown command "%s"')
 
304
        raise errors.CommandError(gettext('unknown command "%s"')
310
305
                                     % cmd_name)
311
306
 
312
307
 
716
711
        r = Option.STD_OPTIONS.copy()
717
712
        std_names = set(r)
718
713
        for o in self.takes_options:
719
 
            if isinstance(o, string_types):
 
714
            if isinstance(o, str):
720
715
                o = option.Option.OPTIONS[o]
721
716
            r[o.name] = o
722
717
            if o.name in std_names:
783
778
            for hook in Command.hooks['pre_command']:
784
779
                hook(self)
785
780
            try:
786
 
                with cleanup.ExitStack() as self._exit_stack:
 
781
                with contextlib.ExitStack() as self._exit_stack:
787
782
                    return class_run(*args, **kwargs)
788
783
            finally:
789
784
                for hook in Command.hooks['post_command']:
915
910
    try:
916
911
        options, args = parser.parse_args(args)
917
912
    except UnicodeEncodeError:
918
 
        raise errors.BzrCommandError(
 
913
        raise errors.CommandError(
919
914
            gettext('Only ASCII permitted in option names'))
920
915
 
921
916
    opts = dict((k, v) for k, v in options.__dict__.items() if
940
935
                argdict[argname + '_list'] = None
941
936
        elif ap[-1] == '+':
942
937
            if not args:
943
 
                raise errors.BzrCommandError(gettext(
 
938
                raise errors.CommandError(gettext(
944
939
                    "command {0!r} needs one or more {1}").format(
945
940
                    cmd, argname.upper()))
946
941
            else:
948
943
                args = []
949
944
        elif ap[-1] == '$':  # all but one
950
945
            if len(args) < 2:
951
 
                raise errors.BzrCommandError(
 
946
                raise errors.CommandError(
952
947
                    gettext("command {0!r} needs one or more {1}").format(
953
948
                        cmd, argname.upper()))
954
949
            argdict[argname + '_list'] = args[:-1]
957
952
            # just a plain arg
958
953
            argname = ap
959
954
            if not args:
960
 
                raise errors.BzrCommandError(
 
955
                raise errors.CommandError(
961
956
                    gettext("command {0!r} requires argument {1}").format(
962
957
                        cmd, argname.upper()))
963
958
            else:
964
959
                argdict[argname] = args.pop(0)
965
960
 
966
961
    if args:
967
 
        raise errors.BzrCommandError(gettext(
 
962
        raise errors.CommandError(gettext(
968
963
            "extra argument to command {0}: {1}").format(
969
964
            cmd, args[0]))
970
965
 
1160
1155
    debug.set_debug_flags_from_config()
1161
1156
 
1162
1157
    if not opt_no_plugins:
1163
 
        load_plugins()
 
1158
        from breezy import config
 
1159
        c = config.GlobalConfig()
 
1160
        warn_load_problems = not c.suppress_warning('plugin_load_failure')
 
1161
        load_plugins(warn_load_problems=warn_load_problems)
1164
1162
    else:
1165
1163
        disable_plugins()
1166
1164
 
1257
1255
 
1258
1256
def _specified_or_unicode_argv(argv):
1259
1257
    # For internal or testing use, argv can be passed.  Otherwise, get it from
1260
 
    # the process arguments in a unicode-safe way.
 
1258
    # the process arguments.
1261
1259
    if argv is None:
1262
 
        return osutils.get_unicode_argv()
 
1260
        return sys.argv[1:]
1263
1261
    new_argv = []
1264
1262
    try:
1265
1263
        # ensure all arguments are unicode strings
1266
1264
        for a in argv:
1267
 
            if not isinstance(a, string_types):
 
1265
            if not isinstance(a, str):
1268
1266
                raise ValueError('not native str or unicode: %r' % (a,))
1269
 
            if isinstance(a, bytes):
1270
 
                # For Python 2 only allow ascii native strings
1271
 
                a = a.decode('ascii')
1272
1267
            new_argv.append(a)
1273
1268
    except (ValueError, UnicodeDecodeError):
1274
1269
        raise errors.BzrError("argv should be list of unicode strings.")