~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Vincent Ladeuil
  • Date: 2012-02-14 17:22:37 UTC
  • mfrom: (6466 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120214172237-7dv7er3n4uy8d5m4
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 
34
34
import bzrlib
35
35
from bzrlib import (
 
36
    config,
36
37
    cleanup,
37
38
    cmdline,
38
39
    debug,
689
690
        """
690
691
        class_run = self.run
691
692
        def run(*args, **kwargs):
 
693
            for hook in Command.hooks['pre_command']:
 
694
                hook(self)
692
695
            self._operation = cleanup.OperationWithCleanups(class_run)
693
696
            try:
694
697
                return self._operation.run_simple(*args, **kwargs)
695
698
            finally:
696
699
                del self._operation
 
700
                for hook in Command.hooks['post_command']:
 
701
                    hook(self)
697
702
        self.run = run
698
703
 
699
704
    def run(self):
787
792
            " is safe to mutate - e.g. to remove a command. "
788
793
            "list_commands should return the updated set of command names.",
789
794
            (1, 17))
 
795
        self.add_hook('pre_command',
 
796
            "Called prior to executing a command. Called with the command "
 
797
            "object.", (2, 5))
 
798
        self.add_hook('post_command',
 
799
            "Called after executing a command. Called with the command "
 
800
            "object.", (2, 5))
790
801
 
791
802
Command.hooks = CommandHooks()
792
803
 
1071
1082
            argv_copy.append(a)
1072
1083
        i += 1
1073
1084
 
1074
 
    bzrlib.global_state.cmdline_overrides._from_cmdline(override_config)
 
1085
    if bzrlib.global_state is None:
 
1086
        # FIXME: Workaround for users that imported bzrlib but didn't call
 
1087
        # bzrlib.initialize -- vila 2012-01-19
 
1088
        cmdline_overrides = config.CommandLineStore()
 
1089
    else:
 
1090
        cmdline_overrides = bzrlib.global_state.cmdline_overrides
 
1091
    cmdline_overrides._from_cmdline(override_config)
1075
1092
 
1076
1093
    debug.set_debug_flags_from_config()
1077
1094
 
1131
1148
            trace.debug_memory('Process status after command:', short=False)
1132
1149
        option._verbosity_level = saved_verbosity_level
1133
1150
        # Reset the overrides 
1134
 
        bzrlib.global_state.cmdline_overrides._reset()
 
1151
        cmdline_overrides._reset()
1135
1152
 
1136
1153
 
1137
1154
def display_command(func):