~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Aaron Bentley
  • Date: 2008-04-24 04:58:42 UTC
  • mfrom: (3377 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3380.
  • Revision ID: aaron@aaronbentley.com-20080424045842-0cajl9v6s4u52kaw
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
    errors,
44
44
    option,
45
45
    osutils,
 
46
    registry,
46
47
    trace,
47
48
    win32utils,
48
49
    )
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, 
 
181
                                                  plugin_metadata, provider)
 
182
 
171
183
    raise KeyError
172
184
 
173
185
 
883
895
            return [cmd]
884
896
 
885
897
 
 
898
class Provider(object):
 
899
    '''Generic class to be overriden by plugins'''
 
900
 
 
901
    def plugin_for_command(self, cmd_name):
 
902
        '''Takes a command and returns the information for that plugin
 
903
        
 
904
        :return: A dictionary with all the available information 
 
905
        for the requested plugin
 
906
        '''
 
907
        raise NotImplementedError
 
908
 
 
909
 
 
910
class ProvidersRegistry(registry.Registry):
 
911
    '''This registry exists to allow other providers to exist'''
 
912
 
 
913
    def __iter__(self):
 
914
        for key, provider in self.iteritems():
 
915
            yield provider
 
916
 
 
917
command_providers_registry = ProvidersRegistry()
 
918
 
 
919
 
886
920
if __name__ == '__main__':
887
921
    sys.exit(main(sys.argv))