[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32771] trunk/blender/doc: == blender file format ==

Luca Bonavita mindrones at gmail.com
Sat Oct 30 15:25:24 CEST 2010


Revision: 32771
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32771
Author:   mindrones
Date:     2010-10-30 15:25:24 +0200 (Sat, 30 Oct 2010)

Log Message:
-----------
== blender file format ==

Hello, from the bconf 2010 from Jeroen and Luca. Our first combined commit :)

Automatically create sdna documentations from Trunk.

Usage: 
        blender2.5 -b -P BlendFileDnaExporter_25.py [-- [options]]
Options:
        --dna-keep-blend:      doesn't delete the produced blend file DNA export to html
        --dna-debug:           sets the logging level to DEBUG (lots of additional info)
        --dna-versioned'       saves version informations in the html and blend filenames
        --dna-overwrite-css'   overwrite dna.css, useful when modifying css in the script
Examples:
        default:       % blender2.5 -b -P BlendFileDnaExporter_25.py
        with options:  % blender2.5 -b -P BlendFileDnaExporter_25.py -- --dna-keep-blend --dna-debug

Added Paths:
-----------
    trunk/blender/doc/blender_file_format/
    trunk/blender/doc/blender_file_format/BlendFileDnaExporter_25.py
    trunk/blender/doc/blender_file_format/BlendFileReader.py
    trunk/blender/doc/blender_file_format/mystery_of_the_blend.css
    trunk/blender/doc/blender_file_format/mystery_of_the_blend.html

