341
341
raise NotImplementedError("sorry, no detailed help yet for %r" % self.name())
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)
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.
382
labels = sorted(sections.keys())
384
result += ':%s:\n%s\n\n' % (label,sections[label])
383
if sections.has_key(label):
384
result += ':%s:\n%s\n\n' % (label,sections[label])
386
386
# Add the aliases, source (plug-in) and see also links, if any
416
416
def _get_help_parts(text):
417
417
"""Split help text into a summary and named sections.
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.
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
431
433
sections[label] = section
433
435
lines = text.rstrip().splitlines()
434
436
summary = lines.pop(0)
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
445
448
if len(section) > 0:
446
449
section += '\n' + line
449
save_section(sections, label, section)
450
return summary, sections
452
save_section(sections, order, label, section)
453
return summary, sections, order
452
455
def get_help_topic(self):
453
456
"""Return the commands help topic - its name."""
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)
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'
901
pdb.post_mortem(sys.exc_traceback)
906
if sys.version_info[:2] < (2, 6):
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)
913
# Setup pdb on the traceback
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])