Mercurial > hg > truffle
comparison mxtool/mx.py @ 6335:897f5bb96d60
fixed generated package-summary.html files to put the complete package description at the top of the page
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 07 Sep 2012 16:55:07 +0200 |
parents | e952911afd2f |
children | f45d5cb03c3b |
comparison
equal
deleted
inserted
replaced
6334:f8ba3bb81f6f | 6335:897f5bb96d60 |
---|---|
2276 extraArgs + | 2276 extraArgs + |
2277 nowarnAPI + | 2277 nowarnAPI + |
2278 list(pkgs)) | 2278 list(pkgs)) |
2279 log('Generated {2} for {0} in {1}'.format(', '.join(names), out, docDir)) | 2279 log('Generated {2} for {0} in {1}'.format(', '.join(names), out, docDir)) |
2280 | 2280 |
2281 class Chunk: | |
2282 def __init__(self, content, ldelim, rdelim=None): | |
2283 lindex = content.find(ldelim) | |
2284 if rdelim is not None: | |
2285 rindex = content.find(rdelim) | |
2286 else: | |
2287 rindex = lindex + len(ldelim) | |
2288 self.ldelim = ldelim | |
2289 self.rdelim = rdelim | |
2290 if lindex != -1 and rindex != -1 and rindex > lindex: | |
2291 self.text = content[lindex + len(ldelim):rindex] | |
2292 else: | |
2293 self.text = None | |
2294 | |
2295 def replace(self, content, repl): | |
2296 lindex = content.find(self.ldelim) | |
2297 if self.rdelim is not None: | |
2298 rindex = content.find(self.rdelim) | |
2299 rdelimLen = len(self.rdelim) | |
2300 else: | |
2301 rindex = lindex + len(self.ldelim) | |
2302 rdelimLen = 0 | |
2303 old = content[lindex:rindex + rdelimLen] | |
2304 return content.replace(old, repl) | |
2305 | |
2306 # Post-process an overview-summary.html file to move the | |
2307 # complete overview to the top of the page | |
2308 def _fix_overview_summary(path, topLink): | |
2309 """ | |
2310 Processes an "overview-summary.html" generated by javadoc to put the complete | |
2311 summary text above the Packages table. | |
2312 """ | |
2313 | |
2314 # This uses scraping and so will break if the relevant content produced by javadoc changes in any way! | |
2315 with open(path) as fp: | |
2316 content = fp.read() | |
2317 | |
2318 chunk1 = Chunk(content, """<div class="header"> | |
2319 <div class="subTitle"> | |
2320 <div class="block">""", """</div> | |
2321 </div> | |
2322 <p>See: <a href="#overview_description">Description</a></p> | |
2323 </div>""") | |
2324 | |
2325 chunk2 = Chunk(content, """<div class="footer"><a name="overview_description"> | |
2326 <!-- --> | |
2327 </a> | |
2328 <div class="subTitle"> | |
2329 <div class="block">""", """</div> | |
2330 </div> | |
2331 </div> | |
2332 <!-- ======= START OF BOTTOM NAVBAR ====== -->""") | |
2333 | |
2334 assert chunk1.text, 'Could not find header section in ' + path | |
2335 assert chunk2.text, 'Could not find footer section in ' + path | |
2336 | |
2337 content = chunk1.replace(content, '<div class="header"><div class="subTitle"><div class="block">' + topLink + chunk2.text +'</div></div></div>') | |
2338 content = chunk2.replace(content, '') | |
2339 | |
2340 with open(path, 'w') as fp: | |
2341 fp.write(content) | |
2342 | |
2343 | |
2344 # Post-process a package-summary.html file to move the | |
2345 # complete package description to the top of the page | |
2346 def _fix_package_summary(path): | |
2347 """ | |
2348 Processes an "overview-summary.html" generated by javadoc to put the complete | |
2349 summary text above the Packages table. | |
2350 """ | |
2351 | |
2352 # This uses scraping and so will break if the relevant content produced by javadoc changes in any way! | |
2353 with open(path) as fp: | |
2354 content = fp.read() | |
2355 | |
2356 chunk1 = Chunk(content, """<div class="header"> | |
2357 <h1 title="Package" class="title">Package""", """<p>See: <a href="#package_description">Description</a></p> | |
2358 </div>""") | |
2359 | |
2360 chunk2 = Chunk(content, """<a name="package_description"> | |
2361 <!-- --> | |
2362 </a>""", """</div> | |
2363 </div> | |
2364 <!-- ======= START OF BOTTOM NAVBAR ====== -->""") | |
2365 | |
2366 if chunk1.text: | |
2367 if chunk2.text: | |
2368 repl = re.sub(r'<h2 title=(.*) Description</h2>', r'<h1 title=\1</h1>', chunk2.text, 1) | |
2369 content = chunk1.replace(content, '<div class="header">' + repl +'</div></div>') | |
2370 content = chunk2.replace(content, '') | |
2371 | |
2372 with open(path, 'w') as fp: | |
2373 fp.write(content) | |
2374 else: | |
2375 log('warning: Could not find package description detail section in ' + path) | |
2376 | |
2377 else: | |
2378 # no package description given | |
2379 pass | |
2380 | |
2281 def site(args): | 2381 def site(args): |
2282 """creates a website containing javadoc and the project dependency graph""" | 2382 """creates a website containing javadoc and the project dependency graph""" |
2283 | 2383 |
2284 parser = ArgumentParser(prog='site') | 2384 parser = ArgumentParser(prog='site') |
2285 parser.add_argument('-d', '--base', action='store', help='directory for generated site', required=True, metavar='<dir>') | 2385 parser.add_argument('-d', '--base', action='store', help='directory for generated site', required=True, metavar='<dir>') |
2361 | 2461 |
2362 # Create HTML that embeds the svg file in an <object> frame | 2462 # Create HTML that embeds the svg file in an <object> frame |
2363 with open(html, 'w') as fp: | 2463 with open(html, 'w') as fp: |
2364 print >> fp, '<html><body><object data="modules.svg" type="image/svg+xml"></object></body></html>' | 2464 print >> fp, '<html><body><object data="modules.svg" type="image/svg+xml"></object></body></html>' |
2365 | 2465 |
2366 # Post-process generated overview-summary.html files | |
2367 def fix_overview_summary(path, topLink): | |
2368 """ | |
2369 Processes an "overview-summary.html" generated by javadoc to put the complete | |
2370 summary text above the Packages table. | |
2371 """ | |
2372 | |
2373 # This uses scraping and so will break if the relevant content produced by javadoc changes in any way! | |
2374 with open(path) as fp: | |
2375 content = fp.read() | |
2376 | |
2377 class Chunk: | |
2378 def __init__(self, content, ldelim, rdelim): | |
2379 lindex = content.find(ldelim) | |
2380 rindex = content.find(rdelim) | |
2381 self.ldelim = ldelim | |
2382 self.rdelim = rdelim | |
2383 if lindex != -1 and rindex != -1 and rindex > lindex: | |
2384 self.text = content[lindex + len(ldelim):rindex] | |
2385 else: | |
2386 self.text = None | |
2387 | |
2388 def replace(self, content, repl): | |
2389 lindex = content.find(self.ldelim) | |
2390 rindex = content.find(self.rdelim) | |
2391 old = content[lindex:rindex + len(self.rdelim)] | |
2392 return content.replace(old, repl) | |
2393 | |
2394 chunk1 = Chunk(content, """<div class="header"> | |
2395 <div class="subTitle"> | |
2396 <div class="block">""", """</div> | |
2397 </div> | |
2398 <p>See: <a href="#overview_description">Description</a></p> | |
2399 </div>""") | |
2400 | |
2401 chunk2 = Chunk(content, """<div class="footer"><a name="overview_description"> | |
2402 <!-- --> | |
2403 </a> | |
2404 <div class="subTitle"> | |
2405 <div class="block">""", """</div> | |
2406 </div> | |
2407 </div> | |
2408 <!-- ======= START OF BOTTOM NAVBAR ====== -->""") | |
2409 | |
2410 assert chunk1.text, 'Could not find header section in ' + path | |
2411 assert chunk2.text, 'Could not find footer section in ' + path | |
2412 | |
2413 content = chunk1.replace(content, '<div class="header"><div class="subTitle"><div class="block">' + topLink + chunk2.text +'</div></div></div>') | |
2414 content = chunk2.replace(content, '') | |
2415 | |
2416 with open(path, 'w') as fp: | |
2417 fp.write(content) | |
2418 | |
2419 top = join(tmpbase, 'all', 'overview-summary.html') | 2466 top = join(tmpbase, 'all', 'overview-summary.html') |
2420 for root, _, files in os.walk(tmpbase): | 2467 for root, _, files in os.walk(tmpbase): |
2421 for f in files: | 2468 for f in files: |
2422 if f == 'overview-summary.html': | 2469 if f == 'overview-summary.html': |
2423 path = join(root, f) | 2470 path = join(root, f) |
2424 topLink = '' | 2471 topLink = '' |
2425 if top != path: | 2472 if top != path: |
2426 link = os.path.relpath(join(tmpbase, 'all', 'index.html'), dirname(path)) | 2473 link = os.path.relpath(join(tmpbase, 'all', 'index.html'), dirname(path)) |
2427 topLink = '<p><a href="' + link + '", target="_top"><b>[return to the overall ' + args.name + ' documentation]</b></a></p>' | 2474 topLink = '<p><a href="' + link + '", target="_top"><b>[return to the overall ' + args.name + ' documentation]</b></a></p>' |
2428 fix_overview_summary(path, topLink) | 2475 _fix_overview_summary(path, topLink) |
2476 elif f == 'package-summary.html': | |
2477 path = join(root, f) | |
2478 _fix_package_summary(path) | |
2429 | 2479 |
2430 | 2480 |
2431 if exists(args.base): | 2481 if exists(args.base): |
2432 shutil.rmtree(args.base) | 2482 shutil.rmtree(args.base) |
2433 shutil.move(tmpbase, args.base) | 2483 shutil.move(tmpbase, args.base) |