2015-11-25 15:14:35 +00:00
|
|
|
#!/usr/bin/env python
|
2015-06-05 18:40:58 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
|
|
import sys
|
2017-06-22 14:42:29 +00:00
|
|
|
import argparse
|
2015-06-05 18:40:58 +00:00
|
|
|
|
2018-04-06 07:17:51 +00:00
|
|
|
from pungi.wrappers.comps import CompsFilter
|
2015-06-05 18:40:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2017-06-22 14:42:29 +00:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument("--output", help="redirect output to a file")
|
2017-06-29 12:51:15 +00:00
|
|
|
parser.add_argument("--arch", required=True,
|
|
|
|
help="filter groups and packages according to an arch")
|
2017-06-22 14:42:29 +00:00
|
|
|
parser.add_argument("--arch-only-groups", default=False, action="store_true",
|
|
|
|
help="keep only arch groups, remove the rest")
|
|
|
|
parser.add_argument("--arch-only-packages", default=False, action="store_true",
|
|
|
|
help="keep only arch packages, remove the rest")
|
2017-06-29 10:46:57 +00:00
|
|
|
parser.add_argument("--arch-only-environments", default=False, action="store_true",
|
|
|
|
help="keep only arch environments, remove the rest")
|
2017-06-22 14:42:29 +00:00
|
|
|
parser.add_argument("--remove-categories", default=False, action="store_true",
|
|
|
|
help="remove all categories")
|
|
|
|
parser.add_argument("--remove-langpacks", default=False, action="store_true",
|
|
|
|
help="remove the langpacks section")
|
|
|
|
parser.add_argument("--remove-translations", default=False, action="store_true",
|
|
|
|
help="remove all translations")
|
|
|
|
parser.add_argument("--remove-environments", default=False, action="store_true",
|
|
|
|
help="remove all environment sections")
|
|
|
|
parser.add_argument("--keep-empty-group", default=[], action="append", metavar="GROUPID",
|
|
|
|
help="keep groups even if they are empty")
|
2018-11-02 11:43:56 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--lookaside-group",
|
|
|
|
default=[],
|
|
|
|
action="append",
|
|
|
|
metavar="GROUPID",
|
|
|
|
help="keep this group in environments even if they are not defined in the comps",
|
|
|
|
)
|
2017-06-22 14:42:29 +00:00
|
|
|
parser.add_argument("--no-cleanup", default=False, action="store_true",
|
|
|
|
help="don't remove empty groups and categories")
|
|
|
|
parser.add_argument("--no-reindent", default=False, action="store_true",
|
|
|
|
help="don't re-indent the output")
|
|
|
|
parser.add_argument("comps_file", metavar='COMPS_FILE')
|
2018-04-09 12:55:24 +00:00
|
|
|
parser.add_argument('--variant',
|
|
|
|
help='filter groups and packages according to variant name')
|
2017-06-22 14:42:29 +00:00
|
|
|
|
|
|
|
opts = parser.parse_args()
|
2015-06-05 18:40:58 +00:00
|
|
|
|
2017-08-24 13:01:33 +00:00
|
|
|
with open(opts.comps_file, "rb") as file_obj:
|
|
|
|
f = CompsFilter(file_obj, reindent=not opts.no_reindent)
|
2018-04-09 12:55:24 +00:00
|
|
|
f.filter_packages(opts.arch, opts.variant, opts.arch_only_packages)
|
|
|
|
f.filter_groups(opts.arch, opts.variant, opts.arch_only_groups)
|
|
|
|
f.filter_environments(opts.arch, opts.variant, opts.arch_only_environments)
|
2015-06-05 18:40:58 +00:00
|
|
|
|
|
|
|
if not opts.no_cleanup:
|
2018-11-02 11:43:56 +00:00
|
|
|
f.cleanup(opts.keep_empty_group, opts.lookaside_group)
|
2015-06-05 18:40:58 +00:00
|
|
|
|
|
|
|
if opts.remove_categories:
|
|
|
|
f.remove_categories()
|
|
|
|
|
|
|
|
if opts.remove_langpacks:
|
|
|
|
f.remove_langpacks()
|
|
|
|
|
|
|
|
if opts.remove_translations:
|
|
|
|
f.remove_translations()
|
|
|
|
|
|
|
|
if opts.remove_environments:
|
|
|
|
f.remove_environments()
|
|
|
|
|
2017-08-24 13:01:33 +00:00
|
|
|
f.write(open(opts.output, 'wb') if opts.output else sys.stdout)
|
2015-06-05 18:40:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|