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

  • Committer: Parth Malwankar
  • Date: 2010-03-03 14:55:44 UTC
  • mfrom: (5074 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5092.
  • Revision ID: parth.malwankar@gmail.com-20100303145544-1fwse4q2nv2alxoh
merged trunk. resolved conflict in NEWS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
import bzrlib
42
42
from bzrlib import (
43
43
    cleanup,
 
44
    cmdline,
44
45
    debug,
45
46
    errors,
46
47
    option,
54
55
from bzrlib.hooks import HookPoint, Hooks
55
56
# Compatibility - Option used to be in commands.
56
57
from bzrlib.option import Option
 
58
from bzrlib.plugin import disable_plugins, load_plugins
57
59
from bzrlib import registry
58
60
from bzrlib.symbol_versioning import (
59
61
    deprecated_function,
197
199
        raise errors.BzrCommandError('unknown command "%s"' % cmd_name)
198
200
 
199
201
 
200
 
def _get_cmd_object(cmd_name, plugins_override=True):
 
202
def _get_cmd_object(cmd_name, plugins_override=True, check_missing=True):
201
203
    """Get a command object.
202
204
 
203
205
    :param cmd_name: The name of the command.
204
206
    :param plugins_override: Allow plugins to override builtins.
 
207
    :param check_missing: Look up commands not found in the regular index via
 
208
        the get_missing_command hook.
205
209
    :return: A Command object instance
206
210
    :raises KeyError: If no command is found.
207
211
    """
217
221
            # We've found a non-plugin command, don't permit it to be
218
222
            # overridden.
219
223
            break
220
 
    if cmd is None:
 
224
    if cmd is None and check_missing:
221
225
        for hook in Command.hooks['get_missing_command']:
222
226
            cmd = hook(cmd_name)
223
227
            if cmd is not None:
368
372
        # List of standard options directly supported
369
373
        self.supported_std_options = []
370
374
        self._operation = cleanup.OperationWithCleanups(self.run)
371
 
    
 
375
 
372
376
    def add_cleanup(self, cleanup_func, *args, **kwargs):
373
377
        """Register a function to call after self.run returns or raises.
374
378
 
388
392
        resources (such as writing results to self.outf).
389
393
        """
390
394
        self._operation.cleanup_now()
391
 
        
 
395
 
392
396
    @deprecated_method(deprecated_in((2, 1, 0)))
393
397
    def _maybe_expand_globs(self, file_list):
394
398
        """Glob expand file_list if the platform does not do that itself.
873
877
    return ret
874
878
 
875
879
 
 
880
@deprecated_function(deprecated_in((2, 2, 0)))
876
881
def shlex_split_unicode(unsplit):
877
 
    import shlex
878
 
    return [u.decode('utf-8') for u in shlex.split(unsplit.encode('utf-8'))]
 
882
    return cmdline.split(unsplit)
879
883
 
880
884
 
881
885
def get_alias(cmd, config=None):
893
897
        config = bzrlib.config.GlobalConfig()
894
898
    alias = config.get_alias(cmd)
895
899
    if (alias):
896
 
        return shlex_split_unicode(alias)
 
900
        return cmdline.split(alias)
897
901
    return None
898
902
 
899
903
 
900
 
def run_bzr(argv):
 
904
def run_bzr(argv, load_plugins=load_plugins, disable_plugins=disable_plugins):
901
905
    """Execute a command.
902
906
 
903
 
    argv
904
 
       The command-line arguments, without the program name from argv[0]
905
 
       These should already be decoded. All library/test code calling
906
 
       run_bzr should be passing valid strings (don't need decoding).
907
 
 
908
 
    Returns a command status or raises an exception.
 
907
    :param argv: The command-line arguments, without the program name from
 
908
        argv[0] These should already be decoded. All library/test code calling
 
909
        run_bzr should be passing valid strings (don't need decoding).
 
910
    :param load_plugins: What function to call when triggering plugin loading.
 
911
        This function should take no arguments and cause all plugins to be
 
912
        loaded.
 
913
    :param disable_plugins: What function to call when disabling plugin
 
914
        loading. This function should take no arguments and cause all plugin
 
915
        loading to be prohibited (so that code paths in your application that
 
916
        know about some plugins possibly being present will fail to import
 
917
        those plugins even if they are installed.)
 
918
    :return: Returns a command exit code or raises an exception.
909
919
 
910
920
    Special master options: these must come before the command because
911
921
    they control how the command is interpreted.
976
986
 
977
987
    debug.set_debug_flags_from_config()
978
988
 
 
989
    if not opt_no_plugins:
 
990
        load_plugins()
 
991
    else:
 
992
        disable_plugins()
 
993
 
979
994
    argv = argv_copy
980
995
    if (not argv):
981
 
        from bzrlib.builtins import cmd_help
982
 
        cmd_help().run_argv_aliases([])
 
996
        get_cmd_object('help').run_argv_aliases([])
983
997
        return 0
984
998
 
985
999
    if argv[0] == '--version':
986
 
        from bzrlib.builtins import cmd_version
987
 
        cmd_version().run_argv_aliases([])
 
1000
        get_cmd_object('version').run_argv_aliases([])
988
1001
        return 0
989
1002
 
990
 
    if not opt_no_plugins:
991
 
        from bzrlib.plugin import load_plugins
992
 
        load_plugins()
993
 
    else:
994
 
        from bzrlib.plugin import disable_plugins
995
 
        disable_plugins()
996
 
 
997
1003
    alias_argv = None
998
1004
 
999
1005
    if not opt_no_aliases:
1163
1169
        if topic and topic.startswith(self.prefix):
1164
1170
            topic = topic[len(self.prefix):]
1165
1171
        try:
1166
 
            cmd = _get_cmd_object(topic)
 
1172
            cmd = _get_cmd_object(topic, check_missing=False)
1167
1173
        except KeyError:
1168
1174
            return []
1169
1175
        else: