source: sasview/sansguiframe/docs/sphinx/genmods.py @ 011e0e4

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 011e0e4 was bce8148, checked in by Gervaise Alina <gervyh@…>, 13 years ago

sphinx build

  • Property mode set to 100644
File size: 3.2 KB
Line 
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
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   :special-members:
28   :private-members:
29
30"""
31
32INDEX_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
51def genfiles(package, package_name, modules, dir='api'):
52    """
53    Generates .rst file for each python module under sans.guiframe
54    """
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
68def 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
81
82if __name__ == "__main__":
83   
84    path = os.path.join('..', '..', 'src', 'sans', 'guiframe')
85    modules = create_module_tuple(path)
86    package = 'sans.guiframe'
87    package_name = 'Reference'
88    genfiles(package, package_name, modules, dir='api')
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         
107    print "Sphinx: generate .rst files complete..."
108   
Note: See TracBrowser for help on using the repository browser.