DocumentationTools/ModuleDocumentor.py

branch
Py2 comp.
changeset 3060
5883ce99ee12
parent 3058
0a02c433f52d
parent 3033
58fe260e7469
child 3145
a9de05d4a22f
equal deleted inserted replaced
3058:0a02c433f52d 3060:5883ce99ee12
30 ^@signal [ \t]+ 30 ^@signal [ \t]+
31 (?P<SignalName2> 31 (?P<SignalName2>
32 [a-zA-Z_] \w* 32 [a-zA-Z_] \w*
33 ) 33 )
34 [ \t]+ (?P<SignalDescription2> .*) 34 [ \t]+ (?P<SignalDescription2> .*)
35 """, re.VERBOSE | re.DOTALL | re.MULTILINE).search 35 """, re.VERBOSE | re.DOTALL | re.MULTILINE).search
36 36
37 _event = re.compile( 37 _event = re.compile(
38 r""" 38 r"""
39 ^@event [ \t]+ 39 ^@event [ \t]+
40 (?P<EventName1> 40 (?P<EventName1>
45 ^@event [ \t]+ 45 ^@event [ \t]+
46 (?P<EventName2> 46 (?P<EventName2>
47 [a-zA-Z_] \w* 47 [a-zA-Z_] \w*
48 ) 48 )
49 [ \t]+ (?P<EventDescription2> .*) 49 [ \t]+ (?P<EventDescription2> .*)
50 """, re.VERBOSE | re.DOTALL | re.MULTILINE).search 50 """, re.VERBOSE | re.DOTALL | re.MULTILINE).search
51 51
52 52
53 class TagError(Exception): 53 class TagError(Exception):
54 """ 54 """
55 Exception class raised, if an invalid documentation tag was found. 55 Exception class raised, if an invalid documentation tag was found.
235 """ 235 """
236 Public method to generate the source code documentation. 236 Public method to generate the source code documentation.
237 237
238 @return The source code documentation. (string) 238 @return The source code documentation. (string)
239 """ 239 """
240 doc = self.headerTemplate.format(**{ \ 240 doc = self.headerTemplate.format(
241 'Title': self.module.name, 241 **{'Title': self.module.name,
242 'Style': self.stylesheet}) + \ 242 'Style': self.stylesheet}) + \
243 self.__genModuleSection() + \ 243 self.__genModuleSection() + \
244 self.footerTemplate 244 self.footerTemplate
245 self.generated = True 245 self.generated = True
246 return doc 246 return doc
247 247
248 def __genModuleSection(self): 248 def __genModuleSection(self):
249 """ 249 """
255 classList = self.__genClassListSection() 255 classList = self.__genClassListSection()
256 functionList = self.__genFunctionListSection() 256 functionList = self.__genFunctionListSection()
257 try: 257 try:
258 if self.module.type == RB_SOURCE: 258 if self.module.type == RB_SOURCE:
259 rbModulesList = self.__genRbModulesListSection() 259 rbModulesList = self.__genRbModulesListSection()
260 modBody = self.rbFileTemplate.format(**{ \ 260 modBody = self.rbFileTemplate.format(
261 'Module': self.module.name, 261 **{'Module': self.module.name,
262 'ModuleDescription': \ 262 'ModuleDescription':
263 self.__formatDescription(self.module.description), 263 self.__formatDescription(self.module.description),
264 'GlobalsList': globalsList, 264 'GlobalsList': globalsList,
265 'ClassList': classList, 265 'ClassList': classList,
266 'RbModulesList': rbModulesList, 266 'RbModulesList': rbModulesList,
267 'FunctionList': functionList, 267 'FunctionList': functionList,
268 }) 268 })
269 else: 269 else:
270 modBody = self.moduleTemplate.format(**{ \ 270 modBody = self.moduleTemplate.format(
271 'Module': self.module.name, 271 **{'Module': self.module.name,
272 'ModuleDescription': \ 272 'ModuleDescription':
273 self.__formatDescription(self.module.description), 273 self.__formatDescription(self.module.description),
274 'GlobalsList': globalsList, 274 'GlobalsList': globalsList,
275 'ClassList': classList, 275 'ClassList': classList,
276 'FunctionList': functionList, 276 'FunctionList': functionList,
277 }) 277 })
278 except TagError as e: 278 except TagError as e:
279 sys.stderr.write( 279 sys.stderr.write(
280 "Error in tags of description of module {0}.\n".format( 280 "Error in tags of description of module {0}.\n".format(
281 self.module.name)) 281 self.module.name))
282 sys.stderr.write("{0}\n".format(e)) 282 sys.stderr.write("{0}\n".format(e))
283 return "" 283 return ""
284 284
285 classesSection = self.__genClassesSection() 285 classesSection = self.__genClassesSection()
286 functionsSection = self.__genFunctionsSection() 286 functionsSection = self.__genFunctionsSection()
300 @param kwSuffix suffix to be used for the QtHelp keywords (string) 300 @param kwSuffix suffix to be used for the QtHelp keywords (string)
301 @return The list section. (string) 301 @return The list section. (string)
302 """ 302 """
303 lst = [] 303 lst = []
304 for name in names: 304 for name in names:
305 lst.append(self.listEntryTemplate.format(**{ \ 305 lst.append(self.listEntryTemplate.format(
306 'Link': "{0}".format(name), 306 **{'Link': "{0}".format(name),
307 'Name': dict[name].name, 307 'Name': dict[name].name,
308 'Description': 308 'Description':
309 self.__getShortDescription(dict[name].description), 309 self.__getShortDescription(dict[name].description),
310 'Deprecated': 310 'Deprecated':
311 self.__checkDeprecated(dict[name].description) and \ 311 self.__checkDeprecated(dict[name].description) and
312 self.listEntryDeprecatedTemplate or "", 312 self.listEntryDeprecatedTemplate or "",
313 })) 313 }))
314 if kwSuffix: 314 if kwSuffix:
315 n = "{0} ({1})".format(name, kwSuffix) 315 n = "{0} ({1})".format(name, kwSuffix)
316 else: 316 else:
317 n = "{0}".format(name) 317 n = "{0}".format(name)
318 self.keywords.append((n, "#{0}".format(name))) 318 self.keywords.append((n, "#{0}".format(name)))
330 if class_ is not None: 330 if class_ is not None:
331 scope = class_ 331 scope = class_
332 else: 332 else:
333 scope = self.module 333 scope = self.module
334 attrNames = sorted([attr for attr in scope.globals.keys() 334 attrNames = sorted([attr for attr in scope.globals.keys()
335 if not scope.globals[attr].isSignal]) 335 if not scope.globals[attr].isSignal])
336 if attrNames: 336 if attrNames:
337 s = ''.join( 337 s = ''.join(
338 [self.listEntrySimpleTemplate.format(**{'Name': name}) \ 338 [self.listEntrySimpleTemplate.format(**{'Name': name})
339 for name in attrNames]) 339 for name in attrNames])
340 else: 340 else:
341 s = self.listEntryNoneTemplate 341 s = self.listEntryNoneTemplate
342 return self.listTemplate.format(**{ \ 342 return self.listTemplate.format(**{'Entries': s})
343 'Entries': s,
344 })
345 343
346 def __genClassListSection(self): 344 def __genClassListSection(self):
347 """ 345 """
348 Private method to generate the section listing all classes of the 346 Private method to generate the section listing all classes of the
349 module. 347 module.
354 if names: 352 if names:
355 self.empty = False 353 self.empty = False
356 s = self.__genListSection(names, self.module.classes) 354 s = self.__genListSection(names, self.module.classes)
357 else: 355 else:
358 s = self.listEntryNoneTemplate 356 s = self.listEntryNoneTemplate
359 return self.listTemplate.format(**{ \ 357 return self.listTemplate.format(**{'Entries': s})
360 'Entries': s,
361 })
362 358
363 def __genRbModulesListSection(self): 359 def __genRbModulesListSection(self):
364 """ 360 """
365 Private method to generate the section listing all modules of the file 361 Private method to generate the section listing all modules of the file
366 (Ruby only). 362 (Ruby only).
371 if names: 367 if names:
372 self.empty = False 368 self.empty = False
373 s = self.__genListSection(names, self.module.modules) 369 s = self.__genListSection(names, self.module.modules)
374 else: 370 else:
375 s = self.listEntryNoneTemplate 371 s = self.listEntryNoneTemplate
376 return self.listTemplate.format(**{ \ 372 return self.listTemplate.format(**{'Entries': s})
377 'Entries': s,
378 })
379 373
380 def __genFunctionListSection(self): 374 def __genFunctionListSection(self):
381 """ 375 """
382 Private method to generate the section listing all functions of the 376 Private method to generate the section listing all functions of the
383 module. 377 module.
388 if names: 382 if names:
389 self.empty = False 383 self.empty = False
390 s = self.__genListSection(names, self.module.functions) 384 s = self.__genListSection(names, self.module.functions)
391 else: 385 else:
392 s = self.listEntryNoneTemplate 386 s = self.listEntryNoneTemplate
393 return self.listTemplate.format(**{ \ 387 return self.listTemplate.format(**{'Entries': s})
394 'Entries': s,
395 })
396 388
397 def __genClassesSection(self): 389 def __genClassesSection(self):
398 """ 390 """
399 Private method to generate the document section with details about 391 Private method to generate the document section with details about
400 classes. 392 classes.
418 self.__genMethodSection(_class, className, Function.General) 410 self.__genMethodSection(_class, className, Function.General)
419 staticMethList, staticMethBodies = \ 411 staticMethList, staticMethBodies = \
420 self.__genMethodSection(_class, className, Function.Static) 412 self.__genMethodSection(_class, className, Function.Static)
421 413
422 try: 414 try:
423 clsBody = self.classTemplate.format(**{ \ 415 clsBody = self.classTemplate.format(
424 'Anchor': className, 416 **{'Anchor': className,
425 'Class': _class.name, 417 'Class': _class.name,
426 'ClassSuper': supers, 418 'ClassSuper': supers,
427 'ClassDescription': 419 'ClassDescription':
428 self.__formatDescription(_class.description), 420 self.__formatDescription(_class.description),
429 'GlobalsList': globalsList, 421 'GlobalsList': globalsList,
430 'ClassMethodList': classMethList, 422 'ClassMethodList': classMethList,
431 'MethodList': methList, 423 'MethodList': methList,
432 'StaticMethodList': staticMethList, 424 'StaticMethodList': staticMethList,
433 'MethodDetails': 425 'MethodDetails':
434 classMethBodies + methBodies + staticMethBodies, 426 classMethBodies + methBodies + staticMethBodies,
435 }) 427 })
436 except TagError as e: 428 except TagError as e:
437 sys.stderr.write( 429 sys.stderr.write(
438 "Error in tags of description of class {0}.\n".format( 430 "Error in tags of description of class {0}.\n".format(
439 className)) 431 className))
440 sys.stderr.write("{0}\n".format(e)) 432 sys.stderr.write("{0}\n".format(e))
441 clsBody = "" 433 clsBody = ""
442 434
443 classes.append(clsBody) 435 classes.append(clsBody)
444 436
458 @return methods list section (string) 450 @return methods list section (string)
459 """ 451 """
460 lst = [] 452 lst = []
461 if includeInit: 453 if includeInit:
462 try: 454 try:
463 lst.append(self.listEntryTemplate.format(**{ \ 455 lst.append(self.listEntryTemplate.format(
464 'Link': "{0}.{1}".format(className, '__init__'), 456 **{'Link': "{0}.{1}".format(className, '__init__'),
465 'Name': clsName, 457 'Name': clsName,
466 'Description': self.__getShortDescription( 458 'Description': self.__getShortDescription(
467 dict['__init__'].description), 459 dict['__init__'].description),
468 'Deprecated': self.__checkDeprecated( 460 'Deprecated': self.__checkDeprecated(
469 dict['__init__'].description) and \ 461 dict['__init__'].description) and
470 self.listEntryDeprecatedTemplate or "", 462 self.listEntryDeprecatedTemplate or "",
471 })) 463 }))
472 self.keywords.append( 464 self.keywords.append(
473 ("{0} (Constructor)".format(className), 465 ("{0} (Constructor)".format(className),
474 "#{0}.{1}".format(className, '__init__'))) 466 "#{0}.{1}".format(className, '__init__')))
475 except KeyError: 467 except KeyError:
476 pass 468 pass
477 469
478 for name in names: 470 for name in names:
479 lst.append(self.listEntryTemplate.format(**{ \ 471 lst.append(self.listEntryTemplate.format(
480 'Link': "{0}.{1}".format(className, name), 472 **{'Link': "{0}.{1}".format(className, name),
481 'Name': dict[name].name, 473 'Name': dict[name].name,
482 'Description': 474 'Description':
483 self.__getShortDescription(dict[name].description), 475 self.__getShortDescription(dict[name].description),
484 'Deprecated': 476 'Deprecated':
485 self.__checkDeprecated(dict[name].description) and \ 477 self.__checkDeprecated(dict[name].description) and
486 self.listEntryDeprecatedTemplate or "", 478 self.listEntryDeprecatedTemplate or "",
487 })) 479 }))
488 self.keywords.append(("{0}.{1}".format(className, name), 480 self.keywords.append(("{0}.{1}".format(className, name),
489 "#{0}.{1}".format(className, name))) 481 "#{0}.{1}".format(className, name)))
490 return ''.join(lst) 482 return ''.join(lst)
491 483
492 def __genMethodSection(self, obj, className, filter): 484 def __genMethodSection(self, obj, className, filter):
503 methods = sorted([k for k in obj.methods.keys() 495 methods = sorted([k for k in obj.methods.keys()
504 if obj.methods[k].modifier == filter]) 496 if obj.methods[k].modifier == filter])
505 if '__init__' in methods: 497 if '__init__' in methods:
506 methods.remove('__init__') 498 methods.remove('__init__')
507 try: 499 try:
508 methBody = self.constructorTemplate.format(**{ \ 500 methBody = self.constructorTemplate.format(
509 'Anchor': className, 501 **{'Anchor': className,
510 'Class': obj.name, 502 'Class': obj.name,
511 'Method': '__init__', 503 'Method': '__init__',
512 'MethodDescription': \ 504 'MethodDescription':
513 self.__formatDescription( 505 self.__formatDescription(
514 obj.methods['__init__'].description), 506 obj.methods['__init__'].description),
515 'Params': 507 'Params':
516 ', '.join(obj.methods['__init__'].parameters[1:]), 508 ', '.join(obj.methods['__init__'].parameters[1:]),
517 }) 509 })
518 except TagError as e: 510 except TagError as e:
519 sys.stderr.write( 511 sys.stderr.write(
520 "Error in tags of description of method {0}.{1}.\n".format( 512 "Error in tags of description of method {0}.{1}.\n".format(
521 className, '__init__')) 513 className, '__init__'))
522 sys.stderr.write("{0}\n".format(e)) 514 sys.stderr.write("{0}\n".format(e))
523 methBody = "" 515 methBody = ""
524 methBodies.append(methBody) 516 methBodies.append(methBody)
525 517
526 if filter == Function.Class: 518 if filter == Function.Class:
529 methodClassifier = " (static)" 521 methodClassifier = " (static)"
530 else: 522 else:
531 methodClassifier = "" 523 methodClassifier = ""
532 for method in methods: 524 for method in methods:
533 try: 525 try:
534 methBody = self.methodTemplate.format(**{ \ 526 methBody = self.methodTemplate.format(
535 'Anchor': className, 527 **{'Anchor': className,
536 'Class': obj.name, 528 'Class': obj.name,
537 'Method': obj.methods[method].name, 529 'Method': obj.methods[method].name,
538 'MethodClassifier': methodClassifier, 530 'MethodClassifier': methodClassifier,
539 'MethodDescription': 531 'MethodDescription':
540 self.__formatDescription( 532 self.__formatDescription(
541 obj.methods[method].description), 533 obj.methods[method].description),
542 'Params': ', '.join(obj.methods[method].parameters[1:]), 534 'Params': ', '.join(obj.methods[method].parameters[1:]),
543 }) 535 })
544 except TagError as e: 536 except TagError as e:
545 sys.stderr.write( 537 sys.stderr.write(
546 "Error in tags of description of method {0}.{1}.\n".format( 538 "Error in tags of description of method {0}.{1}.\n".format(
547 className, method)) 539 className, method))
548 sys.stderr.write("{0}\n".format(e)) 540 sys.stderr.write("{0}\n".format(e))
549 methBody = "" 541 methBody = ""
550 methBodies.append(methBody) 542 methBodies.append(methBody)
551 543
552 methList = self.__genMethodsListSection( 544 methList = self.__genMethodsListSection(
553 methods, obj.methods, className, obj.name, 545 methods, obj.methods, className, obj.name,
554 includeInit=filter == Function.General) 546 includeInit=filter == Function.General)
555 547
556 if not methList: 548 if not methList:
557 methList = self.listEntryNoneTemplate 549 methList = self.listEntryNoneTemplate
558 return self.listTemplate.format(**{ \ 550 return (self.listTemplate.format(**{'Entries': methList}),
559 'Entries': methList, 551 ''.join(methBodies))
560 }), ''.join(methBodies)
561 552
562 def __genRbModulesSection(self): 553 def __genRbModulesSection(self):
563 """ 554 """
564 Private method to generate the document section with details about 555 Private method to generate the document section with details about
565 Ruby modules. 556 Ruby modules.
575 rbModule, rbModuleName, Function.General) 566 rbModule, rbModuleName, Function.General)
576 classList, classBodies = self.__genRbModulesClassesSection( 567 classList, classBodies = self.__genRbModulesClassesSection(
577 rbModule, rbModuleName) 568 rbModule, rbModuleName)
578 569
579 try: 570 try:
580 rbmBody = self.rbModuleTemplate.format(**{ \ 571 rbmBody = self.rbModuleTemplate.format(
581 'Anchor': rbModuleName, 572 **{'Anchor': rbModuleName,
582 'Module': rbModule.name, 573 'Module': rbModule.name,
583 'ModuleDescription': 574 'ModuleDescription':
584 self.__formatDescription(rbModule.description), 575 self.__formatDescription(rbModule.description),
585 'GlobalsList': globalsList, 576 'GlobalsList': globalsList,
586 'ClassesList': classList, 577 'ClassesList': classList,
587 'ClassesDetails': classBodies, 578 'ClassesDetails': classBodies,
588 'FunctionsList': methList, 579 'FunctionsList': methList,
589 'FunctionsDetails': methBodies, 580 'FunctionsDetails': methBodies,
590 }) 581 })
591 except TagError as e: 582 except TagError as e:
592 sys.stderr.write( 583 sys.stderr.write(
593 "Error in tags of description of Ruby module {0}.\n" 584 "Error in tags of description of Ruby module {0}.\n"
594 .format(rbModuleName)) 585 .format(rbModuleName))
595 sys.stderr.write("{0}\n".format(e)) 586 sys.stderr.write("{0}\n".format(e))
620 611
621 methList, methBodies = \ 612 methList, methBodies = \
622 self.__genMethodSection(_class, className, Function.General) 613 self.__genMethodSection(_class, className, Function.General)
623 614
624 try: 615 try:
625 clsBody = self.rbModulesClassTemplate.format(**{ \ 616 clsBody = self.rbModulesClassTemplate.format(
626 'Anchor': className, 617 **{'Anchor': className,
627 'Class': _class.name, 618 'Class': _class.name,
628 'ClassSuper': supers, 619 'ClassSuper': supers,
629 'ClassDescription': 620 'ClassDescription':
630 self.__formatDescription(_class.description), 621 self.__formatDescription(_class.description),
631 'MethodList': methList, 622 'MethodList': methList,
632 'MethodDetails': methBodies, 623 'MethodDetails': methBodies,
633 }) 624 })
634 except TagError as e: 625 except TagError as e:
635 sys.stderr.write( 626 sys.stderr.write(
636 "Error in tags of description of class {0}.\n".format( 627 "Error in tags of description of class {0}.\n".format(
637 className)) 628 className))
638 sys.stderr.write("{0}\n".format(e)) 629 sys.stderr.write("{0}\n".format(e))
639 clsBody = "" 630 clsBody = ""
640 631
641 classes.append(clsBody) 632 classes.append(clsBody)
642 633
643 classesList = self.__genRbModulesClassesListSection( 634 classesList = self.__genRbModulesClassesListSection(
644 classNames, obj.classes, modName) 635 classNames, obj.classes, modName)
645 636
646 if not classesList: 637 if not classesList:
647 classesList = self.listEntryNoneTemplate 638 classesList = self.listEntryNoneTemplate
648 return self.listTemplate.format(**{ \ 639 return (self.listTemplate.format(**{'Entries': classesList}),
649 'Entries': classesList, 640 ''.join(classes))
650 }), ''.join(classes)
651 641
652 def __genRbModulesClassesListSection(self, names, dict, moduleName): 642 def __genRbModulesClassesListSection(self, names, dict, moduleName):
653 """ 643 """
654 Private method to generate the classes list section of a Ruby module. 644 Private method to generate the classes list section of a Ruby module.
655 645
659 (string) 649 (string)
660 @return The list section. (string) 650 @return The list section. (string)
661 """ 651 """
662 lst = [] 652 lst = []
663 for name in names: 653 for name in names:
664 lst.append(self.listEntryTemplate.format(**{ \ 654 lst.append(self.listEntryTemplate.format(
665 'Link': "{0}.{1}".format(moduleName, name), 655 **{'Link': "{0}.{1}".format(moduleName, name),
666 'Name': dict[name].name, 656 'Name': dict[name].name,
667 'Description': 657 'Description':
668 self.__getShortDescription(dict[name].description), 658 self.__getShortDescription(dict[name].description),
669 'Deprecated': 659 'Deprecated':
670 self.__checkDeprecated(dict[name].description) and \ 660 self.__checkDeprecated(dict[name].description) and
671 self.listEntryDeprecatedTemplate or "", 661 self.listEntryDeprecatedTemplate or "",
672 })) 662 }))
673 self.keywords.append(("{0}.{1}".format(moduleName, name), 663 self.keywords.append(("{0}.{1}".format(moduleName, name),
674 "#{0}.{1}".format(moduleName, name))) 664 "#{0}.{1}".format(moduleName, name)))
675 return ''.join(lst) 665 return ''.join(lst)
676 666
677 def __genFunctionsSection(self): 667 def __genFunctionsSection(self):
683 """ 673 """
684 funcBodies = [] 674 funcBodies = []
685 funcNames = sorted(list(self.module.functions.keys())) 675 funcNames = sorted(list(self.module.functions.keys()))
686 for funcName in funcNames: 676 for funcName in funcNames:
687 try: 677 try:
688 funcBody = self.functionTemplate.format(**{ \ 678 funcBody = self.functionTemplate.format(
689 'Anchor': funcName, 679 **{'Anchor': funcName,
690 'Function': self.module.functions[funcName].name, 680 'Function': self.module.functions[funcName].name,
691 'FunctionDescription': self.__formatDescription( 681 'FunctionDescription': self.__formatDescription(
692 self.module.functions[funcName].description), 682 self.module.functions[funcName].description),
693 'Params': 683 'Params':
694 ', '.join(self.module.functions[funcName].parameters), 684 ', '.join(self.module.functions[funcName].parameters),
695 }) 685 })
696 except TagError as e: 686 except TagError as e:
697 sys.stderr.write( 687 sys.stderr.write(
698 "Error in tags of description of function {0}.\n".format( 688 "Error in tags of description of function {0}.\n".format(
699 funcName)) 689 funcName))
700 sys.stderr.write("{0}\n".format(e)) 690 sys.stderr.write("{0}\n".format(e))
701 funcBody = "" 691 funcBody = ""
702 692
703 funcBodies.append(funcBody) 693 funcBodies.append(funcBody)
704 694
778 if line == '.': 768 if line == '.':
779 linelist.append("") 769 linelist.append("")
780 else: 770 else:
781 linelist.append(html_uencode(line)) 771 linelist.append(html_uencode(line))
782 else: 772 else:
783 lst.append(self.paragraphTemplate.format(**{ \ 773 lst.append(self.paragraphTemplate.format(
784 'Lines': '\n'.join(linelist) 774 **{'Lines': '\n'.join(linelist)}))
785 }))
786 linelist = [] 775 linelist = []
787 if linelist: 776 if linelist:
788 lst.append(self.paragraphTemplate.format(**{ \ 777 lst.append(self.paragraphTemplate.format(
789 'Lines': '\n'.join(linelist) 778 **{'Lines': '\n'.join(linelist)}))
790 }))
791 return ''.join(lst) 779 return ''.join(lst)
792 780
793 def __genDescriptionListSection(self, dictionary, template): 781 def __genDescriptionListSection(self, dictionary, template):
794 """ 782 """
795 Private method to generate the list section of a description. 783 Private method to generate the list section of a description.
800 @return The list section. (string) 788 @return The list section. (string)
801 """ 789 """
802 lst = [] 790 lst = []
803 keys = sorted(list(dictionary.keys())) 791 keys = sorted(list(dictionary.keys()))
804 for key in keys: 792 for key in keys:
805 lst.append(template.format(**{ \ 793 lst.append(template.format(
806 'Name': key, 794 **{'Name': key,
807 'Description': html_uencode('\n'.join(dictionary[key])), 795 'Description': html_uencode('\n'.join(dictionary[key])),
808 })) 796 }))
809 return ''.join(lst) 797 return ''.join(lst)
810 798
811 def __genParamDescriptionListSection(self, _list, template): 799 def __genParamDescriptionListSection(self, _list, template):
812 """ 800 """
813 Private method to generate the list section of a description. 801 Private method to generate the list section of a description.
817 @param template The template to be used for the list. (string) 805 @param template The template to be used for the list. (string)
818 @return The list section. (string) 806 @return The list section. (string)
819 """ 807 """
820 lst = [] 808 lst = []
821 for name, lines in _list: 809 for name, lines in _list:
822 lst.append(template.format(**{ \ 810 lst.append(template.format(
823 'Name': name, 811 **{'Name': name,
824 'Description': html_uencode('\n'.join(lines)), 812 'Description': html_uencode('\n'.join(lines)),
825 })) 813 }))
826 return ''.join(lst) 814 return ''.join(lst)
827 815
828 def __formatCrossReferenceEntry(self, entry): 816 def __formatCrossReferenceEntry(self, entry):
829 """ 817 """
830 Private method to format a cross reference entry. 818 Private method to format a cross reference entry.
852 reference = path and "{0}.html".format(path) or '' 840 reference = path and "{0}.html".format(path) or ''
853 if anchor: 841 if anchor:
854 reference = "{0}#{1}".format(reference, anchor) 842 reference = "{0}#{1}".format(reference, anchor)
855 entry = 'href="{0}">{1}</a>'.format(reference, label) 843 entry = 'href="{0}">{1}</a>'.format(reference, label)
856 844
857 return self.seeLinkTemplate.format(**{ \ 845 return self.seeLinkTemplate.format(**{'Link': entry})
858 'Link': entry,
859 })
860 846
861 def __genSeeListSection(self, _list, template): 847 def __genSeeListSection(self, _list, template):
862 """ 848 """
863 Private method to generate the "see also" list section of a 849 Private method to generate the "see also" list section of a
864 description. 850 description.
868 @return The list section. (string) 854 @return The list section. (string)
869 """ 855 """
870 lst = [] 856 lst = []
871 for seeEntry in _list: 857 for seeEntry in _list:
872 seeEntryString = ''.join(seeEntry) 858 seeEntryString = ''.join(seeEntry)
873 lst.append(template.format(**{ \ 859 lst.append(template.format(
874 'Link': html_uencode(self.__formatCrossReferenceEntry( 860 **{'Link': html_uencode(self.__formatCrossReferenceEntry(
875 seeEntryString)), 861 seeEntryString)),
876 })) 862 }))
877 return '\n'.join(lst) 863 return '\n'.join(lst)
878 864
879 def __processInlineTags(self, desc): 865 def __processInlineTags(self, desc):
880 """ 866 """
881 Private method to process inline tags. 867 Private method to process inline tags.
980 inTagSection = True 966 inTagSection = True
981 m = _signal(desc, 0) 967 m = _signal(desc, 0)
982 if m is None: 968 if m is None:
983 raise TagError("Wrong format in @signal line.\n") 969 raise TagError("Wrong format in @signal line.\n")
984 signalName = 1 and m.group("SignalName1") \ 970 signalName = 1 and m.group("SignalName1") \
985 or m.group("SignalName2") 971 or m.group("SignalName2")
986 signalDesc = 1 and m.group("SignalDescription1") \ 972 signalDesc = 1 and m.group("SignalDescription1") \
987 or m.group("SignalDescription2") 973 or m.group("SignalDescription2")
988 signalDict[signalName] = [] 974 signalDict[signalName] = []
989 if signalDesc is not None: 975 if signalDesc is not None:
990 signalDict[signalName].append(signalDesc) 976 signalDict[signalName].append(signalDesc)
991 lastItem = signalDict[signalName] 977 lastItem = signalDict[signalName]
992 elif desc.startswith("@event"): 978 elif desc.startswith("@event"):
994 m = _event(desc, 0) 980 m = _event(desc, 0)
995 if m is None: 981 if m is None:
996 raise TagError( 982 raise TagError(
997 "Wrong format in {0} line.\n".format(parts[0])) 983 "Wrong format in {0} line.\n".format(parts[0]))
998 eventName = 1 and m.group("EventName1") \ 984 eventName = 1 and m.group("EventName1") \
999 or m.group("EventName2") 985 or m.group("EventName2")
1000 eventDesc = 1 and m.group("EventDescription1") \ 986 eventDesc = 1 and m.group("EventDescription1") \
1001 or m.group("EventDescription2") 987 or m.group("EventDescription2")
1002 eventDict[eventName] = [] 988 eventDict[eventName] = []
1003 if eventDesc is not None: 989 if eventDesc is not None:
1004 eventDict[eventName].append(eventDesc) 990 eventDict[eventName].append(eventDesc)
1005 lastItem = eventDict[eventName] 991 lastItem = eventDict[eventName]
1006 elif desc.startswith("@deprecated"): 992 elif desc.startswith("@deprecated"):
1050 description = self.__genParagraphs(paragraphs) 1036 description = self.__genParagraphs(paragraphs)
1051 else: 1037 else:
1052 description = "" 1038 description = ""
1053 1039
1054 if paramList: 1040 if paramList:
1055 parameterSect = self.parametersListTemplate.format(**{ \ 1041 parameterSect = self.parametersListTemplate.format(
1056 'Parameters': self.__genParamDescriptionListSection( 1042 **{'Parameters': self.__genParamDescriptionListSection(
1057 paramList, self.parametersListEntryTemplate) 1043 paramList, self.parametersListEntryTemplate)})
1058 })
1059 else: 1044 else:
1060 parameterSect = "" 1045 parameterSect = ""
1061 1046
1062 if returns: 1047 if returns:
1063 returnSect = self.returnsTemplate.format( 1048 returnSect = self.returnsTemplate.format(
1064 html_uencode('\n'.join(returns))) 1049 html_uencode('\n'.join(returns)))
1065 else: 1050 else:
1066 returnSect = "" 1051 returnSect = ""
1067 1052
1068 if exceptionDict: 1053 if exceptionDict:
1069 exceptionSect = self.exceptionsListTemplate.format(**{ \ 1054 exceptionSect = self.exceptionsListTemplate.format(
1070 'Exceptions': self.__genDescriptionListSection( 1055 **{'Exceptions': self.__genDescriptionListSection(
1071 exceptionDict, self.exceptionsListEntryTemplate) 1056 exceptionDict, self.exceptionsListEntryTemplate)})
1072 })
1073 else: 1057 else:
1074 exceptionSect = "" 1058 exceptionSect = ""
1075 1059
1076 if signalDict: 1060 if signalDict:
1077 signalSect = self.signalsListTemplate.format(**{ \ 1061 signalSect = self.signalsListTemplate.format(
1078 'Signals': self.__genDescriptionListSection( 1062 **{'Signals': self.__genDescriptionListSection(
1079 signalDict, self.signalsListEntryTemplate) 1063 signalDict, self.signalsListEntryTemplate)})
1080 })
1081 else: 1064 else:
1082 signalSect = "" 1065 signalSect = ""
1083 1066
1084 if eventDict: 1067 if eventDict:
1085 eventSect = self.eventsListTemplate.format(**{ \ 1068 eventSect = self.eventsListTemplate.format(
1086 'Events': self.__genDescriptionListSection( 1069 **{'Events': self.__genDescriptionListSection(
1087 eventDict, self.eventsListEntryTemplate) 1070 eventDict, self.eventsListEntryTemplate)})
1088 })
1089 else: 1071 else:
1090 eventSect = "" 1072 eventSect = ""
1091 1073
1092 if deprecated: 1074 if deprecated:
1093 deprecatedSect = self.deprecatedTemplate.format(**{ \ 1075 deprecatedSect = self.deprecatedTemplate.format(
1094 'Lines': html_uencode('\n'.join(deprecated)), 1076 **{'Lines': html_uencode('\n'.join(deprecated))})
1095 })
1096 else: 1077 else:
1097 deprecatedSect = "" 1078 deprecatedSect = ""
1098 1079
1099 if authorInfo: 1080 if authorInfo:
1100 authorInfoSect = self.authorInfoTemplate.format(**{ \ 1081 authorInfoSect = self.authorInfoTemplate.format(
1101 'Authors': html_uencode('\n'.join(authorInfo)), 1082 **{'Authors': html_uencode('\n'.join(authorInfo))})
1102 })
1103 else: 1083 else:
1104 authorInfoSect = "" 1084 authorInfoSect = ""
1105 1085
1106 if sinceInfo: 1086 if sinceInfo:
1107 sinceInfoSect = self.sinceInfoTemplate.format(**{ \ 1087 sinceInfoSect = self.sinceInfoTemplate.format(
1108 'Info': html_uencode(sinceInfo[0]), 1088 **{'Info': html_uencode(sinceInfo[0])})
1109 })
1110 else: 1089 else:
1111 sinceInfoSect = "" 1090 sinceInfoSect = ""
1112 1091
1113 if seeList: 1092 if seeList:
1114 seeSect = self.seeListTemplate.format(**{ \ 1093 seeSect = self.seeListTemplate.format(
1115 'Links': self.__genSeeListSection( 1094 **{'Links': self.__genSeeListSection(
1116 seeList, self.seeListEntryTemplate), 1095 seeList, self.seeListEntryTemplate)})
1117 })
1118 else: 1096 else:
1119 seeSect = '' 1097 seeSect = ''
1120 1098
1121 return "{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}".format( 1099 return "{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}".format(
1122 deprecatedSect, description, parameterSect, returnSect, 1100 deprecatedSect, description, parameterSect, returnSect,

eric ide

mercurial