~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Martin Albisetti
  • Date: 2008-03-03 17:12:37 UTC
  • mto: (3350.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 3351.
  • Revision ID: beuno@beuno-laptop-20080303171237-x3ewkoecmv1ab2ue
Core code for automatic plugin suggestion

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
    osutils,
46
46
    trace,
47
47
    win32utils,
 
48
    registry,
48
49
    )
49
50
""")
50
51
 
168
169
    cmd_obj = ExternalCommand.find_command(cmd_name)
169
170
    if cmd_obj:
170
171
        return cmd_obj
 
172
 
 
173
    # look for plugins that provide this command but aren't installed
 
174
    for provider in command_providers_registry:
 
175
        try:
 
176
            plugin_metadata = provider.plugin_for_command(cmd_name)
 
177
        except errors.NoPluginAvailable:
 
178
            pass
 
179
        else:
 
180
            raise errors.CommandAvailableInPlugin(cmd_name, plugin_metadata, provider)
 
181
 
171
182
    raise KeyError
172
183
 
173
184
 
883
894
            return [cmd]
884
895
 
885
896
 
 
897
class Provider(object):
 
898
 
 
899
    def plugin_for_command(self, cmd_name):
 
900
        raise NotImplementedError
 
901
 
 
902
 
 
903
class ProvidersRegistry(registry.Registry):
 
904
    '''This registry exists to allow other providers to exist'''
 
905
    def __iter__(self):
 
906
        for key, provider in self.iteritems():
 
907
            yield provider
 
908
    pass
 
909
 
 
910
command_providers_registry = ProvidersRegistry()
 
911
 
 
912
 
886
913
if __name__ == '__main__':
887
914
    sys.exit(main(sys.argv))