| |
@@ -0,0 +1,157 @@
|
| |
+ # -*- encoding: utf-8 -*-
|
| |
+
|
| |
+ from __future__ import print_function
|
| |
+
|
| |
+ import argparse
|
| |
+ import os
|
| |
+ import sys
|
| |
+
|
| |
+ import productmd
|
| |
+
|
| |
+ REPO = """\
|
| |
+ [{name}]
|
| |
+ named = {name}
|
| |
+ baseurl = {baseurl}
|
| |
+ enabled = {enabled}
|
| |
+ gpgcheck = 0
|
| |
+ """
|
| |
+
|
| |
+ CONTENT_TYPES = {
|
| |
+ "repository": "-rpms",
|
| |
+ "debug_repository": "-debuginfo-rpms",
|
| |
+ "source_repository": "-source-rpms",
|
| |
+ }
|
| |
+
|
| |
+
|
| |
+ def translate(path, strip_prefix, url_prefix):
|
| |
+ """Remove prefix from path and replace it with url_prefix."""
|
| |
+ if not path.startswith(strip_prefix):
|
| |
+ raise RuntimeError("{0} does not start with {1}.".format(path, strip_prefix))
|
| |
+ return url_prefix + path[len(strip_prefix) :]
|
| |
+
|
| |
+
|
| |
+ def emit(compose, opts, variant, output, content_type="repository"):
|
| |
+ """Print configuration for a single repository into output."""
|
| |
+ paths = getattr(variant.paths, content_type)
|
| |
+ release = compose.info.release
|
| |
+ bp = compose.info.base_product
|
| |
+ name = opts.name_pattern.format(
|
| |
+ release_id=compose.info.release_id,
|
| |
+ release_short=compose.info.release.short,
|
| |
+ release_name=release.name,
|
| |
+ release_version=release.version,
|
| |
+ release_type=release.type,
|
| |
+ release_major_version=release.major_version,
|
| |
+ base_product_short=bp.short if release.is_layered else None,
|
| |
+ base_product_name=bp.name if release.is_layered else None,
|
| |
+ base_product_version=bp.version if release.is_layered else None,
|
| |
+ base_product_type=bp.type if release.is_layered else None,
|
| |
+ compose_id=compose.info.compose.id,
|
| |
+ compose_type=compose.info.compose.type,
|
| |
+ compose_date=compose.info.compose.date,
|
| |
+ compose_respin=compose.info.compose.respin,
|
| |
+ label=compose.info.compose.label,
|
| |
+ variant=variant.uid,
|
| |
+ arch=opts.arch,
|
| |
+ )
|
| |
+ name += CONTENT_TYPES[content_type]
|
| |
+ enabled = "1" if not opts.disabled or variant.uid not in opts.disabled else "0"
|
| |
+
|
| |
+ if opts.arch:
|
| |
+ if opts.arch not in paths:
|
| |
+ raise RuntimeError(
|
| |
+ "Variant {0} does not have arch {1}.".format(variant.uid, opts.arch)
|
| |
+ )
|
| |
+ url = paths[opts.arch]
|
| |
+ elif paths:
|
| |
+ arch, path = list(paths.items())[0]
|
| |
+ url = path.replace(arch, "$basearch")
|
| |
+ else:
|
| |
+ # No paths...
|
| |
+ return
|
| |
+
|
| |
+ baseurl = os.path.join(compose.compose_path, url)
|
| |
+ if opts.translate:
|
| |
+ baseurl = translate(baseurl, *opts.translate)
|
| |
+ else:
|
| |
+ baseurl = "file://" + baseurl
|
| |
+
|
| |
+ content = REPO.format(name=name, enabled=enabled, baseurl=baseurl)
|
| |
+ print(content, file=output)
|
| |
+
|
| |
+
|
| |
+ def run(opts, output):
|
| |
+ compose = productmd.Compose(os.path.realpath(opts.COMPOSE))
|
| |
+
|
| |
+ def by_uid(variant):
|
| |
+ return variant.uid
|
| |
+
|
| |
+ for variant in sorted(compose.info.variants.variants.values(), key=by_uid):
|
| |
+ if opts.variant and variant.uid not in opts.variant:
|
| |
+ # Variant is excluded
|
| |
+ continue
|
| |
+
|
| |
+ emit(compose, opts, variant, output)
|
| |
+ if opts.include_debuginfo:
|
| |
+ emit(compose, opts, variant, output, content_type="debug_repository")
|
| |
+
|
| |
+ if opts.include_source:
|
| |
+ emit(compose, opts, variant, output, content_type="source_repository")
|
| |
+
|
| |
+
|
| |
+ def parse_mapping(value):
|
| |
+ return value.split(",", 1)
|
| |
+
|
| |
+
|
| |
+ def main(args=None):
|
| |
+ parser = argparse.ArgumentParser()
|
| |
+ parser.add_argument("COMPOSE", help="Compose to work with.")
|
| |
+ parser.add_argument(
|
| |
+ "--arch", help="Hardcode given architecture instead of using $basearch."
|
| |
+ )
|
| |
+ parser.add_argument(
|
| |
+ "--include-debuginfo",
|
| |
+ action="store_true",
|
| |
+ help="Create entries for debuginfo repos as well.",
|
| |
+ )
|
| |
+ parser.add_argument(
|
| |
+ "--include-source",
|
| |
+ action="store_true",
|
| |
+ help="Create entries for source repos as well.",
|
| |
+ )
|
| |
+ parser.add_argument(
|
| |
+ "--variant",
|
| |
+ action="append",
|
| |
+ help="Include only these variants. May be used multiple times.",
|
| |
+ )
|
| |
+ parser.add_argument(
|
| |
+ "--disabled",
|
| |
+ metavar="VARIANT",
|
| |
+ action="append",
|
| |
+ help="Disable this variant by default. May be used multiple times.",
|
| |
+ )
|
| |
+ parser.add_argument(
|
| |
+ "-o",
|
| |
+ "--output",
|
| |
+ default="/dev/stdout",
|
| |
+ help="Path for output file. Defaults to stdout.",
|
| |
+ )
|
| |
+ parser.add_argument(
|
| |
+ "--translate",
|
| |
+ metavar="PATH_PREFIX,URL_PREFIX",
|
| |
+ help="How to generate URLs.",
|
| |
+ type=parse_mapping,
|
| |
+ )
|
| |
+ parser.add_argument(
|
| |
+ "--name-pattern",
|
| |
+ default="{release_short}-{release_version}-{variant}",
|
| |
+ help="Pattern for repository names.",
|
| |
+ )
|
| |
+ opts = parser.parse_args(args)
|
| |
+
|
| |
+ try:
|
| |
+ with open(opts.output, "w") as output:
|
| |
+ run(opts, output)
|
| |
+ except RuntimeError as exc:
|
| |
+ print(str(exc), file=sys.stderr)
|
| |
+ sys.exit(1)
|
| |