#!/usr/bin/env python import types from os.path import join from inspect import getsource, getmembers, isclass, isfunction, ismethod, ismodule from importlib import import_module root="./build/api" # autopath from os.path import dirname, abspath, join, normpath import sys HERE = dirname(abspath(__file__)) PATH = normpath(join(HERE, '..', '..')) if PATH not in sys.path: sys.path.insert(1, PATH) htmltmpl = """ {title}
{content}
""" def write_source(name, content): fh = file(join(root, name)+'.html', 'w') fh.write(format_html(name, content)) fh.close() def format_html(title, content): return htmltmpl.format(title=title, content=content) def parse_module(module): module = import_module(module) write_source(module.__name__, getsource(module)) # classes = [(cls, value) for cls, value in getattr(module, '__dict__').items() if value == types.ClassType] classes = getmembers(module, isclass) for name, obj in classes: write_source(module.__name__ + '.' + name, getsource(obj)) # methods = [(meth, value) for meth, value in getattr(obj, '__dict__').items() if type(value) == types.MethodType] methods = getmembers(obj, ismethod) for meth, value in methods: write_source(module.__name__ + '.' + name + '.' + meth, getsource(value)) #functions = [(func, value) for func, value in getattr(module, '__dict__').items() if type(value) == types.FunctionType] functions = getmembers(module, isfunction) for name, obj in functions: write_source(module.__name__ + '.' + name, getsource(obj)) def process_modules(): from glob import glob from os.path import abspath, dirname, normpath, splitext, basename here = abspath(__file__) directory = dirname(here) pyfiles = glob(normpath(join(directory, '..', '*.py'))) for pyf in pyfiles: pyf = splitext(basename(pyf))[0] modname = 'tiramisu.' + pyf if not '__init__' in modname: parse_module(modname) pyfiles = glob(normpath(join(directory, '..', 'test', '*.py'))) for pyf in pyfiles: pyf = splitext(basename(pyf))[0] modname = 'tiramisu.test.' + pyf if not '__init__' in modname: parse_module(modname) process_modules()