[PATCH 8/9] sb: Add HTML generation to formatter class

Sebastian Huber sebastian.huber at embedded-brains.de
Mon Dec 8 06:48:51 UTC 2014


---
 source-builder/sb/reports.py | 68 ++++++++++++++++++--------------------------
 1 file changed, 28 insertions(+), 40 deletions(-)

diff --git a/source-builder/sb/reports.py b/source-builder/sb/reports.py
index 0cad3ce..8b8a5c1 100644
--- a/source-builder/sb/reports.py
+++ b/source-builder/sb/reports.py
@@ -148,6 +148,9 @@ class formatter(object):
                 c.line('       %s' % (h))
         return c.get()
 
+    def post_process(self, out):
+        return out
+
 class asciidoc_formatter(formatter):
     def format(self):
         return 'asciidoc'
@@ -261,12 +264,34 @@ class asciidoc_formatter(formatter):
         return c.get()
 
 class html_formatter(asciidoc_formatter):
+    def __init__(self):
+        super(html_formatter, self).__init__()
+        try:
+            import asciidocapi
+        except:
+            raise error.general('installation error: no asciidocapi found')
+        asciidoc_py = _make_path(self.sbpath, options.basepath, 'asciidoc', 'asciidoc.py')
+        try:
+            self.asciidoc = asciidocapi.AsciiDocAPI(asciidoc_py)
+        except:
+            raise error.general('application error: asciidocapi failed')
+
     def format(self):
         return 'html'
 
     def ext(self):
         return '.html'
 
+    def post_process(self, out):
+        import StringIO
+        infile = StringIO.StringIO(out)
+        outfile = StringIO.StringIO()
+        self.asciidoc.execute(infile, outfile)
+        out = outfile.getvalue()
+        infile.close()
+        outfile.close()
+        return out
+
 class text_formatter(formatter):
     def __init__(self):
         super(text_formatter, self).__init__()
@@ -454,7 +479,6 @@ class report:
 
     def __init__(self, formatter, _configs, opts, macros = None):
         self.formatter = formatter
-        self.format = formatter.format()
         self.configs = _configs
         self.opts = opts
         if macros is None:
@@ -465,40 +489,14 @@ class report:
         self.formatter.set_sbpath(self.sbpath)
         self.bset_nesting = 0
         self.out = ''
-        self.asciidoc = None
-        if self.is_ini():
-            self.cini = ';'
-        else:
-            self.cini = ''
         self.tree = {}
         self.files = { 'buildsets':[], 'configs':[] }
 
     def output(self, text):
         self.out += text + '\n'
 
-    def is_text(self):
-        return self.format == 'text'
-
-    def is_asciidoc(self):
-        return self.format == 'asciidoc' or self.format == 'html'
-
-    def is_html(self):
-        return self.format == 'html'
-
     def is_ini(self):
-        return self.format == 'ini'
-
-    def setup(self):
-        if self.is_html():
-            try:
-                import asciidocapi
-            except:
-                raise error.general('installation error: no asciidocapi found')
-            asciidoc_py = _make_path(self.sbpath, options.basepath, 'asciidoc', 'asciidoc.py')
-            try:
-                self.asciidoc = asciidocapi.AsciiDocAPI(asciidoc_py)
-            except:
-                raise error.general('application error: asciidocapi failed')
+        return self.formatter.format() == 'ini'
 
     def header(self):
         pass
@@ -709,17 +707,8 @@ class report:
             self.generate_ini_node(_tree_name(node), self.tree[node])
 
     def write(self, name):
-        if self.is_html():
-            if self.asciidoc is None:
-                raise error.general('asciidoc not initialised')
-            import StringIO
-            infile = StringIO.StringIO(self.out)
-            outfile = StringIO.StringIO()
-            self.asciidoc.execute(infile, outfile)
-            self.out = outfile.getvalue()
-            infile.close()
-            outfile.close()
-        elif self.is_ini():
+        self.out = self.formatter.post_process(self.out)
+        if self.is_ini():
             self.generate_ini()
         if name is not None:
             try:
@@ -754,7 +743,6 @@ class report:
         self.bset_nesting -= 1
 
     def create(self, inname, outname = None, intro_text = None):
-        self.setup()
         self.introduction(inname, intro_text)
         self.generate(inname)
         self.epilogue(inname)
-- 
1.8.4.5




More information about the devel mailing list