[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30717] branches/soc-2010-nexyon/intern/ audaspace/Python: Audaspace Python API documentation generator.
Joerg Mueller
nexyon at gmail.com
Sun Jul 25 14:57:04 CEST 2010
Revision: 30717
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30717
Author: nexyon
Date: 2010-07-25 14:57:03 +0200 (Sun, 25 Jul 2010)
Log Message:
-----------
Audaspace Python API documentation generator.
* See the README on how to create the docs.
* This commit includes two external python libraries: mako and markupsafe in their python3 version
Added Paths:
-----------
branches/soc-2010-nexyon/intern/audaspace/Python/doc/
branches/soc-2010-nexyon/intern/audaspace/Python/doc/README
branches/soc-2010-nexyon/intern/audaspace/Python/doc/createdocs.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/doctree.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/examples/
branches/soc-2010-nexyon/intern/audaspace/Python/doc/examples/aud.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/examples/tetris.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/
branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/LICENSE
branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/__init__.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/_ast_util.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/ast.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/cache.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/codegen.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/exceptions.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/ext/
branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/ext/__init__.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/ext/autohandler.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/ext/babelplugin.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/ext/preprocessors.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/ext/pygmentplugin.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/ext/turbogears.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/filters.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/lexer.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/lookup.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/parsetree.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/pygen.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/pyparser.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/runtime.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/template.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/util.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/markupsafe/
branches/soc-2010-nexyon/intern/audaspace/Python/doc/markupsafe/AUTHORS
branches/soc-2010-nexyon/intern/audaspace/Python/doc/markupsafe/LICENSE
branches/soc-2010-nexyon/intern/audaspace/Python/doc/markupsafe/__init__.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/markupsafe/_constants.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/markupsafe/_native.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/markupsafe/_speedups.c
branches/soc-2010-nexyon/intern/audaspace/Python/doc/markupsafe/_speedups.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/markupsafe/_speedups.so
branches/soc-2010-nexyon/intern/audaspace/Python/doc/markupsafe/tests.py
branches/soc-2010-nexyon/intern/audaspace/Python/doc/templates/
branches/soc-2010-nexyon/intern/audaspace/Python/doc/templates/Class.rst
branches/soc-2010-nexyon/intern/audaspace/Python/doc/templates/Code.rst
branches/soc-2010-nexyon/intern/audaspace/Python/doc/templates/Module.rst
branches/soc-2010-nexyon/intern/audaspace/Python/doc/util.py
Added: branches/soc-2010-nexyon/intern/audaspace/Python/doc/README
===================================================================
--- branches/soc-2010-nexyon/intern/audaspace/Python/doc/README (rev 0)
+++ branches/soc-2010-nexyon/intern/audaspace/Python/doc/README 2010-07-25 12:57:03 UTC (rev 30717)
@@ -0,0 +1,11 @@
+This is a temporary solution:
+
+Run blender in this directory starting the createdocs.py script:
+
+ pathtoblender/blender -b -P createdocs.py
+
+This will create a folder named out with rst files in it, copy those into the folder
+
+ blender/source/blender/python/doc/sphinx-in/
+
+which is created by sphinx_doc_gen.py and then run sphinx.
Added: branches/soc-2010-nexyon/intern/audaspace/Python/doc/createdocs.py
===================================================================
--- branches/soc-2010-nexyon/intern/audaspace/Python/doc/createdocs.py (rev 0)
+++ branches/soc-2010-nexyon/intern/audaspace/Python/doc/createdocs.py 2010-07-25 12:57:03 UTC (rev 30717)
@@ -0,0 +1,43 @@
+# -*- coding: utf-8 -*-
+# ##### 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+import sys
+import os
+
+sys.path.append('.')
+
+import aud
+import doctree
+
+from mako.template import Template
+from mako.lookup import TemplateLookup
+
+module = doctree.Module('aud', aud)
+
+lookup = TemplateLookup(directories = ['templates'])
+class_tpl = lookup.get_template('Class.rst')
+module_tpl = lookup.get_template('Module.rst')
+
+if 'out' not in os.listdir('.'):
+ os.mkdir('out')
+
+open('out/'+module.title+'.rst', 'w').write(module_tpl.render(module=module))
+
+for _class in module.classes:
+ open('out/'+module.title+'.'+_class.title+'.rst', 'w').write(class_tpl.render(module=module, _class=_class))
Added: branches/soc-2010-nexyon/intern/audaspace/Python/doc/doctree.py
===================================================================
--- branches/soc-2010-nexyon/intern/audaspace/Python/doc/doctree.py (rev 0)
+++ branches/soc-2010-nexyon/intern/audaspace/Python/doc/doctree.py 2010-07-25 12:57:03 UTC (rev 30717)
@@ -0,0 +1,124 @@
+# -*- coding: utf-8 -*-
+# ##### 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+import inspect
+
+class Util:
+ @staticmethod
+ def isExternal(name):
+ return not name.startswith('_') and name != 'error'
+
+ @staticmethod
+ def getDoc(obj, doc = None):
+ if doc:
+ return doc
+ elif obj.__doc__:
+ return obj.__doc__
+ else:
+ print('Undocumented object: '+repr(obj))
+ return 'Undocumented!'
+
+class Module:
+ def __init__(self, title, module):
+ self.title = title
+ self.module = module
+ self.doc = Util.getDoc(module)
+
+ self.classes = []
+ self.dates = []
+ self.functions = []
+
+ for name in (mem for mem in sorted(dir(module)) if Util.isExternal(mem)):
+ obj = getattr(module, name)
+
+ if inspect.isbuiltin(obj):
+ self.functions.append(Function(name, obj))
+ elif inspect.isclass(obj):
+ self.classes.append(Class(name, obj, self))
+ elif inspect.ismethoddescriptor(obj):
+ self.dates.append(Data(name, obj))
+ elif isinstance(obj, (bool, int, float, str, tuple)):
+ self.dates.append(Data(name, obj, "Constant value: {0}".format(repr(obj))))
+ else:
+ raise TypeError(name)
+
+ def __repr__(self):
+ return repr({'title': self.title, 'doc': self.doc, 'functions': repr(self.functions), 'dates': repr(self.dates), 'classes': repr(self.classes)})
+
+class Class:
+ def __init__(self, title, _class, module):
+ self.title = title
+ self._class = _class
+ self.doc = Util.getDoc(_class)
+ self.module = module
+
+ self.methods = []
+ self.attributes = []
+ self.dates = []
+
+ for name in (mem for mem in sorted(dir(_class)) if Util.isExternal(mem)):
+ obj = getattr(_class, name)
+
+ if inspect.isbuiltin(obj) or inspect.ismethod(obj) or inspect.ismethoddescriptor(obj):
+ self.methods.append(Method(name, obj))
+ elif inspect.isdatadescriptor(obj):
+ self.attributes.append(Attribute(name, obj))
+ elif isinstance(obj, (bool, int, float, str, tuple)):
+ self.dates.append(Data(name, obj, "Constant value: {0}".format(repr(obj))))
+ else:
+ raise TypeError(name)
+
+ def __repr__(self):
+ return repr({'title': self.title, 'doc': self.doc, 'methods': repr(self.methods), 'dates': repr(self.dates), 'attributes': repr(self.attributes)})
+
+class Data:
+ def __init__(self, title, data, doc = None):
+ self.title = title
+ self.data = data
+ self.doc = Util.getDoc(data, doc)
+
+ def __repr__(self):
+ return repr({'title': self.title, 'doc': self.doc})
+
+class Function:
+ def __init__(self, title, function):
+ self.title = title
+ self.function = function
+ self.doc = Util.getDoc(function)
+
+ def __repr__(self):
+ return repr({'title': self.title, 'doc': self.doc})
+
+class Method:
+ def __init__(self, title, method):
+ self.title = title
+ self.method = method
+ self.doc = Util.getDoc(method)
+
+ def __repr__(self):
+ return repr({'title': self.title, 'doc': self.doc})
+
+class Attribute:
+ def __init__(self, title, attribute):
+ self.title = title
+ self.attribute = attribute
+ self.doc = Util.getDoc(attribute)
+
+ def __repr__(self):
+ return repr({'title': self.title, 'doc': self.doc})
Added: branches/soc-2010-nexyon/intern/audaspace/Python/doc/examples/aud.py
===================================================================
--- branches/soc-2010-nexyon/intern/audaspace/Python/doc/examples/aud.py (rev 0)
+++ branches/soc-2010-nexyon/intern/audaspace/Python/doc/examples/aud.py 2010-07-25 12:57:03 UTC (rev 30717)
@@ -0,0 +1,8 @@
+import aud
+device = aud.get_c_device()
+s = aud.Sound('music.ogg')
+c = device.play(s)
+buffered = aud.Sound.buffer(s)
+c2 = device.play(buffered)
+c.stop()
+c2.stop()
Added: branches/soc-2010-nexyon/intern/audaspace/Python/doc/examples/tetris.py
===================================================================
--- branches/soc-2010-nexyon/intern/audaspace/Python/doc/examples/tetris.py (rev 0)
+++ branches/soc-2010-nexyon/intern/audaspace/Python/doc/examples/tetris.py 2010-07-25 12:57:03 UTC (rev 30717)
@@ -0,0 +1,60 @@
+import aud
+import math
+
+def parseNotes(notes, bpm, basefreq, notechars = "XXXCXDXEFXGXAXHcXdXefXgXaXhp"):
+ pos = 0
+ sound = None
+ fadelength = 60/bpm/10
+ halfchars = "#b"
+ durationchars = "2345678"
+
+ while pos < len(notes):
+ char = notes[pos]
+ mod = None
+ dur = 1
+ pos += 1
+ while pos < len(notes) and notes[pos] not in notechars:
+ if notes[pos] in halfchars:
+ mod = notes[pos]
+ elif notes[pos] in durationchars:
+ dur = notes[pos]
+ pos += 1
+
+ freq = notechars.find(char)
+ if mod == '#':
+ freq += 1
+ elif mod == 'b':
+ freq -= 1
+
+ freq = math.pow(2, freq/12)*basefreq
+ length = float(dur)*60/bpm
+
+ snd = aud.Sound.sine(freq)
+ if char == 'p':
+ snd = aud.Sound.volume(snd, 0)
+ else:
+ snd = aud.Sound.square(snd, 0)
+ snd = aud.Sound.limiter(snd, 0, length)
+ snd = aud.Sound.fadein(snd, 0, fadelength)
+ snd = aud.Sound.fadeout(snd, length - fadelength, fadelength)
+
+ if sound:
+ sound = aud.Sound.double(sound, snd)
+ else:
+ sound = snd
+ return sound
+
+def tetris(bpm = 300, freq = 220):
+ notes = "e2Hcd2cH A2Ace2dc H3cd2e2 c2A2A4 pd2fa2gf e3ce2dc H2Hcd2e2 c2A2A2p2"
+ s11 = parseNotes(notes, bpm, freq)
+
+ notes = "e4c4 d4H4 c4A4 G#4p4 e4c4 d4H4 A2c2a4 g#4p4"
+ s12 = parseNotes(notes, bpm, freq)
+
+ notes = "EeEeEeEe AaAaAaAa AbabAbabAbabAbab AaAaAAHC DdDdDdDd CcCcCcCc HhHhHhHh AaAaA2p2"
+ s21 = parseNotes(notes, bpm, freq, notechars = "AXHCXDXEFXGXaXhcXdXefXgXp")
+
+ notes = "aeaeaeae g#dg#dg#dg#d aeaeaeae g#dg#dg#2p2 aeaeaeae g#dg#dg#dg#d aeaeaeae g#dg#dg#2p2"
+ s22 = parseNotes(notes, bpm, freq/2)
+
+ return aud.Sound.superpose(aud.Sound.volume(aud.Sound.double(aud.Sound.double(s11, s12), s11), 0.5), aud.Sound.volume(aud.Sound.double(aud.Sound.double(s21, s22), s21), 0.3))
Added: branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/LICENSE
===================================================================
--- branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/LICENSE (rev 0)
+++ branches/soc-2010-nexyon/intern/audaspace/Python/doc/mako/LICENSE 2010-07-25 12:57:03 UTC (rev 30717)
@@ -0,0 +1,20 @@
+This is the MIT license: http://www.opensource.org/licenses/mit-license.php
+
+Copyright (C) 2006, 2007, 2008, 2009, 2010 Michael Bayer and contributors.
+Mako is a trademark of Michael Bayer.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this
+software and associated documentation files (the "Software"), to deal in the Software
+without restriction, including without limitation the rights to use, copy, modify, merge,
+publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
+to whom the Software is furnished to do so, subject to the following conditions:
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list