[PATCH] main: https is a sane package source URL scheme

Brian C. Lane bcl at redhat.com
Thu Jul 31 20:39:17 UTC 2014


On Thu, Jul 31, 2014 at 03:41:08PM -0400, Colin Walters wrote:
> Not sure exactly why sanitize_repo() was written this way; annotate
> traces it to a rename from an earlier file and I was too lazy
> to go back farther.
> 
> Anyways, I want to use https, so rework this code to add it.
> ---
>  src/sbin/lorax | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 

> From 1080ba885b70ed89f875415806011fced3c5bc28 Mon Sep 17 00:00:00 2001
> From: Colin Walters <walters at verbum.org>
> Date: Thu, 31 Jul 2014 15:39:06 -0400
> Subject: [PATCH] main: https is a sane package source URL scheme
> 
> Not sure exactly why sanitize_repo() was written this way; annotate
> traces it to a rename from an earlier file and I was too lazy
> to go back farther.
> 
> Anyways, I want to use https, so rework this code to add it.
> ---
>  src/sbin/lorax | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/src/sbin/lorax b/src/sbin/lorax
> index 8dfd20f..8978a64 100755
> --- a/src/sbin/lorax
> +++ b/src/sbin/lorax
> @@ -214,13 +214,13 @@ def get_yum_base_object(installroot, repositories, mirrorlists=None,
>                          tempdir="/var/tmp", proxy=None, excludepkgs=None):
>  
>      def sanitize_repo(repo):
> +        """Convert bare paths to file:/// URIs, and silently reject protocols unhandled by yum"""
>          if repo.startswith("/"):
>              return "file://{0}".format(repo)
> -        elif (repo.startswith("http://") or repo.startswith("ftp://")
> -              or repo.startswith("file://")):
> +        c = repo.find('://')
> +        if c > 0 and repo[:c] in ('http', 'https', 'ftp', 'file'):
>              return repo
> -        else:
> -            return None
> +        return None
>  
>      mirrorlists = mirrorlists or []
>      excludepkgs = excludepkgs or []
> -- 
> 1.8.3.1
> 

I like the idea, but's that, umm, kinda ugly :)

elif any(repo.startswith(p) for p in ('http://', 'https://', 'ftp://', 'file'://)):

is more pythonic.

-- 
Brian C. Lane | Anaconda Team | IRC: bcl #anaconda | Port Orchard, WA (PST8PDT)


More information about the anaconda-patches mailing list