[elbe-devel] [PATCH v3 3/6] pbuilder: Handle mirror's options

Bastian Germann bage at linutronix.de
Mon Jul 27 14:39:25 CEST 2020


Am 23.07.20 um 18:31 schrieb Olivier Dion:
> This is still a big mess, but I think it's more readable now.
> 
> get_apt_mirrors_and_keys() will return a tuple where the first element is a
> a list of mirrors to write to /etc/apt/sources.list and the second element is a
> list of GPG keys to import by apt.

import -> be imported

> Signed-off-by: Olivier Dion <dion at linutronix.de>

With the suggested change:
Reviewed-by: Bastian Germann <bage at linutronix.de>

> ---
>  elbepack/pbuilder.py | 100 +++++++++++++++++++++++++------------------
>  1 file changed, 59 insertions(+), 41 deletions(-)
> 
> diff --git a/elbepack/pbuilder.py b/elbepack/pbuilder.py
> index fe90f3d1..f08bd646 100644
> --- a/elbepack/pbuilder.py
> +++ b/elbepack/pbuilder.py
> @@ -12,6 +12,8 @@ try:
>  except ImportError:
>      from urllib2 import urlopen
>  
> +from elbepack.filesystem import Filesystem
> +
>  def pbuilder_write_config(builddir, xml, noccache):
>      distname = xml.prj.text('suite')
>      pbuilderrc_fname = os.path.join(builddir, "pbuilderrc")
> @@ -126,22 +128,13 @@ def pbuilder_write_apt_conf(builddir, xml):
>      fp.write('Aptitude::CmdLine::Ignore-Trust-Violations "true";\n')
>      fp.close()
>  
> -
> -def mirror_script_add_key_text(mirror, key_text):
> -    mirror += "cat << EOF | apt-key add -\n"
> -    mirror += key_text + "\n"
> -    mirror += "EOF\n"
> -
> -    return mirror
> -
> -
> -def mirror_script_add_key_url(mirror, key_url):
> +def mirror_script_add_key_url(key_url):
>      key_url = key_url.replace("LOCALMACHINE", "10.0.2.2")
>      key_conn = urlopen(key_url, None, 10)
>      key_text = key_conn.read()
>      key_conn.close()
>  
> -    return mirror_script_add_key_text(mirror, key_text)
> +    return key_text
>  
>  
>  def pbuilder_write_repo_hook(builddir, xml, cross):
> @@ -154,50 +147,75 @@ def pbuilder_write_repo_hook(builddir, xml, cross):
>      with open(os.path.join(pbuilder_hook_dir, "H10elbe_apt_update"), "w") as f:
>          f.write("#!/bin/sh\napt update\n")
>  
> -    fp = open(os.path.join(pbuilder_hook_dir, "G10elbe_apt_sources"), "w")
> +    with open(os.path.join(pbuilder_hook_dir, "G10elbe_apt_sources"), "w") as f:
> +
> +        mirrors, keys = get_apt_mirrors_and_keys(builddir, xml, cross)
> +
> +        f.write("#!/bin/sh\n")
> +
> +        # cat reads from stdin (-) and redirect (>) to
> +        # /etc/apt/sources.list
> +        f.write("cat -> /etc/apt/sources.list <<EOF\n%s\nEOF\n" %
> +                '\n'.join(mirrors).replace("LOCALMACHINE", "10.0.2.2"))
> +
> +        for key in keys:
> +            f.write("cat << EOF | apt-key add -\n%s\nEOF\n" % key)
> +
> +        f.write("apt-get update\n")
> +
> +def get_apt_mirrors_and_keys(builddir, xml, _cross):
>  
>      if xml.prj is None:
> -        return "# No Project"
> +        return (["# No Project"], [])
>  
>      if not xml.prj.has("mirror") and not xml.prj.has("mirror/cdrom"):
> -        return "# no mirrors configured"
> +        return (["# No mirrors configured"], [])
>  
> -    mirror = "#!/bin/sh\n"
> +    suite = xml.prj.text("suite")
>  
> -    mirror += 'echo "deb http://127.0.0.1:8080' + builddir + '/repo ' + \
> -        xml.prj.text("suite") + ' main" > /etc/apt/sources.list\n'
> +    local_http = "deb http://127.0.0.1:8080%s/repo %s main" % (builddir, suite)
>  
> -    mirror = mirror_script_add_key_url(
> -        mirror,
> -        'http://127.0.0.1:8080' +
> -        builddir +
> -        '/repo/repo.pub')
> +    mirrors = [local_http]
> +    keys    = [Filesystem(builddir).read_file("repo/repo.pub")]
> +    suite   = xml.prj.text("suite")
>  
>      if xml.prj.has("mirror/primary_host"):
> -        mirror += 'echo "deb ' + xml.get_primary_mirror(None) + ' ' + \
> -                  xml.prj.text("suite") + ' main" >> /etc/apt/sources.list\n'
> +
> +        if xml.prj.has("mirror/options"):
> +            poptions = "[%s]" % ' '.join([opt.et.text.strip(' \t\n')
> +                                          for opt
> +                                          in xml.prj.all("mirror/options/option")])
> +        else:
> +            poptions = ""
> +
> +        pmirror = xml.get_primary_mirror(None)
> +
> +        mirrors.append("deb %s %s %s main" % (poptions, pmirror, suite))
>  
>          if xml.prj.has("mirror/url-list"):
> -            noauth = ""
> -            if xml.prj.has("noauth"):
> -                noauth = "[trusted=yes] "
> +
>              for url in xml.prj.node("mirror/url-list"):
> +
> +                if url.has("options"):
> +                    options = "[%s]" % ' '.join([opt.et.text.strip(' \t\n')
> +                                                 for opt
> +                                                 in url.all("options/option")])
> +                else:
> +                    options = ""
> +
>                  if url.has("binary"):
> -                    mirror += 'echo "deb ' + noauth + \
> -                              url.text("binary").strip() + \
> -                              '" >> /etc/apt/sources.list\n'
> -                if url.has("raw-key") and not xml.prj.has("noauth"):
> -                    key = "\n".join(line.strip(" \t") for line in url.text('raw-key').splitlines()[1:-1])
> -                    mirror = mirror_script_add_key_text(mirror, key)
> +                    bin_url = url.text("binary").strip()
> +                    mirrors.append("deb %s %s" % (options, bin_url))
>  
> -    if xml.prj.has("mirror/cdrom"):
> -        mirror += 'echo "deb copy:///cdrom/targetrepo %s main added" >> ' \
> -                  '/etc/apt/sources.list' % (xml.prj.text("suite"))
> +                if url.has("raw-key") and not "trusted=yes" in options:
>  
> -    mirror += 'apt-get update\n'
> -    mirror = mirror.replace("LOCALMACHINE", "10.0.2.2")
> +                    key = "\n".join(line.strip(" \t")
> +                                    for line
> +                                    in url.text('raw-key').splitlines()[1:-1])
>  
> -    fp.write(mirror)
> -    fp.close()
> +                    keys.append(key)
> +
> +    if xml.prj.has("mirror/cdrom"):
> +        mirrors.append("deb copy:///cdrom/targetrepo %s main added" % suite)
>  
> -    return ""
> +    return (mirrors, keys)
> 


More information about the elbe-devel mailing list