/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: Gustav Hartvigsson
  • Date: 2021-01-09 21:36:27 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210109213627-h1xwcutzy9m7a99b
Added 'Case Preserving Working Tree Use Cases' from Canonical Wiki

* Addod a page from the Canonical Bazaar wiki
  with information on the scmeatics of case
  perserving filesystems an a case insensitive
  filesystem works.
  
  * Needs re-work, but this will do as it is the
    same inforamoton as what was on the linked
    page in the currint documentation.

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
 
264
259
        names.update(cmd.aliases)
265
260
    # candidate: modified levenshtein distance against cmd_name.
266
261
    costs = {}
267
 
    from . import patiencediff
 
262
    import patiencediff
268
263
    for name in sorted(names):
269
264
        matcher = patiencediff.PatienceSequenceMatcher(None, cmd_name, name)
270
265
        distance = 0.0
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
 
496
491
 
497
492
        Functions will be called in LIFO order.
498
493
        """
499
 
        self._operation.add_cleanup(cleanup_func, *args, **kwargs)
 
494
        self._exit_stack.callback(cleanup_func, *args, **kwargs)
500
495
 
501
496
    def cleanup_now(self):
502
497
        """Execute and empty pending cleanup functions immediately.
511
506
        as it releases all resources, this may release locks that the command
512
507
        wants to hold, so use should be done with care.
513
508
        """
514
 
        self._operation.cleanup_now()
 
509
        self._exit_stack.close()
 
510
 
 
511
    def enter_context(self, cm):
 
512
        return self._exit_stack.enter_context(cm)
515
513
 
516
514
    def _usage(self):
517
515
        """Return single-line grammar for this command.
713
711
        r = Option.STD_OPTIONS.copy()
714
712
        std_names = set(r)
715
713
        for o in self.takes_options:
716
 
            if isinstance(o, string_types):
 
714
            if isinstance(o, str):
717
715
                o = option.Option.OPTIONS[o]
718
716
            r[o.name] = o
719
717
            if o.name in std_names:
779
777
        def run(*args, **kwargs):
780
778
            for hook in Command.hooks['pre_command']:
781
779
                hook(self)
782
 
            self._operation = cleanup.OperationWithCleanups(class_run)
783
780
            try:
784
 
                return self._operation.run_simple(*args, **kwargs)
 
781
                with contextlib.ExitStack() as self._exit_stack:
 
782
                    return class_run(*args, **kwargs)
785
783
            finally:
786
 
                del self._operation
787
784
                for hook in Command.hooks['post_command']:
788
785
                    hook(self)
789
786
        self.run = run
799
796
        an exception to raise up.
800
797
 
801
798
        This method is automatically wrapped by Command.__init__ with a
802
 
        cleanup operation, stored as self._operation. This can be used
 
799
        ExitStack, stored as self._exit_stack. This can be used
803
800
        via self.add_cleanup to perform automatic cleanups at the end of
804
801
        run().
805
802
 
913
910
    try:
914
911
        options, args = parser.parse_args(args)
915
912
    except UnicodeEncodeError:
916
 
        raise errors.BzrCommandError(
 
913
        raise errors.CommandError(
917
914
            gettext('Only ASCII permitted in option names'))
918
915
 
919
916
    opts = dict((k, v) for k, v in options.__dict__.items() if
938
935
                argdict[argname + '_list'] = None
939
936
        elif ap[-1] == '+':
940
937
            if not args:
941
 
                raise errors.BzrCommandError(gettext(
 
938
                raise errors.CommandError(gettext(
942
939
                    "command {0!r} needs one or more {1}").format(
943
940
                    cmd, argname.upper()))
944
941
            else:
946
943
                args = []
947
944
        elif ap[-1] == '$':  # all but one
948
945
            if len(args) < 2:
949
 
                raise errors.BzrCommandError(
 
946
                raise errors.CommandError(
950
947
                    gettext("command {0!r} needs one or more {1}").format(
951
948
                        cmd, argname.upper()))
952
949
            argdict[argname + '_list'] = args[:-1]
955
952
            # just a plain arg
956
953
            argname = ap
957
954
            if not args:
958
 
                raise errors.BzrCommandError(
 
955
                raise errors.CommandError(
959
956
                    gettext("command {0!r} requires argument {1}").format(
960
957
                        cmd, argname.upper()))
961
958
            else:
962
959
                argdict[argname] = args.pop(0)
963
960
 
964
961
    if args:
965
 
        raise errors.BzrCommandError(gettext(
 
962
        raise errors.CommandError(gettext(
966
963
            "extra argument to command {0}: {1}").format(
967
964
            cmd, args[0]))
968
965
 
972
969
def apply_coveraged(the_callable, *args, **kwargs):
973
970
    import coverage
974
971
    cov = coverage.Coverage()
975
 
    os.environ['COVERAGE_PROCESS_START'] = cov.config_file
 
972
    try:
 
973
        config_file = cov.config.config_file
 
974
    except AttributeError:  # older versions of coverage
 
975
        config_file = cov.config_file
 
976
    os.environ['COVERAGE_PROCESS_START'] = config_file
976
977
    cov.start()
977
978
    try:
978
979
        return exception_to_return_code(the_callable, *args, **kwargs)
1154
1155
    debug.set_debug_flags_from_config()
1155
1156
 
1156
1157
    if not opt_no_plugins:
1157
 
        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)
1158
1162
    else:
1159
1163
        disable_plugins()
1160
1164
 
1251
1255
 
1252
1256
def _specified_or_unicode_argv(argv):
1253
1257
    # For internal or testing use, argv can be passed.  Otherwise, get it from
1254
 
    # the process arguments in a unicode-safe way.
 
1258
    # the process arguments.
1255
1259
    if argv is None:
1256
 
        return osutils.get_unicode_argv()
 
1260
        return sys.argv[1:]
1257
1261
    new_argv = []
1258
1262
    try:
1259
1263
        # ensure all arguments are unicode strings
1260
1264
        for a in argv:
1261
 
            if not isinstance(a, string_types):
 
1265
            if not isinstance(a, str):
1262
1266
                raise ValueError('not native str or unicode: %r' % (a,))
1263
 
            if isinstance(a, bytes):
1264
 
                # For Python 2 only allow ascii native strings
1265
 
                a = a.decode('ascii')
1266
1267
            new_argv.append(a)
1267
1268
    except (ValueError, UnicodeDecodeError):
1268
1269
        raise errors.BzrError("argv should be list of unicode strings.")