| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
import os |
| 4 |
import os.path |
| 5 |
import re |
| 6 |
|
| 7 |
pkg_re = re.compile("^(private)?\s*package\s*(\S+)") |
| 8 |
|
| 9 |
|
| 10 |
def recursive_ls(dir): |
| 11 |
"""Return the list of ads files in dir and its subdirs""" |
| 12 |
result = set() |
| 13 |
for f in os.listdir(dir): |
| 14 |
if f.endswith(".ads") \ |
| 15 |
and f.startswith("gnatcoll-"): |
| 16 |
|
| 17 |
private = False |
| 18 |
pkg = "" |
| 19 |
for l in file(os.path.join(dir, f)).readlines(): |
| 20 |
m = pkg_re.search(l) |
| 21 |
if m: |
| 22 |
private = m.group(1) |
| 23 |
pkg = m.group(2) |
| 24 |
break |
| 25 |
|
| 26 |
if not private: |
| 27 |
result.add((pkg, os.path.splitext(f)[0])) |
| 28 |
|
| 29 |
elif os.path.isdir(os.path.join(dir, f)): |
| 30 |
result = result.union(recursive_ls(os.path.join(dir, f))) |
| 31 |
|
| 32 |
return result |
| 33 |
|
| 34 |
list = recursive_ls("../src") |
| 35 |
out = file("gnatcoll/runtime.py", "wb") |
| 36 |
out.write("""XML = r'''<?xml version="1.0"?> |
| 37 |
<GPS> |
| 38 |
""") |
| 39 |
|
| 40 |
for pkg, f in sorted(list): |
| 41 |
if '__' in f: |
| 42 |
# An internal package with a specific naming scheme |
| 43 |
continue |
| 44 |
|
| 45 |
menu = pkg.replace(".", "/").replace("_", "__") |
| 46 |
|
| 47 |
# Do we have a submenu ? |
| 48 |
in_front = False |
| 49 |
for pkg2, b in list: |
| 50 |
if b.startswith(f + "-"): |
| 51 |
item = menu[menu.rfind("/") + 1:] |
| 52 |
menu = menu + "/<" + item + ">" |
| 53 |
break |
| 54 |
|
| 55 |
out.write(""" <documentation_file> |
| 56 |
<shell>Editor.edit "%(file)s.ads"</shell> |
| 57 |
<descr>%(package)s</descr> |
| 58 |
<menu>/Help/GNAT Runtime/%(menu)s</menu> |
| 59 |
<category>GNAT Components Collection</category> |
| 60 |
</documentation_file> |
| 61 |
|
| 62 |
""" % {"file": f, "menu": menu, "package": pkg}) |
| 63 |
|
| 64 |
out.write("""</GPS>''' |
| 65 |
import GPS |
| 66 |
GPS.parse_xml(XML) |
| 67 |
""") |
| 68 |
out.close() |