~jelmer/ubuntu/maverick/bzr/2.2.5

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2009-02-14 00:24:06 UTC
  • mfrom: (1.1.48 upstream)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20090214002406-h2zfezq54iylm2w8
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
341
341
            raise NotImplementedError("sorry, no detailed help yet for %r" % self.name())
342
342
 
343
343
        # Extract the summary (purpose) and sections out from the text
344
 
        purpose,sections = self._get_help_parts(doc)
 
344
        purpose,sections,order = self._get_help_parts(doc)
345
345
 
346
346
        # If a custom usage section was provided, use it
347
347
        if sections.has_key('Usage'):
379
379
        # Add the custom sections (e.g. Examples). Note that there's no need
380
380
        # to indent these as they must be indented already in the source.
381
381
        if sections:
382
 
            labels = sorted(sections.keys())
383
 
            for label in labels:
384
 
                result += ':%s:\n%s\n\n' % (label,sections[label])
 
382
            for label in order:
 
383
                if sections.has_key(label):
 
384
                    result += ':%s:\n%s\n\n' % (label,sections[label])
385
385
 
386
386
        # Add the aliases, source (plug-in) and see also links, if any
387
387
        if self.aliases:
416
416
    def _get_help_parts(text):
417
417
        """Split help text into a summary and named sections.
418
418
 
419
 
        :return: (summary,sections) where summary is the top line and
 
419
        :return: (summary,sections,order) where summary is the top line and
420
420
            sections is a dictionary of the rest indexed by section name.
 
421
            order is the order the section appear in the text.
421
422
            A section starts with a heading line of the form ":xxx:".
422
423
            Indented text on following lines is the section value.
423
424
            All text found outside a named section is assigned to the
424
425
            default section which is given the key of None.
425
426
        """
426
 
        def save_section(sections, label, section):
 
427
        def save_section(sections, order, label, section):
427
428
            if len(section) > 0:
428
429
                if sections.has_key(label):
429
430
                    sections[label] += '\n' + section
430
431
                else:
 
432
                    order.append(label)
431
433
                    sections[label] = section
432
434
 
433
435
        lines = text.rstrip().splitlines()
434
436
        summary = lines.pop(0)
435
437
        sections = {}
 
438
        order = []
436
439
        label,section = None,''
437
440
        for line in lines:
438
441
            if line.startswith(':') and line.endswith(':') and len(line) > 2:
439
 
                save_section(sections, label, section)
 
442
                save_section(sections, order, label, section)
440
443
                label,section = line[1:-1],''
441
444
            elif (label is not None) and len(line) > 1 and not line[0].isspace():
442
 
                save_section(sections, label, section)
 
445
                save_section(sections, order, label, section)
443
446
                label,section = None,line
444
447
            else:
445
448
                if len(section) > 0:
446
449
                    section += '\n' + line
447
450
                else:
448
451
                    section = line
449
 
        save_section(sections, label, section)
450
 
        return summary, sections
 
452
        save_section(sections, order, label, section)
 
453
        return summary, sections, order
451
454
 
452
455
    def get_help_topic(self):
453
456
        """Return the commands help topic - its name."""
868
871
 
869
872
def main(argv):
870
873
    import bzrlib.ui
871
 
    from bzrlib.ui.text import TextUIFactory
872
 
    bzrlib.ui.ui_factory = TextUIFactory()
 
874
    bzrlib.ui.ui_factory = bzrlib.ui.make_ui_for_terminal(
 
875
        sys.stdin, sys.stdout, sys.stderr)
873
876
 
874
877
    # Is this a final release version? If so, we should suppress warnings
875
878
    if bzrlib.version_info[3] == 'final':
894
897
    except (KeyboardInterrupt, Exception), e:
895
898
        # used to handle AssertionError and KeyboardInterrupt
896
899
        # specially here, but hopefully they're handled ok by the logger now
897
 
        exitcode = trace.report_exception(sys.exc_info(), sys.stderr)
 
900
        exc_info = sys.exc_info()
 
901
        exitcode = trace.report_exception(exc_info, sys.stderr)
898
902
        if os.environ.get('BZR_PDB'):
899
903
            print '**** entering debugger'
 
904
            tb = exc_info[2]
900
905
            import pdb
901
 
            pdb.post_mortem(sys.exc_traceback)
 
906
            if sys.version_info[:2] < (2, 6):
 
907
                # XXX: we want to do
 
908
                #    pdb.post_mortem(tb)
 
909
                # but because pdb.post_mortem gives bad results for tracebacks
 
910
                # from inside generators, we do it manually.
 
911
                # (http://bugs.python.org/issue4150, fixed in Python 2.6)
 
912
                
 
913
                # Setup pdb on the traceback
 
914
                p = pdb.Pdb()
 
915
                p.reset()
 
916
                p.setup(tb.tb_frame, tb)
 
917
                # Point the debugger at the deepest frame of the stack
 
918
                p.curindex = len(p.stack) - 1
 
919
                p.curframe = p.stack[p.curindex]
 
920
                # Start the pdb prompt.
 
921
                p.print_stack_entry(p.stack[p.curindex])
 
922
                p.execRcLines()
 
923
                p.cmdloop()
 
924
            else:
 
925
                pdb.post_mortem(tb)
902
926
        return exitcode
903
927
 
904
928