~durga/maus/online

« back to all changes in this revision

Viewing changes to doc/doc_tools/generate_maus_doc.py

  • Committer: Adam Dobbs
  • Date: 2015-01-23 16:47:07 UTC
  • mfrom: (799.1.1 maus-doxytest)
  • Revision ID: phuccj@gmail.com-20150123164707-ikejaee3j0y7xha1
Doxygen update from Jan

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/env python
 
1
#!/usr/bin/env python
2
2
"""Generate doxygen documentation for MAUS components"""
3
3
# This file should be run second, after generate_third_party_doc.py
4
4
# For more information see README.
44
44
    if prompt != 0:
45
45
        raw_input('If everything is correct, please press enter to compile ' +
46
46
                  'documentation')
47
 
    
 
47
 
 
48
    # To make things portable we need to get the relative path from the MAUS dir
 
49
    # to the third party dir, as we do in generate_doc_index.py
 
50
    paths = [maus_thirdparty, maus_rootdir]
 
51
    tppath_segment = paths[0][len(commonprefix(paths))+1:]
 
52
    maus_path_segment = paths[1][len(commonprefix(paths))+1:]
 
53
    # Need to deal with the case where the two paths are the same
 
54
    if tppath_segment == maus_path_segment:
 
55
        rel_tppath = ''
 
56
    # Generate the appropriate paths to link to the third party libaries.
 
57
    else:
 
58
        rel_tppath = tppath_segment + '/doc/'
 
59
        dir_prepend = '../'*(maus_path_segment.count('/')+2)
 
60
        rel_tppath = dir_prepend + rel_tppath
 
61
 
48
62
    # A list of all tagfiles with doc location. MAUS component tagfiles are
49
63
    # added one by one as they are created.
