/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: Jelmer Vernooij
  • Date: 2020-07-05 12:50:01 UTC
  • mfrom: (7490.40.46 work)
  • mto: (7490.40.48 work)
  • mto: This revision was merged to the branch mainline in revision 7519.
  • Revision ID: jelmer@jelmer.uk-20200705125001-7s3vo0p55szbbws7
Merge lp:brz/3.1.

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
 
17
19
# TODO: Define arguments by objects, rather than just using names.
18
20
# Those objects can specify the expected type of the argument, which
19
21
# would help with validation and shell completion.  They could also provide
21
23
 
22
24
# TODO: Specific "examples" property on commands for consistent formatting.
23
25
 
24
 
import contextlib
25
26
import os
26
27
import sys
27
28
 
37
38
 
38
39
import breezy
39
40
from breezy import (
 
41
    cleanup,
40
42
    cmdline,
41
43
    debug,
42
44
    trace,
50
52
from .option import Option
51
53
from .plugin import disable_plugins, load_plugins, plugin_name
52
54
from . import errors, registry
 
55
from .sixish import (
 
56
    string_types,
 
57
    )
53
58
 
54
59
 
55
60
class BzrOptionError(errors.CommandError):
711
716
        r = Option.STD_OPTIONS.copy()
712
717
        std_names = set(r)
713
718
        for o in self.takes_options:
714
 
            if isinstance(o, str):
 
719
            if isinstance(o, string_types):
715
720
                o = option.Option.OPTIONS[o]
716
721
            r[o.name] = o
717
722
            if o.name in std_names:
778
783
            for hook in Command.hooks['pre_command']:
779
784
                hook(self)
780
785
            try:
781
 
                with contextlib.ExitStack() as self._exit_stack:
 
786
                with cleanup.ExitStack() as self._exit_stack:
782
787
                    return class_run(*args, **kwargs)
783
788
            finally:
784
789
                for hook in Command.hooks['post_command']:
1155
1160
    debug.set_debug_flags_from_config()
1156
1161
 
1157
1162
    if not opt_no_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)
 
1163
        load_plugins()
1162
1164
    else:
1163
1165
        disable_plugins()
1164
1166
 
1255
1257
 
1256
1258
def _specified_or_unicode_argv(argv):
1257
1259
    # For internal or testing use, argv can be passed.  Otherwise, get it from
1258
 
    # the process arguments.
 
1260
    # the process arguments in a unicode-safe way.
1259
1261
    if argv is None:
1260
 
        return sys.argv[1:]
 
1262
        return osutils.get_unicode_argv()
1261
1263
    new_argv = []
1262
1264
    try:
1263
1265
        # ensure all arguments are unicode strings
1264
1266
        for a in argv:
1265
 
            if not isinstance(a, str):
 
1267
            if not isinstance(a, string_types):
1266
1268
                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')
1267
1272
            new_argv.append(a)
1268
1273
    except (ValueError, UnicodeDecodeError):
1269
1274
        raise errors.BzrError("argv should be list of unicode strings.")