""" This module generates .rst file for each python file under sans.guiframe. Please run this file to autogenerate .rst files and build sphinx doc. """ from __future__ import with_statement import os.path MODULE_TEMPLATE=""".. Autogenerated by genmods.py ****************************************************************************** %(name)s ****************************************************************************** :mod:`%(package)s.%(module)s` ============================================================================== .. automodule:: %(package)s.%(module)s :members: :undoc-members: :inherited-members: :show-inheritance: :special-members: :private-members: """ INDEX_TEMPLATE=""".. Autogenerated by genmods.py .. _api-index: ############################################################################## %(package_name)s ############################################################################## .. only:: html :Release: |version| :Date: |today| .. toctree:: %(rsts)s """ def genfiles(package, package_name, modules, dir='api'): """ Generates .rst file for each python module under sans.guiframe """ if not os.path.exists(dir): os.makedirs(dir) for module,name in modules: with open(os.path.join(dir,module+'.rst'), 'w') as f: f.write(MODULE_TEMPLATE%locals()) rsts = "\n ".join(module+'.rst' for module,name in modules) with open(os.path.join(dir,'index.rst'),'w') as f: f.write(INDEX_TEMPLATE%locals()) def create_module_tuple(path): """ Create tuples of module and module name :param path: path of the a package directory """ modules = [] list = os.listdir(path) for item in list: toks = os.path.splitext(os.path.basename(item)) if toks[1] == '.py' and toks[0] not in ["__init__"]: exec "module = ('%s', '%s')"%(toks[0], toks[0]) modules.append(module) return modules if __name__ == "__main__": path = os.path.join('..', '..', 'src', 'sans', 'guiframe') modules = create_module_tuple(path) package = 'sans.guiframe' package_name = 'Reference' genfiles(package, package_name, modules, dir='api') # build local plugin for f in os.listdir(path): if os.path.isdir(os.path.join(path, f)) and not f.startswith('.') \ and f not in ['images', 'media']: if f == "local_perspectives": temp = os.path.join(path, f) if os.path.isdir(temp): for tf in os.listdir(temp): if os.path.isdir(os.path.join(path, f, tf)) \ and not tf.startswith('.') : package = "sans.guiframe" package += ".local_perspectives.%s" % str(tf) p = os.path.join(path, f, tf) package_name = 'Local Perspective: %s' % str(tf) modules = create_module_tuple(p) dir = os.path.join("api", "local_perspectives", tf) genfiles(package, package_name, modules, dir=dir) print "Sphinx: generate .rst files complete..."