[elbe-devel] [PATCH v2 2/6] elbexml: Handle mirror's options

Olivier Dion dion at linutronix.de
Tue Jul 21 17:13:02 CEST 2020


This also remove the global 'noauth'.  It should be passed as a
<option> tag instead for individual mirror.

Signed-off-by: Olivier Dion <dion at linutronix.de>
---
 elbepack/elbexml.py | 55 ++++++++++++++++++++++++++++++++-------------
 1 file changed, 39 insertions(+), 16 deletions(-)

diff --git a/elbepack/elbexml.py b/elbepack/elbexml.py
index 6496e442..577ac0b8 100644
--- a/elbepack/elbexml.py
+++ b/elbepack/elbexml.py
@@ -149,39 +149,62 @@ class ElbeXML(object):
 
     # XXX: maybe add cdrom path param ?
     def create_apt_sources_list(self, build_sources=False, initvm=True):
+
+        # pylint: disable=too-many-branches
+
         if self.prj is None:
             return "# No Project"
 
         if not self.prj.has("mirror") and not self.prj.has("mirror/cdrom"):
-            return "# no mirrors configured"
+            return "# No mirrors configured"
 
-        noauth = ""
-        if self.prj.has("noauth"):
-            noauth = "[trusted=yes] "
+        mirrors = []
 
-        mirror = ""
         if self.prj.has("mirror/primary_host"):
-            mirror += "deb " + noauth + self.get_primary_mirror(None)
-            mirror += " " + self.prj.text("suite") + " main\n"
+
+            if self.prj.has("mirror/options"):
+                poptions = "[ %s ]" % ' '.join([opt.et.text.strip(' \t\n')
+                                                for opt
+                                                in self.prj.all("mirror/options/option")])
+            else:
+                poptions = ""
+
+            pmirror = self.get_primary_mirror(None)
+            suite   = self.prj.text("suite")
+
+            mirrors.append("deb %s %s %s main" %
+                           (poptions, pmirror, suite))
 
             if build_sources:
-                mirror += "deb-src " + noauth + self.get_primary_mirror(None)
-                mirror += " " + self.prj.text("suite") + " main\n"
+                mirrors.append("deb-src %s %s %s main" %
+                               (poptions, pmirror, suite))
 
             if self.prj.has("mirror/url-list"):
+
                 for url in self.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 += "deb " + noauth + \
-                                   url.text("binary").strip() + "\n"
+                        bin_url = url.text("binary").strip()
+                        mirrors.append("deb %s %s" %
+                                       (options, bin_url))
+
                     if url.has("source"):
-                        mirror += "deb-src " + noauth + \
-                            url.text("source").strip() + "\n"
+                        src_url = url.text("source").strip()
+                        mirrors.append("deb-src %s %s" %
+                                       (options, src_url))
 
         if self.prj.has("mirror/cdrom"):
-            mirror += "deb copy:///cdrom/targetrepo %s main added\n" % (
-                self.prj.text("suite"))
+            mirrors.append("deb copy:///cdrom/targetrepo %s main added" %
+                           self.prj.text("suite"))
 
-        return replace_localmachine(mirror, initvm)
+        return replace_localmachine('\n'.join(mirrors), initvm)
 
     @staticmethod
     def validate_repo(r):
-- 
2.27.0



More information about the elbe-devel mailing list