From 87c485f2d0dc26a8ae46bdc727d20520150a49d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Thu, 22 Jun 2017 16:42:29 +0200 Subject: [PATCH] comps_filter: Port to argparse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lubomír Sedlář --- bin/comps_filter | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/bin/comps_filter b/bin/comps_filter index a023fb82..0195a5e4 100755 --- a/bin/comps_filter +++ b/bin/comps_filter @@ -4,7 +4,7 @@ import sys import fnmatch -import optparse +import argparse import lxml.etree import re from io import StringIO @@ -151,30 +151,35 @@ class CompsFilter(object): def main(): - parser = optparse.OptionParser("%prog [options] ") - parser.add_option("--output", help="redirect output to a file") - parser.add_option("--arch", help="filter groups and packagews according to an arch") - parser.add_option("--arch-only-groups", default=False, action="store_true", help="keep only arch groups, remove the rest") - parser.add_option("--arch-only-packages", default=False, action="store_true", help="keep only arch packages, remove the rest") - parser.add_option("--remove-categories", default=False, action="store_true", help="remove all categories") - parser.add_option("--remove-langpacks", default=False, action="store_true", help="remove the langpacks section") - parser.add_option("--remove-translations", default=False, action="store_true", help="remove all translations") - parser.add_option("--remove-environments", default=False, action="store_true", help="remove all environment sections") - parser.add_option("--keep-empty-group", default=[], action="append", metavar="[GROUPID]", help="keep groups even if they are empty") - parser.add_option("--no-cleanup", default=False, action="store_true", help="don't remove empty groups and categories") - parser.add_option("--no-reindent", default=False, action="store_true", help="don't re-indent the output") + parser = argparse.ArgumentParser() + parser.add_argument("--output", help="redirect output to a file") + parser.add_argument("--arch", help="filter groups and packagews according to an arch") + 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") + 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") + 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') - opts, args = parser.parse_args() - - if len(args) != 1: - parser.error("please specify exactly one comps file") - - comps_file = args[0] + opts = parser.parse_args() if opts.arch is None: parser.error("please specify arch") - file_obj = open(comps_file, "r") + file_obj = open(opts.comps_file, "r") f = CompsFilter(file_obj, reindent=not opts.no_reindent) f.filter_packages(opts.arch, opts.arch_only_packages) f.filter_groups(opts.arch, opts.arch_only_groups)