[PATCH 1/2] Add the -A option to makeupdates to allow easy extraction of multiple RPMs

Anne Mulhern amulhern at redhat.com
Mon Feb 2 14:25:35 UTC 2015






----- Original Message -----
> From: "Vratislav Podzimek" <vpodzime at redhat.com>
> To: anaconda-patches at lists.fedorahosted.org
> Sent: Sunday, February 1, 2015 7:21:15 PM
> Subject: [PATCH 1/2] Add the -A option to makeupdates to allow easy extraction	of multiple RPMs
> 
> This is very useful if we need to test a new version of some tool/library
> that
> has multiple RPMs (as e.g. libblockdev with all its plugins).
> 
> Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
> ---
>  scripts/makeupdates | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/scripts/makeupdates b/scripts/makeupdates
> index ab420e3..0c8195a 100755
> --- a/scripts/makeupdates
> +++ b/scripts/makeupdates
> @@ -978,6 +978,10 @@ def main():
>                          dest='add_rpms', metavar='PATH_TO_RPM', default=[],
>                          help='add contents of RPMs to the updates image')
>  
> +    parser.add_argument('-A', '--add-dir-rpms', action='append', type=str,
> nargs='+',
> +                        dest='add_dir_rpms', metavar='PATH_TO_RPM_DIR',
> default=[],
> +                        help='add contents of RPMs from the directory to the
> updates image')
> +
>      parser.add_argument('-f', '--fetch', action='store', type=str,
>      metavar="ARCH",
>                          help='autofetch new dependencies from Koji for
>                          ARCH')
>  
> @@ -1025,6 +1029,21 @@ def main():
>      if args.po:
>          copyTranslations(updates, cwd, builddir)
>  
> +    if args.add_dir_rpms:
> +        # as using -A or --add-dir-rpms mutltiple times adds a new list to
> the
> +        # list instead of extending the original list, we need to
> "normalize" to
> +        # a one-level list of strings
> +        rpm_dirs = []
> +        for item in args.add_dir_rpms:
> +            if isinstance(item, list):
> +                rpm_dirs.extend(item)
> +            else:
> +                rpm_dirs.append(item)
> +

This duplicates the code for add_rpms, but that code is incorrect in treating
the add_rpms list as if it might be heterogenous; its only elements are lists.

>>> z = arser.parse_args("--add rpm1 --add rpm2 --add rpm3 rpm4 rpm5".split())
>>> z.add_rpms
[['rpm1'], ['rpm2'], ['rpm3', 'rpm4', 'rpm5']]

So both lists can be flattened a lot more simply, like below.

>>> [r for l in z.add_rpms for r in l]
['rpm1', 'rpm2', 'rpm3', 'rpm4', 'rpm5']

The _really_ proper thing would be to define a custom Action to use instead of
append, something like:

class Extend(argparse.Action):

     def __call__(self, parser, namespace, values, option_string=None):
         setattr(namespace, self.dest, getattr(namespace, self.dest) + values)

I think, and use it for both add_rpms and add_rpm_dirs.
 
It almost seems like an extend action should be part of argparse package;
I'm trying out an RFE on Python bugs.

> +        # and now add the RPMs from all the dirs to the list of RPMs to add
> +        for dir_path in rpm_dirs:
> +            args.add_rpms.extend(glob.glob(os.path.join(dir_path, "*.rpm")))
> +
>      if args.add_rpms:
>          # as using -a or --add mutltiple times
>          # adds a new list to the list instead of extending the
> --
> 2.1.0
> 
> _______________________________________________
> anaconda-patches mailing list
> anaconda-patches at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
> 

- mulhern



More information about the anaconda-patches mailing list