~durga/maus/online

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env python
"""Generate doxygen documentation for MAUS components"""
# This file should be run second, after generate_third_party_doc.py
# For more information see README.

import subprocess
import os
import sys
import glob
import re
from generate_doc_index import create_index_html # pylint: disable=F0401

# pylint: disable = C0103
if os.environ.get('MAUS_THIRD_PARTY') == None:
    print 'MAUS environment variables not set.'
    print 'Please make sure to source env.sh before running this script.'
    print 'Exiting...'
    exit()

def main():
    """Generate list of tagfiles, then trigger doxygen for components"""
    prompt = 1
    if len(sys.argv) > 1 and str(sys.argv[1]) == '--noprompt':
        prompt = 0
    maus_thirdparty = os.environ['MAUS_THIRD_PARTY']
    maus_rootdir = os.environ['MAUS_ROOT_DIR']
    thirdpartylibs = ['root', 'geant4', 'clhep', 'jsoncpp']
    maus_components = ['framework', 'datastructure', 'input', 'map', 'reduce',
                      'output']
    print 'MAUS_THIRD_PARTY path is set to ' + maus_thirdparty
    print 'Checking for existing tag files...'
    tagfiles = []
    # Check for tagfiles. Note that this information isn't actually used as an
    # input to doxygen, just to let the user choose whether he wants to
    # continue if fewer tagfiles than expected were found. See below for more
    # info.
    for tplib in thirdpartylibs:
        tppath = (maus_thirdparty + '/doc/doxygen_' + tplib + '/' + tplib +
                  '.tag')
        if os.path.isfile(tppath):
            tagfiles.append(tppath)
            print 'Tagfile found: ' + tppath
    check_tagfiles(tagfiles, prompt)
    if prompt != 0:
        raw_input('If everything is correct, please press enter to compile ' +
                  'documentation')

    # To make things portable we need to get the relative path from the MAUS dir
    # to the third party dir, as we do in generate_doc_index.py
    paths = [maus_thirdparty, maus_rootdir]
    tppath_segment = paths[0][len(commonprefix(paths))+1:]
    maus_path_segment = paths[1][len(commonprefix(paths))+1:]
    # Need to deal with the case where the two paths are the same
    if tppath_segment == maus_path_segment:
        rel_tppath = ''
    # Generate the appropriate paths to link to the third party libaries.
    else:
        rel_tppath = tppath_segment + '/doc/'
        dir_prepend = '../'*(maus_path_segment.count('/')+2)
        rel_tppath = dir_prepend + rel_tppath

    # A list of all tagfiles with doc location. MAUS component tagfiles are
    # added one by one as they are created.
    tagfiles_dict = dict((i, '../' + rel_tppath + 'doxygen_' + i + '/' + i +
                        '.tag=' + '../../' + rel_tppath + 'doxygen_' + i +
                        '/html') for i in thirdpartylibs)
    tagfilesmaus_dict = dict((i, '../doxygen_' + i + '/' + i +
                            '.tag=' + '../../doxygen_' + i +
                            '/html') for i in maus_components)
    tagfiles = ' '.join(tagfiles_dict.values())
    
    for component in maus_components:
        if component == 'framework':
            run_doxygen_framework(tagfiles)
        elif component == 'datastructure':
            run_doxygen_datastructure(tagfiles)
        else:
            run_doxygen(component, tagfiles)
        tagfiles = tagfiles + ' ' + tagfilesmaus_dict[component]
    create_index_html()
    exit()


def check_tagfiles(tagfiles, prompt):
    """Check for tagfiles, if missing prompt user for how to proceed"""
    # Case where we have 0 or 0 < # < expected tagfiles found.
    if len(tagfiles) == 0:
        print ('No Tagfiles found. Most likely, third party documentation has '
              'not been compiled.')
    elif len(tagfiles) <= 3:
        print ('Only found tagfiles for ' + str(len(tagfiles)) +
              ' out of 4 third party libraries.')
        print ('Maybe there was a problem with compiling third party '
              'documentation?')
    # If fewer tagfiles than expected found, prompt whether documentation
    # should still be compiled.
    if len(tagfiles) <= 3:
        choice = ''
        while choice not in ['c', 'a'] and prompt != 0:
            choice = raw_input('Would you like to [c]ontinue anyway or '
                               '[a]bort ')
            if choice == 'a':
                exit()
            else:
                continue


# framework and datastructure need own snippets due to some special settings

def run_doxygen_framework(tagfiles):
    """Run doxygen for the MAUS framework"""
    script = """( cat Doxyfile.general ;
        echo 'PROJECT_NAME = "MAUS-framework"';
        echo INPUT = ../../src/common_*/ ../../src/py_cpp/ ../../src/legacy/;
        echo OUTPUT_DIRECTORY = ../doxygen_framework/;
        echo TAGFILES = $0;
        echo QUIET = YES;
        echo EXCLUDE_PATTERNS = */DataStructure/*;
        echo GENERATE_TAGFILE = ../doxygen_framework/framework.tag ) | doxygen -
        """
    subprocess.call([script, str(tagfiles)], shell=True)


def run_doxygen_datastructure(tagfiles):
    """Run doxygen for the MAUS DataStructure"""
    script = """( cat Doxyfile.general ;
        echo 'PROJECT_NAME = "MAUS-datastructure"';
        echo INPUT = ../../src/common_cpp/DataStructure/;
        echo OUTPUT_DIRECTORY = ../doxygen_datastructure/;
        echo TAGFILES = $0;
        echo QUIET = YES;
        echo EXCLUDE_PATTERNS = *MausDataStructure.*
        echo GENERATE_TAGFILE = ../doxygen_datastructure/datastructure.tag ) | doxygen -
        """
    subprocess.call([script, str(tagfiles)], shell=True)


def run_doxygen(component, tagfiles):
    """Run doxygen for other MAUS components"""
    script = """( cat Doxyfile.general ;
        echo PROJECT_NAME = MAUS-$0;
        echo INPUT = ../../src/$0/;
        echo OUTPUT_DIRECTORY = ../doxygen_$0/;
        echo TAGFILES = $1;
        echo QUIET = YES;
        echo GENERATE_TAGFILE = ../doxygen_$0/$0.tag ) | doxygen -
        """
    subprocess.call([script, str(component), str(tagfiles)], shell=True)

def commonprefix(*args):
    """Fix behaviour of commonprefix function"""
    return os.path.commonprefix(*args).rpartition('/')[0]

if __name__ == "__main__":
    main()