source: sasview/sansguiframe/docs/sphinx/genmods.py @ b4293d2

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since b4293d2 was c0ddd6b, checked in by Mathieu Doucet <doucetm@…>, 13 years ago

removed generated docs

  • Property mode set to 100644
File size: 3.1 KB
RevLine 
[4f82183]1"""
2This module generates .rst file for each python file under sans.guiframe.
3Please run this file to autogenerate .rst files and build sphinx doc.
4
5"""
6
7
8
9
[0d86fecb]10from __future__ import with_statement
11import os.path
12
13MODULE_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
30INDEX_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
49def 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]66def 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
80if __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   
Note: See TracBrowser for help on using the repository browser.