summaryrefslogtreecommitdiff
path: root/giscanner/sectionparser.py
diff options
context:
space:
mode:
authorJasper St. Pierre <jstpierre@mecheye.net>2013-03-28 16:14:48 -0400
committerJasper St. Pierre <jstpierre@mecheye.net>2013-06-16 01:19:36 -0400
commit3ec52d6198a8afb6360bf9985cee03cdcbfdfb63 (patch)
tree0ffdf5317d9dff40e7be23e6abe57de2a6fd0bb0 /giscanner/sectionparser.py
parentf0b95de7d521144113ff7ef7ff5946e35c90aae1 (diff)
downloadgobject-introspection-3ec52d6198a8afb6360bf9985cee03cdcbfdfb63.tar.gz
giscanner: Add a simple automatic sections file generator
This is a very basic sections file generator, and isn't too smart. It's simply intended to be a base to build docs on, and will be used if the user doesn't provide a sections file when calling g-ir-doc-tool, for convenience purposes. https://bugzilla.gnome.org/show_bug.cgi?id=699856
Diffstat (limited to 'giscanner/sectionparser.py')
-rw-r--r--giscanner/sectionparser.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/giscanner/sectionparser.py b/giscanner/sectionparser.py
index 61763e45..6a6a231c 100644
--- a/giscanner/sectionparser.py
+++ b/giscanner/sectionparser.py
@@ -18,6 +18,8 @@
#
import re
+from . import ast
+from .utils import to_underscores
class SectionsFile(object):
@@ -89,3 +91,60 @@ def parse_sections_file(lines):
current_subsection.symbols.append(line)
return SectionsFile(sections)
+
+def write_sections_file(f, sections_file):
+ for section in sections_file.sections:
+ f.write("\n<SECTION>\n")
+ if section.file is not None:
+ f.write("<FILE>%s</FILE>\n" % (section.file, ))
+ if section.title is not None:
+ f.write("<TITLE>%s</TITLE>\n" % (section.title, ))
+ if section.includes is not None:
+ f.write("<INCLUDE>%s</INCLUDE>\n" % (section.includes, ))
+
+ is_first_subsection = True
+ for subsection in section.subsections:
+ if subsection.name is not None:
+ f.write("<SUBSECTION %s>\n" % (subsection.name, ))
+ elif not is_first_subsection:
+ f.write("\n<SUBSECTION>\n")
+
+ is_first_subsection = False
+
+ for symbol in subsection.symbols:
+ f.write(symbol + "\n")
+
+def generate_sections_file(transformer):
+ ns = transformer.namespace
+
+ sections = []
+
+ def new_section(file_, title):
+ section = Section()
+ section.file = file_
+ section.title = title
+ section.subsections.append(Subsection(None))
+ sections.append(section)
+ return section
+
+ def append_symbol(section, sym):
+ section.subsections[0].symbols.append(sym)
+
+ general_section = new_section("main", "Main")
+
+ for node in ns.itervalues():
+ if isinstance(node, ast.Function):
+ append_symbol(general_section, node.symbol)
+ elif isinstance(node, (ast.Class, ast.Interface)):
+ gtype_name = node.gtype_name
+ file_name = to_underscores(gtype_name).replace('_', '-').lower()
+ section = new_section(file_name, gtype_name)
+ append_symbol(section, gtype_name)
+ append_symbol(section, node.glib_type_struct.target_giname.replace('.', ''))
+
+ for meth in node.methods:
+ append_symbol(section, meth.symbol)
+ for meth in node.static_methods:
+ append_symbol(section, meth.symbol)
+
+ return SectionsFile(sections)