debian-forge/osbuild
Christian Kellner 2a9cdde5ec osbuild: refactor stage information
For all currently supported modules, i.e. stages and assemblers,
convert the STAGE_DESC and STAGE_INFO into a proper doc-string.
Rename the STAGE_OPTS into SCHEMA.
Refactor meta.ModuleInfo loading accordingly.

The script to be used for the conversion is:

  --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< ---

import os
import sys

import osbuild
import osbuild.meta

from osbuild.meta import ModuleInfo

def find_line(lines, start):
    for i, l in enumerate(lines):
        if l.startswith(start):
            return i
    return None

def del_block(lines, prefix):
    start = find_line(lines, prefix)
    end = find_line(lines[start:], '"""')
    print(start, end)
    del lines[start:start+end+1]

def main():
    index = osbuild.meta.Index(os.curdir)

    modules = []
    for klass in ("Stage", "Assembler"):
        mods = index.list_modules_for_class(klass)
        modules += [(klass, module) for module in mods]

    for m in modules:
        print(m)
        klass, name = m
        info = ModuleInfo.load(os.curdir, klass, name)

        module_path = ModuleInfo.module_class_to_directory(klass)
        path = os.path.join(os.curdir, module_path, name)
        with open(path, "r") as f:
            data = list(f.readlines())

            i = find_line(data, "STAGE_DESC")
            print(i)
            del data[i]

            del_block(data, "STAGE_INFO")

            i = find_line(data, "STAGE_OPTS")
            data[i] = 'SCHEMA = """\n'

        docstr = '"""\n' + info.desc + "\n" + info.info + '"""\n'
        doclst = docstr.split("\n")
        doclst = [l + "\n" for l in doclst]
        data = [data[0]] + doclst + data[1:]

        with open(path, "w") as f:
            f.writelines(data)

if __name__ == "__main__":
    main()
2020-05-29 08:37:47 +02:00
..
util osbuild: avoid [] as default value 2020-05-28 11:06:05 +02:00
__init__.py osbuild: extract CLI to prepare for additional entrypoints 2020-04-28 15:39:54 +02:00
__main__.py osbuild: extract CLI to prepare for additional entrypoints 2020-04-28 15:39:54 +02:00
api.py osbuild: convert to jsoncomm 2020-04-21 13:47:38 +02:00
buildroot.py buildroot: convert unused format-string 2020-05-28 11:06:05 +02:00
loop.py loop: fix FD leak in mknod() 2020-04-21 13:02:29 +02:00
main_cli.py pipeline: checkpoint assemblers just like stages 2020-05-28 14:55:00 +02:00
meta.py osbuild: refactor stage information 2020-05-29 08:37:47 +02:00
objectstore.py pipeline: drop output_id and pull in output-directory 2020-05-28 11:16:15 +02:00
pipeline.py pipeline: checkpoint assemblers just like stages 2020-05-28 14:55:00 +02:00
remoteloop.py osbuild: convert to jsoncomm 2020-04-21 13:47:38 +02:00
sources.py sources: pass the library dir to the sources 2020-05-20 14:43:33 +02:00
treesum.py treesum: don't use dir_fd parameter in os.scandir() 2019-11-29 00:45:14 +01:00