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()
81 lines
2 KiB
Python
Executable file
81 lines
2 KiB
Python
Executable file
#!/usr/bin/python3
|
|
"""
|
|
Assemble a tar archive
|
|
|
|
Assembles the tree into a tar archive named `filename`.
|
|
|
|
Uses the buildhost's `tar` command, like: `tar -cf $FILENAME -C $TREE`
|
|
|
|
If the `compression` option is given, the archive will be compressed by passing
|
|
the `--{compression}` option to `tar`. (This option is non-standard and might
|
|
not work for anything other than GNU tar.)
|
|
|
|
Known options for `compression`: "bzip2", "xz", "lzip", "lzma", "lzop", "gzip".
|
|
|
|
Note that using `compression` does not add an extension to `filename`, so the
|
|
caller is responsible for making sure that `compression` and `filename` match.
|
|
|
|
Buildhost commands used: `tar` and any named `compression` program.
|
|
"""
|
|
|
|
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
|
|
SCHEMA = """
|
|
"additionalProperties": false,
|
|
"required": ["filename"],
|
|
"properties": {
|
|
"filename": {
|
|
"description": "Filename for tar archive",
|
|
"type": "string"
|
|
},
|
|
"compression": {
|
|
"description": "Name of compression program",
|
|
"type": "string",
|
|
"enum": ["bzip2", "xz", "lzip", "lzma", "lzop", "gzip"]
|
|
}
|
|
}
|
|
"""
|
|
|
|
def main(tree, output_dir, options):
|
|
filename = options["filename"]
|
|
compression = options.get("compression")
|
|
|
|
extra_args = []
|
|
if compression is not None:
|
|
if compression not in {"bzip2", "xz", "lzip", "lzma", "lzop", "gzip"}:
|
|
return 1
|
|
extra_args.append(f"--{compression}")
|
|
|
|
# Set environment variables for the tar operation.
|
|
tar_env = {
|
|
# Speed up xz by allowing it to use all CPU cores for compression.
|
|
"XZ_OPT": "--threads 0"
|
|
}
|
|
|
|
# Set up the tar command.
|
|
tar_cmd = [
|
|
"tar",
|
|
*extra_args,
|
|
"-cf", f"{output_dir}/{filename}",
|
|
"-C", tree,
|
|
"."
|
|
]
|
|
|
|
# Make a tarball of the tree.
|
|
subprocess.run(
|
|
tar_cmd,
|
|
stdout=subprocess.DEVNULL,
|
|
check=True,
|
|
env=tar_env
|
|
)
|
|
|
|
return 0
|
|
|
|
|
|
if __name__ == '__main__':
|
|
args = json.load(sys.stdin)
|
|
r = main(args["tree"], args["output_dir"], args["options"])
|
|
sys.exit(r)
|