aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Zamarin <arthurzam@gentoo.org>2023-10-23 20:03:30 +0300
committerArthur Zamarin <arthurzam@gentoo.org>2023-10-23 20:03:30 +0300
commit590658425abffe0253602adc30f7c22172f92b13 (patch)
tree2f2d72459303dc2f9ca1145700bd35ff430ed5bd
parentpmaint eclass: improve rst output (diff)
downloadpkgcore-590658425abffe0253602adc30f7c22172f92b13.tar.gz
pkgcore-590658425abffe0253602adc30f7c22172f92b13.tar.bz2
pkgcore-590658425abffe0253602adc30f7c22172f92b13.zip
pmaint eclass: add better invocation with output filename format
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
-rw-r--r--src/pkgcore/scripts/pmaint.py26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/pkgcore/scripts/pmaint.py b/src/pkgcore/scripts/pmaint.py
index 008de533..c148454a 100644
--- a/src/pkgcore/scripts/pmaint.py
+++ b/src/pkgcore/scripts/pmaint.py
@@ -497,6 +497,19 @@ eclass_opts.add_argument(
"--dir", dest="output_dir", type=arghparse.create_dir, help="output directory"
)
eclass_opts.add_argument(
+ "-o",
+ "--output",
+ dest="output_format",
+ default="{eclass}.eclass.{format}",
+ help="output file name format",
+ docs="""
+ Output file name format. Defaults to ``{eclass}.eclass.{format}``. You
+ can use ``{eclass}`` and ``{format}`` placeholders to customize the
+ output file name. The filename can have path separator, for example:
+ ``{eclass}/{eclass}.eclass.{format}``.
+ """,
+)
+eclass_opts.add_argument(
"-f",
"--format",
help="output format",
@@ -541,9 +554,16 @@ def _eclass_main(options, out, err):
for path in options.eclasses:
try:
- with open(
- pjoin(options.output_dir, f"{os.path.basename(path)}.{ext}"), "wt"
- ) as f:
+ filename = pjoin(
+ options.output_dir,
+ options.output_format.format(
+ eclass=os.path.basename(path).removesuffix(".eclass"),
+ format=ext,
+ ),
+ )
+ out.write("Compiling: ", path)
+ os.makedirs(os.path.dirname(filename), exist_ok=True)
+ with open(filename, "wt") as f:
obj = EclassDoc(path, sourced=True)
convert_func = getattr(obj, f"to_{options.format}")
f.write(convert_func())