public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: claudius.heine.ext@siemens.com
To: isar-users@googlegroups.com
Cc: Claudius Heine <ch@denx.de>
Subject: [PATCH 1/1] isar-bootstrap: implement DISTRO_APT_PREMIRRORS feature
Date: Tue, 10 Apr 2018 12:33:12 +0200	[thread overview]
Message-ID: <20180410103312.26468-2-claudius.heine.ext@siemens.com> (raw)
In-Reply-To: <20180410103312.26468-1-claudius.heine.ext@siemens.com>

From: Claudius Heine <ch@denx.de>

With this patch its now possible to overwrite Debian repositories from
the 'APT_PREMIRRORS' variable.

The format of this variable is similar to how OpenEmbedded handels the
PREMIRROS variable:

    DISTRO_APT_PREMIRRORS = "source-uri-regex1    replace-uri-string1 \n \
                             source-uri-regex1    replace-uri-string2 \n \
                             ...
                            "

So for instance to select a different debian upstream mirror:

    DISTRO_APT_PREMIRRORS += "ftp\.(\S+\.)?debian.org  ftp.us.debian.org \n"

Signed-off-by: Claudius Heine <ch@denx.de>
---
 meta/recipes-core/isar-bootstrap/isar-bootstrap.bb | 50 +++++++++++++++++++---
 1 file changed, 44 insertions(+), 6 deletions(-)

diff --git a/meta/recipes-core/isar-bootstrap/isar-bootstrap.bb b/meta/recipes-core/isar-bootstrap/isar-bootstrap.bb
index a38dd88..3fbf890 100644
--- a/meta/recipes-core/isar-bootstrap/isar-bootstrap.bb
+++ b/meta/recipes-core/isar-bootstrap/isar-bootstrap.bb
@@ -83,7 +83,44 @@ def parse_aptsources_list_line(source_list_line):
 
     components = " ".join(s.split())
 
-    return type, options, source, suite, components
+    return [type, options, source, suite, components]
+
+def get_apt_source_mirror(d, aptsources_entry_list):
+    import re
+
+    premirrors = d.getVar('DISTRO_APT_PREMIRRORS', True) or ""
+    mirror_list = [entry.split()
+                  for entry in premirrors.split('\n')
+                  if any(entry)]
+
+    for regex, replace in mirror_list:
+        match = re.search(regex, aptsources_entry_list[2])
+
+        if match:
+            new_aptsources_entry_list = aptsources_entry_list.copy()
+            new_aptsources_entry_list[2] = re.sub(regex, replace,
+                                                  aptsources_entry_list[2],
+                                                  count = 1)
+            return new_aptsources_entry_list
+
+    return aptsources_entry_list
+
+def aggregate_aptsources_list(d, file_list, file_out):
+    import shutil
+
+    with open(file_out, "wb") as out_fd:
+        for entry in file_list:
+            entry_real = bb.parse.resolve_file(entry, d)
+            with open(entry_real, "r") as in_fd:
+                for line in in_fd:
+                    parsed = parse_aptsources_list_line(line)
+                    if parsed:
+                        parsed = get_apt_source_mirror(d, parsed)
+                        out_fd.write(" ".join(parsed).encode())
+                    else:
+                        out_fd.write(line.encode())
+                    out_fd.write("\n".encode())
+            out_fd.write("\n".encode())
 
 def get_distro_primary_source_entry(d):
     apt_sources_list = (d.getVar("DISTRO_APT_SOURCES", True) or "").split()
@@ -93,10 +130,10 @@ def get_distro_primary_source_entry(d):
             for line in in_fd:
                 parsed = parse_aptsources_list_line(line)
                 if parsed:
-                    type, _, source, suite, components = parsed
-                    if type == "deb":
-                        return source, suite, components
-    return "", "", ""
+                    parsed = get_apt_source_mirror(d, parsed)
+                    if parsed[0] == "deb":
+                        return parsed[2:]
+    return ["", "", ""]
 
 def get_distro_source(d):
     return get_distro_primary_source_entry(d)[0]
@@ -141,12 +178,13 @@ python do_apt_config_prepare() {
     apt_sources_out = d.getVar("APTSRCS", True)
     apt_sources_list = (d.getVar("DISTRO_APT_SOURCES", True) or "").split()
 
-    aggregate_files(d, apt_sources_list, apt_sources_out)
+    aggregate_aptsources_list(d, apt_sources_list, apt_sources_out)
 }
 addtask apt_config_prepare before do_build after do_generate_keyring
 
 do_bootstrap[stamp-extra-info] = "${DISTRO}-${DISTRO_ARCH}"
 do_bootstrap[vardeps] += "DISTRO_APT_SOURCES"
+do_bootstrap[vardeps] += "DISTRO_APT_PREMIRRORS"
 do_bootstrap() {
     if [ -e "${ROOTFSDIR}" ]; then
        sudo umount -l "${ROOTFSDIR}/dev" || true
-- 
2.16.3


      reply	other threads:[~2018-04-10 10:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-10 10:33 [PATCH 0/1] isar-bootstrap support for changing repo url claudius.heine.ext
2018-04-10 10:33 ` claudius.heine.ext [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180410103312.26468-2-claudius.heine.ext@siemens.com \
    --to=claudius.heine.ext@siemens.com \
    --cc=ch@denx.de \
    --cc=isar-users@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox