[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: |
---|
| 27 | |
---|
| 28 | """ |
---|
| 29 | |
---|
| 30 | INDEX_TEMPLATE=""".. Autogenerated by genmods.py |
---|
| 31 | |
---|
| 32 | .. _api-index: |
---|
| 33 | |
---|
| 34 | ############################################################################## |
---|
| 35 | %(package_name)s |
---|
| 36 | ############################################################################## |
---|
| 37 | |
---|
| 38 | .. only:: html |
---|
| 39 | |
---|
| 40 | :Release: |version| |
---|
| 41 | :Date: |today| |
---|
| 42 | |
---|
| 43 | .. toctree:: |
---|
| 44 | |
---|
| 45 | %(rsts)s |
---|
| 46 | """ |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | def genfiles(package, package_name, modules, dir='api'): |
---|
[4f82183] | 50 | """ |
---|
| 51 | Generates .rst file for each python module under sans.guiframe |
---|
| 52 | """ |
---|
[0d86fecb] | 53 | |
---|
| 54 | if not os.path.exists(dir): |
---|
| 55 | os.makedirs(dir) |
---|
| 56 | |
---|
| 57 | for module,name in modules: |
---|
| 58 | with open(os.path.join(dir,module+'.rst'), 'w') as f: |
---|
| 59 | f.write(MODULE_TEMPLATE%locals()) |
---|
| 60 | |
---|
| 61 | rsts = "\n ".join(module+'.rst' for module,name in modules) |
---|
| 62 | with open(os.path.join(dir,'index.rst'),'w') as f: |
---|
| 63 | f.write(INDEX_TEMPLATE%locals()) |
---|
| 64 | |
---|
| 65 | |
---|
[4f82183] | 66 | def create_module_tuple(path): |
---|
| 67 | """ |
---|
| 68 | Create tuples of module and module name |
---|
| 69 | :param path: path of the a package directory |
---|
| 70 | """ |
---|
| 71 | modules = [] |
---|
| 72 | list = os.listdir(path) |
---|
| 73 | for item in list: |
---|
| 74 | toks = os.path.splitext(os.path.basename(item)) |
---|
| 75 | if toks[1] == '.py' and toks[0] not in ["__init__"]: |
---|
| 76 | exec "module = ('%s', '%s')"%(toks[0], toks[0]) |
---|
| 77 | modules.append(module) |
---|
| 78 | return modules |
---|
[0d86fecb] | 79 | |
---|
| 80 | if __name__ == "__main__": |
---|
[4f82183] | 81 | |
---|
| 82 | path = os.path.join('..', '..', 'src', 'sans', 'guiframe') |
---|
| 83 | modules = create_module_tuple(path) |
---|
| 84 | package = 'sans.guiframe' |
---|
| 85 | package_name = 'Reference' |
---|
[0d86fecb] | 86 | genfiles(package, package_name, modules, dir='api') |
---|
[4f82183] | 87 | # build local plugin |
---|
| 88 | for f in os.listdir(path): |
---|
| 89 | if os.path.isdir(os.path.join(path, f)) and not f.startswith('.') \ |
---|
| 90 | and f not in ['images', 'media']: |
---|
| 91 | if f == "local_perspectives": |
---|
| 92 | temp = os.path.join(path, f) |
---|
| 93 | if os.path.isdir(temp): |
---|
| 94 | for tf in os.listdir(temp): |
---|
| 95 | if os.path.isdir(os.path.join(path, f, tf)) \ |
---|
| 96 | and not tf.startswith('.') : |
---|
| 97 | package = "sans.guiframe" |
---|
| 98 | package += ".local_perspectives.%s" % str(tf) |
---|
| 99 | p = os.path.join(path, f, tf) |
---|
| 100 | package_name = 'Local Perspective: %s' % str(tf) |
---|
| 101 | modules = create_module_tuple(p) |
---|
| 102 | dir = os.path.join("api", "local_perspectives", tf) |
---|
| 103 | genfiles(package, package_name, modules, dir=dir) |
---|
| 104 | |
---|
[0d86fecb] | 105 | print "Sphinx: generate .rst files complete..." |
---|
| 106 | |
---|