Added: trunk/blender/doc/blender_file_format/BlendFileDnaExporter_25.py
===================================================================
--- trunk/blender/doc/blender_file_format/BlendFileDnaExporter_25.py	                        (rev 0)
+++ trunk/blender/doc/blender_file_format/BlendFileDnaExporter_25.py	2010-10-30 13:25:24 UTC (rev 32771)
@@ -0,0 +1,477 @@
+#! /usr/bin/env python3
+
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, 
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation, 
+# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+# ***** END GPL LICENCE BLOCK *****
+
+######################################################
+#
+#    Name:
+#        dna.py
+#        
+#    Description:
+#        Creates a browsable DNA output to HTML.
+#        
+#    Author:
+#        Jeroen Bakker
+#        
+#    Version:
+#        v0.1 (12-05-2009) - migration of original source code to python.
+#           Added code to support blender 2.5 branch
+#        v0.2 (25-05-2009) - integrated with BlendFileReader.py
+#        
+#    Input:
+#        blender build executable
+#        
+#    Output:
+#        dna.html
+#        dna.css (will only be created when not existing)
+#
+#    Startup:
+#        ./blender -P BlendFileDnaExporter.py
+#
+#    Process:
+#        1: write blend file with SDNA info
+#        2: read blend header from blend file
+#        3: seek DNA1 file-block
+#        4: read dna record from blend file
+#        5: close and eventually delete temp blend file
+#        6: export dna to html and css
+#        7: quit blender
+#
+######################################################
+
+import struct
+import sys
+import getopt                   # command line arguments handling
+from string import Template     # strings completion
+
+
+# logs
+import logging
+log = logging.getLogger("BlendFileDnaExporter")
+
+if '--dna-debug' in sys.argv:
+    logging.basicConfig(level=logging.DEBUG)
+else:
+    logging.basicConfig(level=logging.INFO)
+
+
+class DNACatalogHTML:
+    '''
+    DNACatalog is a catalog of all information in the DNA1 file-block
+    '''
+
+    def __init__(self, catalog, bpy_module = None):
+        self.Catalog = catalog
+        self.bpy = bpy_module
+    
+    def WriteToHTML(self, handle):
+            
+        dna_html_template = """
+            <!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/html4/loose.dtd>
+            <html>
+            <head>
+                <link rel="stylesheet" type="text/css" href="dna.css" media="screen, print" />
+                <meta http-equiv="Content-Type" content="text/html"; charset="ISO-8859-1" />
+                <title>The mystery of the blend</title>
+            </head>
+            <body>
+                <div class=title>
+                    Blender ${version}<br/>
+                    Internal SDNA structures
+                </div>
+                Architecture: ${bitness} ${endianness}<br/>
+                Build revision: <a href="https://svn.blender.org/svnroot/bf-blender/!svn/bc/${revision}/trunk/">${revision}</a><br/>
+                File format reference: <a href="mystery_of_the_blend.html">The mystery of the blend</a> by Jeroen Bakker<br/>
+                <h1>Index of blender structures</h1>
+                <ul class=multicolumn>
+                    ${structs_list}
+                </ul>
+                ${structs_content}
+            </body>
+            </html>"""
+        
+        header = self.Catalog.Header
+        bpy = self.bpy
+        
+        # ${version} and ${revision}
+        if bpy:
+            version = '.'.join(map(str, bpy.app.version))
+            revision = bpy.app.build_revision[:-1]
+        else:
+            version = str(header.Version)
+            revision = 'Unknown'
+        
+        # ${bitness}
+        if header.PointerSize == 8:
+            bitness = '64 bit'
+        else:
+            bitness = '32 bit'
+
+        # ${endianness}
+        if header.LittleEndianness:
+            endianess= 'Little endianness'
+        else:
+            endianess= 'Big endianness'
+        
+        # ${structs_list}
+        log.debug("Creating structs index")
+        structs_list = ''
+        list_item = '<li class="multicolumn">({0}) <a href="#{1}">{1}</a></li>\n'
+        structureIndex = 0
+        for structure in self.Catalog.Structs:
+            structs_list += list_item.format(structureIndex, structure.Type.Name)
+            structureIndex+=1
+
+        # ${structs_content}
+        log.debug("Creating structs content")
+        structs_content = ''
+        for structure in self.Catalog.Structs:
+            log.debug(structure.Type.Name)
+            structs_content += self.Structure(structure)
+           
+        d = dict(
+            version = version, 
+            revision = revision, 
+            bitness = bitness, 
+            endianness = endianess, 
+            structs_list = structs_list, 
+            structs_content = structs_content
+        )
+
+        dna_html = Template(dna_html_template).substitute(d)
+        dna_html = self.format(dna_html)
+        handle.write(dna_html)
+    
+    def Structure(self, structure):
+        struct_table_template = """
+            <table><a name="${struct_name}"></a>
+                <caption><a href="#${struct_name}">${struct_name}</a></caption>
+                <thead>
+                    <tr>
+                        <th>reference</th>
+                        <th>structure</th>
+                        <th>type</th>
+                        <th>name</th>
+                        <th>offset</th>
+                        <th>size</th>
+                    </tr>
+                </thead>
+                <tbody>
+                ${fields}
+                </tbody>
+            </table>
+            <label>Total size: ${size} bytes</label><br/>
+            <label>(<a href="#top">top</a>)</label><br/>"""
+        
+        d = dict(
+            struct_name = structure.Type.Name, 
+            fields = self.StructureFields(structure, None, 0), 
+            size = str(structure.Type.Size)
+        )
+        
+        struct_table = Template(struct_table_template).substitute(d)
+        return struct_table
+        
+    def StructureFields(self, structure, parentReference, offset):
+        fields = ''
+        for field in structure.Fields:
+            fields += self.StructureField(field, structure, parentReference, offset)
+            offset += field.Size(self.Catalog.Header)
+        return fields
+        
+    def StructureField(self, field, structure, parentReference, offset):
+        structure_field_template = """
+            <tr>
+                <td>${reference}</td>
+                <td>${struct}</td>
+                <td>${type}</td>
+                <td>${name}</td>
+                <td>${offset}</td>
+                <td>${size}</td>
+            </tr>"""
+        
+        if field.Type.Structure == None or field.Name.IsPointer():
+
+            # ${reference}
+            reference = field.Name.AsReference(parentReference)
+
+            # ${struct}
+            if parentReference != None:
+                struct = '<a href="#{0}">{0}</a>'.format(structure.Type.Name)
+            else:
+                struct = structure.Type.Name
+            
+            # ${type}
+            type = field.Type.Name
+            
+            # ${name}
+            name = field.Name.Name
+            
+            # ${offset}
+            # offset already set
+            
+            # ${size}
+            size = field.Size(self.Catalog.Header)
+        
+            d = dict(
+                reference = reference, 
+                struct = struct, 
+                type = type, 
+                name = name, 
+                offset = offset, 
+                size = size
+            )
+            
+            structure_field = Template(structure_field_template).substitute(d)
+        
+        elif field.Type.Structure != None:
+            reference = field.Name.AsReference(parentReference)
+            structure_field = self.StructureFields(field.Type.Structure, reference, offset) 
+
+        return structure_field
+
+    def indent(self, input, dent, startswith = ''):
+        output = ''
+        if dent < 0:
+            for line in input.split('\n'):
+                dent = abs(dent)
+                output += line[dent:] + '\n'   # unindent of a desired amount
+        elif dent == 0:
+            for line in input.split('\n'):
+                output += line.lstrip() + '\n'  # remove indentation completely
+        elif dent > 0:
+            for line in input.split('\n'):
+                output += ' '* dent + line + '\n'
+        return output
+    
+    def format(self, input):
+        diff = {
+            '\n<!DOCTYPE':'<!DOCTYPE', 
+            '\n</ul>'    :'</ul>', 
+            '<a name'         :'\n<a name', 
+            '<tr>\n'     :'<tr>', 
+            '<tr>'       :'  <tr>', 
+            '</th>\n'    :'</th>', 
+            '</td>\n'    :'</td>', 
+            '<tbody>\n'  :'<tbody>'
+        }
+        output = self.indent(input, 0)
+        for key, value in diff.items():
+            output = output.replace(key, value)
+        return output
+
+    def WriteToCSS(self, handle):
+        '''
+        Write the Cascading stylesheet template to the handle
+        It is expected that the handle is a Filehandle
+        '''
+        css = """
+            @CHARSET "ISO-8859-1";
+            
+            body {
+                font-family: verdana;
+                font-size: small;
+            }
+            
+            div.title {
+                font-size: large;
+                text-align: center;
+            }
+            
+            h1 {
+                page-break-before: always;
+            }
+
+            h1, h2 {
+                background-color: #D3D3D3;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list