926b57670c49360d275355ae5b929a1fb4f6a118
[senf.git] / doclib / SConscript
1 # -*- python -*-
2
3 Import('env')
4 import SENFSCons
5
6 ###########################################################################
7
8 import yaptu
9
10 def modules():
11     # Naja ... etwas rumgehackt aber was solls ...
12     global EXTRA_MODULES
13     mods = {}
14     pathbase = len(env.Dir('#').abspath)+1
15     for module in env.Alias('all_docs')[0].sources:
16         if module.name != 'html.stamp' : continue 
17         mods[module.dir.dir.dir.abspath] = [ module.dir.dir.dir.name,
18                                              module.dir.abspath[pathbase:],
19                                              0 ]
20         
21     rv = []
22     keys = mods.keys()
23     keys.sort()
24     for mod in keys:
25         i = 0
26         while i < len(rv):
27             if len(rv[i]) > pathbase and mod.startswith(rv[i] + '/'):
28                 level = mods[rv[i]][2] + 1
29                 i += 1
30                 while i < len(rv) and mods[rv[i]][2] >= level:
31                     i += 1
32                 rv[i:i] = [ mod ]
33                 mods[mod][2] = level
34                 break
35             i += 1
36         if i == len(rv):
37             rv.append(mod)
38
39     for mod in keys:
40         if mods[mod][2] == 0:
41             mods[mod][0] = 'lib' + mods[mod][0]
42
43     n = 0
44     for name,path in EXTRA_MODULES:
45         path = env.Dir(path).dir.dir.abspath
46         i = 0
47         while i < len(rv):
48             if rv[i] == path:
49                 mods[rv[i]][0] = name
50                 m = 1
51                 while i+m < len(rv) and mods[rv[i+m]][2] > mods[rv[i]][2]:
52                     m += 1
53                 rv[n:n] = rv[i:i+m]
54                 rv[i+m:i+2*m] = []
55                 i += m
56                 n += m
57             else:
58                 i += 1
59
60     return ( tuple(mods[mod]) for mod in rv )
61
62 def indices():
63     ix = len(env.Dir('#').abspath)+1
64     return [ doc.dir.abspath[ix:]
65              for doc in env.Alias('all_docs')[0].sources
66              if doc.name == "search.idx" ]
67
68 def writeTemplate(target = None, source = None, env = None):
69     file(target[0].abspath,"w").write(yaptu.process(str(env['TEMPLATE']), globals(), env.Dictionary()))
70
71 writeTemplate = env.Action(writeTemplate, varlist = [ 'TEMPLATE' ])
72
73 ###########################################################################
74
75 # Extra documentation modules which are handled (named) different from
76 # library modules
77 EXTRA_MODULES = [
78     ('Overview', '#/doc/html'),
79     ('Examples', '#/Examples/doc/html'),
80     ('HowTo\'s', '#/HowTos/doc/html'),
81     ('SENFSCons', '#/senfscons/doc/html') ]
82
83 HEADER = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
84 <html>
85 <head>
86 <title>$title</title>
87 <link href="@TOPDIR@/doc/html/doxygen.css" rel="stylesheet" type="text/css">
88 <link href="@TOPDIR@/doclib/senf.css" rel="stylesheet" type="text/css">
89 <link rel="shortcut icon" href="@TOPDIR@/doclib/favicon.ico">
90 <style type="text/css">
91 div.tabs ul li.$projectname a { background-color: #EDE497; }
92 </style>
93 </head>
94 <body>
95
96 <div id="head">
97   <div id="title">
98     <div id="title2">
99       <div id="search">
100         <form action="@TOPDIR@/doclib/search.php" method="get">
101           Search: <input type="text" name="query" size="20" accesskey="s"/> 
102         </form>
103       </div>
104       <h1>SENF Extensible Network Framework</h1>
105     </div>
106   </div>
107   <div id="subtitle">
108     <ul>
109       <li><a href="@TOPDIR@/doc/html/xref.html">Open Issues</a></li>
110       <li><a class="ext" href="http://developer.berlios.de/bugs/?group_id=7489">Bug Tracker</a></li>
111       <li><a class="ext" href="http://svn.berlios.de/viewcvs/senf/trunk/">Browse SVN</a></li>
112       <li><a class="ext" href="http://svn.berlios.de/wsvn/senf/?op=log&rev=0&sc=0&isdir=1">ChangeLog</a></li>
113       <li><a class="ext" href="http://developer.berlios.de/projects/senf">BerliOS</a></li>
114       <li><a class="ext" href="http://openfacts.berlios.de/index-en.phtml?title=SENF+Network+Framework">Wiki</a></li>
115       <li><a href="@TOPDIR@/doc/html/index.html">Home</a></li>
116     </ul>
117     <h2>${TITLE}</h2>
118   </div>
119 </div>
120
121 <div id="content1">
122   <div id="content2">
123     <div class="tabs menu">
124       <ul>
125 {{      for name, path, level in modules():
126           <li class="${name} level${level}"><a href="@TOPDIR@/${path}/index.html">${name}</a></li>
127 }}
128       </ul>
129     </div>"""
130
131 FOOTER = """<hr style="width:0px;border:none;clear:both;margin:0;padding:0" />
132   </div>
133 </div>
134 <div id="footer">
135   <span>
136     <a href="mailto:senf-dev@lists.berlios.de">Contact: senf-dev@lists.berlios.de</a> |
137     Copyright &copy; 2006 Fraunhofer Gesellschaft, SatCom, Stefan Bund
138   </span>
139 </div>
140 </body></html>"""
141
142 SEARCH_PHP="""
143 <?php include 'search_functions.php'; ?>
144 <?php search(); ?>"""
145
146 SEARCH_PATHS_PHP="""<?php
147 function paths() {
148   return array(
149 {{  for index in indices():
150       "../${index}/",
151 }}
152   );
153 }
154 ?>"""
155
156 env.Command('doxy-header.html', 'SConscript', writeTemplate,
157             TEMPLATE = Literal(HEADER),
158             TITLE = "Documentation and API reference")
159 env.Command('doxy-footer.html', 'SConscript', writeTemplate,
160             TEMPLATE = Literal(FOOTER))
161 env.Alias('all_docs',
162           env.Command('search.php', [ 'html-munge.xsl', 'SConscript' ],
163                       [ writeTemplate,
164                         'xsltproc --nonet --html --stringparam topdir .. -o - $SOURCE $TARGET 2>/dev/null'
165                             + "| sed"
166                             +   r" -e 's/\[\[/<?/g' -e 's/\]\]/?>/g'"
167                             +   r" -e 's/\$$projectname/Overview/g'"
168                             +   r" -e 's/\$$title/Search results/g'"
169                             +       "> ${TARGETS[0]}.tmp",
170                         'mv ${TARGET}.tmp ${TARGET}' ],
171                       TEMPLATE = Literal(HEADER
172                                          + SEARCH_PHP.replace('<?','[[').replace('?>',']]')
173                                          + FOOTER),
174                       TITLE = "Search results"))
175 env.Alias('all_docs',
176           env.Command('search_paths.php', 'SConscript', writeTemplate,
177                       TEMPLATE = Literal(SEARCH_PATHS_PHP)))
178
179 env.Alias('install_all',
180           env.Install( '$DOCINSTALLDIR/doclib', [ 'favicon.ico',
181                                                   'logo-head.png',
182                                                   'search.php',
183                                                   'search_functions.php',
184                                                   'search_paths.php',
185                                                   'senf.css' ] ))
186
187 env.Clean('all', 'doxy-header.html') # I should not need this but I do ...
188 env.Clean('all_docs', 'doxy-header.html') # I should not need this but I do ...