[PATCH] Add variable substitution to DNF (#1164803)

Vratislav Podzimek vpodzime at redhat.com
Wed Dec 10 07:49:53 UTC 2014


On Tue, 2014-12-09 at 16:35 -0800, Brian C. Lane wrote:
> Add support for $releasever and $basearch in the kickstart url and repo
> commands when using dnf.
> ---
>  pyanaconda/packaging/dnfpayload.py | 26 +++++++++++++++++++++++---
>  1 file changed, 23 insertions(+), 3 deletions(-)
> 
> diff --git a/pyanaconda/packaging/dnfpayload.py b/pyanaconda/packaging/dnfpayload.py
> index 2d4a151..8e3246a 100644
> --- a/pyanaconda/packaging/dnfpayload.py
> +++ b/pyanaconda/packaging/dnfpayload.py
> @@ -22,6 +22,7 @@
>  import os
>  
>  from blivet.size import Size
> +import blivet.arch
>  from pyanaconda.flags import flags
>  from pyanaconda.i18n import _
>  from pyanaconda.progress import progressQ
> @@ -196,6 +197,25 @@ class DNFPayload(packaging.PackagePayload):
>          super(DNFPayload, self).unsetup()
>          self._base = None
>  
> +    def _replace_vars(self, url):
> +        """ Replace url variables with their values
> +
> +            :param url: url string to do replacement on
> +            :type url:  string
> +            :returns:   string with variables substituted
> +            :rtype:     string or None
> +
> +            Currently supports $releasever and $basearch
> +        """
> +        if not url:
> +            return url
> +
> +        url = url.replace("$releasever", self._base.conf.releasever)
> +        url = url.replace("$basearch", blivet.arch.getArch())
> +
> +        return url
> +
> +
>      def _add_repo(self, ksrepo):
>          """Add a repo to the dnf repo object
>  
> @@ -204,8 +224,8 @@ class DNFPayload(packaging.PackagePayload):
>             :returns: None
>          """
>          repo = dnf.repo.Repo(ksrepo.name, DNF_CACHE_DIR)
> -        url = ksrepo.baseurl
> -        mirrorlist = ksrepo.mirrorlist
> +        url = self._replace_vars(ksrepo.baseurl)
> +        mirrorlist = self._replace_vars(ksrepo.mirrorlist)
>          if url:
>              repo.baseurl = [url]
>          if mirrorlist:
> @@ -220,7 +240,7 @@ class DNFPayload(packaging.PackagePayload):
>          except dnf.exceptions.RepoError as e:
>              raise packaging.MetadataError(e)
>  
> -        log.info("added repo: '%s'", ksrepo.name)
> +        log.info("added repo: '%s' - %s", ksrepo.name, url or mirrorlist)
I thought you guys hate this "Perl style" ;) ACK.

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list