| 1 | import py |
| 2 | from pypy.config import pypyoption, makerestdoc |
| 3 | from rpython.config import translationoption, config |
| 4 | |
| 5 | all_optiondescrs = [pypyoption.pypy_optiondescription, |
| 6 | translationoption.translation_optiondescription, |
| 7 | ] |
| 8 | start_to_descr = dict([(descr._name, descr) for descr in all_optiondescrs]) |
| 9 | |
| 10 | def make_cmdline_overview(): |
| 11 | result = [] |
| 12 | txtpath = thisdir.join("commandline.txt") |
| 13 | for line in txtpath.read().splitlines(): |
| 14 | if line.startswith('.. GENERATE:'): |
| 15 | start = line[len('.. GENERATE:'):].strip() |
| 16 | descr = start_to_descr[start] |
| 17 | line = makerestdoc.make_cmdline_overview(descr, title=False).text() |
| 18 | result.append(line) |
| 19 | rstpath = txtpath.new(ext=".rst") |
| 20 | rstpath.write("\n".join(result)) |
| 21 | |
| 22 | def make_rst(basename): |
| 23 | txtpath = thisdir.join(basename) |
| 24 | txtpath.ensure() |
| 25 | rstpath = txtpath.new(ext=".rst") |
| 26 | |
| 27 | fullpath = txtpath.purebasename |
| 28 | start = fullpath.split(".")[0] |
| 29 | path = fullpath.rsplit(".", 1)[0] |
| 30 | basedescr = start_to_descr.get(start) |
| 31 | if basedescr is None: |
| 32 | return |
| 33 | if fullpath.count(".") == 0: |
| 34 | descr = basedescr |
| 35 | path = "" |
| 36 | else: |
| 37 | conf = config.Config(basedescr) |
| 38 | subconf, step = conf._cfgimpl_get_home_by_path( |
| 39 | fullpath.split(".", 1)[1]) |
| 40 | descr = getattr(subconf._cfgimpl_descr, step) |
| 41 | text = unicode(descr.make_rest_doc(path).text()) |
| 42 | if txtpath.check(file=True): |
| 43 | content = txtpath.read() |
| 44 | if content: |
| 45 | text += "\n\n" |
| 46 | text = u"%s\n\n%s" % (text, unicode(txtpath.read(), "utf-8")) |
| 47 | rstpath.write(text.encode("utf-8")) |
| 48 | |
| 49 | |
| 50 | thisdir = py.path.local(__file__).dirpath() |
| 51 | |
| 52 | for descr in all_optiondescrs: |
| 53 | prefix = descr._name |
| 54 | c = config.Config(descr) |
| 55 | thisdir.join(prefix + ".txt").ensure() |
| 56 | make_rst(prefix + ".txt") |
| 57 | for p in c.getpaths(include_groups=True): |
| 58 | basename = prefix + "." + p + ".txt" |
| 59 | make_rst(basename) |
| 60 | |
| 61 | make_cmdline_overview() |