/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: Andrew Bennetts
  • Date: 2008-09-08 12:59:00 UTC
  • mfrom: (3695 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3756.
  • Revision ID: andrew.bennetts@canonical.com-20080908125900-8ywtsr7jqyyatjz0
Merge from 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
    )
94
95
 
95
96
 
96
97
def _unsquish_command_name(cmd):
97
 
    assert cmd.startswith("cmd_")
98
98
    return cmd[4:].replace('_','-')
99
99
 
100
100
 
168
168
    cmd_obj = ExternalCommand.find_command(cmd_name)
169
169
    if cmd_obj:
170
170
        return cmd_obj
 
171
 
 
172
    # look for plugins that provide this command but aren't installed
 
173
    for provider in command_providers_registry:
 
174
        try:
 
175
            plugin_metadata = provider.plugin_for_command(cmd_name)
 
176
        except errors.NoPluginAvailable:
 
177
            pass
 
178
        else:
 
179
            raise errors.CommandAvailableInPlugin(cmd_name, 
 
180
                                                  plugin_metadata, provider)
 
181
 
171
182
    raise KeyError
172
183
 
173
184
 
271
282
            elif aname[-1] == '*':
272
283
                aname = '[' + aname[:-1] + '...]'
273
284
            s += aname + ' '
274
 
                
275
 
        assert s[-1] == ' '
276
 
        s = s[:-1]
 
285
        s = s[:-1]      # remove last space
277
286
        return s
278
287
 
279
288
    def get_help_text(self, additional_see_also=None, plain=True,
357
366
            result += ':See also: '
358
367
            result += ', '.join(see_also) + '\n'
359
368
 
360
 
        # If this will be rendered as plan text, convert it
 
369
        # If this will be rendered as plain text, convert it
361
370
        if plain:
362
371
            import bzrlib.help_topics
363
372
            result = bzrlib.help_topics.help_as_plain_text(result)
380
389
                    sections[label] += '\n' + section
381
390
                else:
382
391
                    sections[label] = section
383
 
            
 
392
 
384
393
        lines = text.rstrip().splitlines()
385
394
        summary = lines.pop(0)
386
395
        sections = {}
389
398
            if line.startswith(':') and line.endswith(':') and len(line) > 2:
390
399
                save_section(sections, label, section)
391
400
                label,section = line[1:-1],''
392
 
            elif label != None and len(line) > 1 and not line[0].isspace():
 
401
            elif (label is not None) and len(line) > 1 and not line[0].isspace():
393
402
                save_section(sections, label, section)
394
403
                label,section = None,line
395
404
            else:
433
442
 
434
443
    def _setup_outf(self):
435
444
        """Return a file linked to stdout, which has proper encoding."""
436
 
        assert self.encoding_type in ['strict', 'exact', 'replace']
437
 
 
438
445
        # Originally I was using self.stdout, but that looks
439
446
        # *way* too much like sys.stdout
440
447
        if self.encoding_type == 'exact':
490
497
        self._setup_outf()
491
498
 
492
499
        return self.run(**all_cmd_args)
493
 
    
 
500
 
494
501
    def run(self):
495
502
        """Actually run the command.
496
503
 
789
796
            ret = apply_coveraged(opt_coverage_dir, run, *run_argv)
790
797
        else:
791
798
            ret = run(*run_argv)
 
799
        if 'memory' in debug.debug_flags:
 
800
            try:
 
801
                status_file = file('/proc/%s/status' % os.getpid(), 'rb')
 
802
            except IOError:
 
803
                pass
 
804
            else:
 
805
                status = status_file.read()
 
806
                status_file.close()
 
807
                trace.note("Process status after command:")
 
808
                for line in status.splitlines():
 
809
                    trace.note(line)
792
810
        return ret or 0
793
811
    finally:
794
812
        # reset, in case we may do other commands later within the same process
818
836
    import bzrlib.ui
819
837
    from bzrlib.ui.text import TextUIFactory
820
838
    bzrlib.ui.ui_factory = TextUIFactory()
 
839
     
 
840
    # Is this a final release version? If so, we should suppress warnings
 
841
    if bzrlib.version_info[3] == 'final':
 
842
        from bzrlib import symbol_versioning
 
843
        symbol_versioning.suppress_deprecation_warnings(override=False)
821
844
    try:
822
845
        user_encoding = osutils.get_user_encoding()
823
846
        argv = [a.decode(user_encoding) for a in argv[1:]]
885
908
            return [cmd]
886
909
 
887
910
 
 
911
class Provider(object):
 
912
    '''Generic class to be overriden by plugins'''
 
913
 
 
914
    def plugin_for_command(self, cmd_name):
 
915
        '''Takes a command and returns the information for that plugin
 
916
        
 
917
        :return: A dictionary with all the available information 
 
918
        for the requested plugin
 
919
        '''
 
920
        raise NotImplementedError
 
921
 
 
922
 
 
923
class ProvidersRegistry(registry.Registry):
 
924
    '''This registry exists to allow other providers to exist'''
 
925
 
 
926
    def __iter__(self):
 
927
        for key, provider in self.iteritems():
 
928
            yield provider
 
929
 
 
930
command_providers_registry = ProvidersRegistry()
 
931
 
 
932
 
888
933
if __name__ == '__main__':
889
934
    sys.exit(main(sys.argv))