[4f82183] | 1 | """ |
---|
| 2 | This module generates .rst file for each python file under sans.guiframe. |
---|
| 3 | Please run this file to autogenerate .rst files and build sphinx doc. |
---|
| 4 | |
---|
| 5 | """ |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | |
---|
[0d86fecb] | 10 | from __future__ import with_statement |
---|
| 11 | import os.path |
---|
| 12 | |
---|
| 13 | MODULE_TEMPLATE=""".. Autogenerated by genmods.py |
---|
| 14 | |
---|
| 15 | ****************************************************************************** |
---|
| 16 | %(name)s |
---|
| 17 | ****************************************************************************** |
---|
| 18 | |
---|
| 19 | :mod:`%(package)s.%(module)s` |
---|
| 20 | ============================================================================== |
---|
| 21 | |
---|
| 22 | .. automodule:: %(package)s.%(module)s |
---|
| 23 | :members: |
---|
| 24 | :undoc-members: |
---|
| 25 | :inherited-members: |
---|
| 26 | :show-inheritance: |
---|
[bce8148] | 27 | :special-members: |
---|
| 28 | :private-members: |
---|
[0d86fecb] | 29 | |
---|
| 30 | """ |
---|
| 31 | |
---|
| 32 | INDEX_TEMPLATE=""".. Autogenerated by genmods.py |
---|
| 33 | |
---|
| 34 | .. _api-index: |
---|
| 35 | |
---|
| 36 | ############################################################################## |
---|
| 37 | %(package_name)s |
---|
| 38 | ############################################################################## |
---|
| 39 | |
---|
| 40 | .. only:: html |
---|
| 41 | |
---|
| 42 | :Release: |version| |
---|
| 43 | :Date: |today| |
---|
| 44 | |
---|
| 45 | .. toctree:: |
---|
| 46 | |
---|
| 47 | %(rsts)s |
---|
| 48 | """ |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | def genfiles(package, package_name, modules, dir='api'): |
---|
[4f82183] | 52 | """ |
---|
| 53 | Generates .rst file for each python module under sans.guiframe |
---|
| 54 | """ |
---|
[0d86fecb] | 55 | |
---|
| 56 | if not os.path.exists(dir): |
---|
| 57 | os.makedirs(dir) |
---|
| 58 | |
---|
| 59 | for module,name in modules: |
---|
| 60 | with open(os.path.join(dir,module+'.rst'), 'w') as f: |
---|
| 61 | f.write(MODULE_TEMPLATE%locals()) |
---|
| 62 | |
---|
| 63 | rsts = "\n ".join(module+'.rst' for module,name in modules) |
---|
| 64 | with open(os.path.join(dir,'index.rst'),'w') as f: |
---|
| 65 | f.write(INDEX_TEMPLATE%locals()) |
---|
| 66 | |
---|
| 67 | |
---|
[4f82183] | 68 | def create_module_tuple(path): |
---|
| 69 | """ |
---|
| 70 | Create tuples of module and module name |
---|
| 71 | :param path: path of the a package directory |
---|
| 72 | """ |
---|
| 73 | modules = [] |
---|
| 74 | list = os.listdir(path) |
---|
| 75 | for item in list: |
---|
| 76 | toks = os.path.splitext(os.path.basename(item)) |
---|
| 77 | if toks[1] == '.py' and toks[0] not in ["__init__"]: |
---|
| 78 | exec "module = ('%s', '%s')"%(toks[0], toks[0]) |
---|
| 79 | modules.append(module) |
---|
| 80 | return modules |
---|
[0d86fecb] | 81 | |
---|
| 82 | if __name__ == "__main__": |
---|
[4f82183] | 83 | |
---|
| 84 | path = os.path.join('..', '..', 'src', 'sans', 'guiframe') |
---|
| 85 | modules = create_module_tuple(path) |
---|
| 86 | package = 'sans.guiframe' |
---|
| 87 | package_name = 'Reference' |
---|
[0d86fecb] | 88 | genfiles(package, package_name, modules, dir='api') |
---|
[4f82183] | 89 | # build local plugin |
---|
| 90 | for f in os.listdir(path): |
---|
| 91 | if os.path.isdir(os.path.join(path, f)) and not f.startswith('.') \ |
---|
| 92 | and f not in ['images', 'media']: |
---|
| 93 | if f == "local_perspectives": |
---|
| 94 | temp = os.path.join(path, f) |
---|
| 95 | if os.path.isdir(temp): |
---|
| 96 | for tf in os.listdir(temp): |
---|
| 97 | if os.path.isdir(os.path.join(path, f, tf)) \ |
---|
| 98 | and not tf.startswith('.') : |
---|
| 99 | package = "sans.guiframe" |
---|
| 100 | package += ".local_perspectives.%s" % str(tf) |
---|
| 101 | p = os.path.join(path, f, tf) |
---|
| 102 | package_name = 'Local Perspective: %s' % str(tf) |
---|
| 103 | modules = create_module_tuple(p) |
---|
| 104 | dir = os.path.join("api", "local_perspectives", tf) |
---|
| 105 | genfiles(package, package_name, modules, dir=dir) |
---|
| 106 | |
---|
[0d86fecb] | 107 | print "Sphinx: generate .rst files complete..." |
---|
| 108 | |
---|