50
 
    tagfiles_dict = dict((i, maus_thirdparty + '/doc/doxygen_' + i + '/' + i +
51
 
                        '.tag=' + maus_thirdparty + '/doc/doxygen_' + i +
 
64
    tagfiles_dict = dict((i, '../' + rel_tppath + 'doxygen_' + i + '/' + i +
 
65
                        '.tag=' + '../../' + rel_tppath + 'doxygen_' + i +
52
66
                        '/html') for i in thirdpartylibs)
53
 
    tagfilesmaus_dict = dict((i, maus_rootdir + '/doc/doxygen_' + i + '/' + i +
54
 
                            '.tag=' + maus_rootdir + '/doc/doxygen_' + i +
 
67
    tagfilesmaus_dict = dict((i, '../doxygen_' + i + '/' + i +
 
68
                            '.tag=' + '../../doxygen_' + i +
55
69
                            '/html') for i in maus_components)
56
70
    tagfiles = ' '.join(tagfiles_dict.values())
57
71
    
63
77
        else:
64
78
            run_doxygen(component, tagfiles)
65
79
        tagfiles = tagfiles + ' ' + tagfilesmaus_dict[component]
66
 
    fix_doxygen_paths()
67
80
    create_index_html()
68
81
    exit()
69
82
 
96
109
 
97
110
def run_doxygen_framework(tagfiles):
98
111
    """Run doxygen for the MAUS framework"""
99
 
    script = """( cat ${MAUS_ROOT_DIR}/doc/doc_tools/Doxyfile.general ;
 
112
    script = """( cat Doxyfile.general ;
100
113
        echo 'PROJECT_NAME = "MAUS-framework"';
101
 
        echo INPUT = ${MAUS_ROOT_DIR}/src/common_*/ ${MAUS_ROOT_DIR}/src/py_cpp/ ${MAUS_ROOT_DIR}/src/legacy/;
102
 
        echo OUTPUT_DIRECTORY = ${MAUS_ROOT_DIR}/doc/doxygen_framework/;
 
114
        echo INPUT = ../../src/common_*/ ../../src/py_cpp/ ../../src/legacy/;
 
115
        echo OUTPUT_DIRECTORY = ../doxygen_framework/;
103
116
        echo TAGFILES = $0;
104
117
        echo QUIET = YES;
105
118
        echo EXCLUDE_PATTERNS = */DataStructure/*;
106
 
        echo GENERATE_TAGFILE = ${MAUS_ROOT_DIR}/doc/doxygen_framework/framework.tag ) | doxygen -
 
119
        echo GENERATE_TAGFILE = ../doxygen_framework/framework.tag ) | doxygen -
107
120
        """
108
121
    subprocess.call([script, str(tagfiles)], shell=True)
109
122
 
110
123
 
111
124
def run_doxygen_datastructure(tagfiles):
112
125
    """Run doxygen for the MAUS DataStructure"""
113
 
    script = """( cat ${MAUS_ROOT_DIR}/doc/doc_tools/Doxyfile.general ;
 
126
    script = """( cat Doxyfile.general ;
114
127
        echo 'PROJECT_NAME = "MAUS-datastructure"';
115
 
        echo INPUT = ${MAUS_ROOT_DIR}/src/common_cpp/DataStructure/;
116
 
        echo OUTPUT_DIRECTORY = ${MAUS_ROOT_DIR}/doc/doxygen_datastructure/;
 
128
        echo INPUT = ../../src/common_cpp/DataStructure/;
 
129
        echo OUTPUT_DIRECTORY = ../doxygen_datastructure/;
117
130
        echo TAGFILES = $0;
118
131
        echo QUIET = YES;
119
132
        echo EXCLUDE_PATTERNS = *MausDataStructure.*
120
 
        echo GENERATE_TAGFILE = ${MAUS_ROOT_DIR}/doc/doxygen_datastructure/datastructure.tag ) | doxygen -
 
133
        echo GENERATE_TAGFILE = ../doxygen_datastructure/datastructure.tag ) | doxygen -
121
134
        """
122
135
    subprocess.call([script, str(tagfiles)], shell=True)
123
136
 
124
137
 
125
138
def run_doxygen(component, tagfiles):
126
139
    """Run doxygen for other MAUS components"""
127
 
    script = """( cat ${MAUS_ROOT_DIR}/doc/doc_tools/Doxyfile.general ;
 
140
    script = """( cat Doxyfile.general ;
128
141
        echo PROJECT_NAME = MAUS-$0;
129
 
        echo INPUT = ${MAUS_ROOT_DIR}/src/$0/;
130
 
        echo OUTPUT_DIRECTORY = ${MAUS_ROOT_DIR}/doc/doxygen_$0/;
 
142
        echo INPUT = ../../src/$0/;
 
143
        echo OUTPUT_DIRECTORY = ../doxygen_$0/;
131
144
        echo TAGFILES = $1;
132
145
        echo QUIET = YES;
133
 
        echo GENERATE_TAGFILE = ${MAUS_ROOT_DIR}/doc/doxygen_$0/$0.tag ) | doxygen -
 
146
        echo GENERATE_TAGFILE = ../doxygen_$0/$0.tag ) | doxygen -
134
147
        """
135
148
    subprocess.call([script, str(component), str(tagfiles)], shell=True)
136
149
 
137
 
def fix_doxygen_paths():
138
 
    """Fix relative paths in doxygen search scripts"""
139
 
    # Note that there may be a simpler way to do this with the doxy config
140
 
    # however I have not been able to get that to work, hence this hack
141
 
    #
142
 
    # go through all doxygen generated components
143
 
    doxy_comps = ['root', 'geant4', 'clhep', 'jsoncpp', \
144
 
                 'framework', 'datastructure', 'input', 'map', 'reduce', \
145
 
                 'output']
146
 
    for component in doxy_comps:
147
 
        doxdir = 'doxygen_' + component
148
 
        # find the directory with the javascripts
149
 
        replace_in = os.path.expandvars("${MAUS_ROOT_DIR}")
150
 
        replace_out = '/maus/MAUS_latest_version'
151
 
        jsdir = os.path.join(os.environ['MAUS_ROOT_DIR'], \
152
 
                             'doc', doxdir, 'html', 'search')
153
 
        os.chdir(jsdir)
154
 
        for inputFile in glob.glob("*.js"):
155
 
            # open a tmp file to write the modified lines into
156
 
            tmpOut = inputFile + '.tmp'
157
 
            tmpFd = open(tmpOut, "w")
158
 
            # open the input js file
159
 
            inputFd = open(inputFile)
160
 
            for line in inputFd:
161
 
                # replace
162
 
                tmpFd.write(re.sub(replace_in, replace_out, line))
163
 
            # close the tmp file and rename it
164
 
            tmpFd.close()
165
 
            os.rename(tmpOut, inputFile)
 
150
def commonprefix(*args):
 
151
    """Fix behaviour of commonprefix function"""
 
152
    return os.path.commonprefix(*args).rpartition('/')[0]
 
153
 
166
154
if __name__ == "__main__":
167
155
    main()