[PATCH 6 of 6] gendoc: automatically create help for default extensions

Erik Zielke ez at aragost.com
Mon Oct 18 07:54:07 CDT 2010


# HG changeset patch
# User Erik Zielke <ez at aragost.com>
# Date 1287406401 -7200
# Node ID 9cbe3419825fdc15e83c83073cbcdb2713b800ef
# Parent  bc4f8b25cbbf1de33ba54dec5e662411086e9489
gendoc: automatically create help for default extensions.

Creates help for extensions by extracting doc strings from the extension module
and its commands.

diff -r bc4f8b25cbbf -r 9cbe3419825f doc/gendoc.py
--- a/doc/gendoc.py	Mon Oct 18 14:52:29 2010 +0200
+++ b/doc/gendoc.py	Mon Oct 18 14:53:21 2010 +0200
@@ -8,6 +8,7 @@
 from mercurial.commands import table, globalopts
 from mercurial.i18n import _
 from mercurial.help import helptable
+from mercurial import extensions
 
 def get_desc(docstr):
     if not docstr:
@@ -66,6 +67,10 @@
         ui.write("%s\n%s\n\n" % (s, "-" * encoding.colwidth(s)))
     def subsection(s):
         ui.write("%s\n%s\n\n" % (s, '"' * encoding.colwidth(s)))
+    def subsubsection(s):
+        ui.write("%s\n%s\n\n" % (s, "." * encoding.colwidth(s)))
+    def subsubsubsection(s):
+        ui.write("%s\n%s\n\n" % (s, "#" * encoding.colwidth(s)))
 
     # print options
     section(_("Options"))
@@ -74,7 +79,7 @@
 
     # print cmds
     section(_("Commands"))
-    commandprinter(ui, table)
+    commandprinter(ui, table, subsection)
 
     # print topics
     for names, sec, doc in helptable:
@@ -87,7 +92,25 @@
         ui.write(doc)
         ui.write("\n")
 
-def commandprinter(ui, cmdtable):
+    section(_("Extensions"))
+    ui.write("""
+
+.. contents::
+   :local:
+   :depth: 1
+
+""")
+
+    for extensionname in sorted(allextensionnames()):
+        mod = extensions.load(None, extensionname, None)
+        subsection(extensionname)
+        ui.write("%s\n\n" % mod.__doc__)
+        if hasattr(mod, 'cmdtable'):
+            subsubsection(_('Commands'))
+            commandprinter(ui, getattr(mod, 'cmdtable', None), subsubsubsection)
+
+
+def commandprinter(ui, cmdtable, cmdlevel):
     h = {}
     for c, attr in cmdtable.items():
         f = c.split("|")[0]
@@ -101,9 +124,13 @@
             continue
         d = get_cmd(h[f], cmdtable)
         # synopsis
-        ui.write(".. _%s:\n\n" % d['cmd'])
-        ui.write("``%s``\n" % d['synopsis'].replace("hg ","", 1))
-        ui.write("\n")
+        cmdlevel(d['cmd'])
+
+        synopsislines = d['synopsis'].splitlines()
+        ui.write("::\n\n")
+        for line in synopsislines:
+            ui.write("   %s\n" % line.replace("hg ","", 1))
+        ui.write('\n')
         # description
         ui.write("%s\n\n" % d['desc'][1])
         # options
@@ -123,5 +150,18 @@
             ui.write(_("    aliases: %s\n\n") % " ".join(d['aliases']))
 
 
+def allextensionnames():
+    extensionnames = []
+
+    def getnames(dictandlen):
+        dict, len = dictandlen
+        extensionnames.extend(dict.keys())
+
+    getnames(extensions.enabled())
+    getnames(extensions.disabled())
+
+    return extensionnames
+
+
 if __name__ == "__main__":
     show_doc(sys.stdout)
diff -r bc4f8b25cbbf -r 9cbe3419825f doc/hg.1.txt
--- a/doc/hg.1.txt	Mon Oct 18 14:52:29 2010 +0200
+++ b/doc/hg.1.txt	Mon Oct 18 14:53:21 2010 +0200
@@ -14,7 +14,7 @@
 .. contents::
    :backlinks: top
    :class: htmlonly
-
+   :depth: 1
 
 Synopsis
 --------
diff -r bc4f8b25cbbf -r 9cbe3419825f doc/style.css
--- a/doc/style.css	Mon Oct 18 14:52:29 2010 +0200
+++ b/doc/style.css	Mon Oct 18 14:53:21 2010 +0200
@@ -35,16 +35,18 @@
 table.docinfo { max-width: 72%; }
 
 /* headings */
-h1, h2, .topic-title, .admonition-title {
+h1, h2, h3, h4, .topic-title, .admonition-title {
     font-family: "MgOpen Cosmetica", "Lucida Sans Unicode", sans-serif;
     font-weight: normal;
 }
-h1, h2, .topic-title, .admonition-title {
+h1, h2, h3, h4, .topic-title, .admonition-title {
     margin: 1em 0 0.5em;
 }
 h1.title { font-size: 300%; }
 h2.subtitle, h1 { font-size: 200%; }
 h2, .topic-title, .admonition-title { font-size: 140%; }
+h3 { font-size: 125%; }
+h4 { font-size: 115%; }
 
 /* subtitle starts with lowercase in man pages, but not in HTML */
 h2.subtitle:first-letter { text-transform: uppercase; }
@@ -299,3 +301,4 @@
 ul.auto-toc {
     list-style-type: none;
 }
+


More information about the Mercurial-devel mailing list