[elbe-devel] [PATCH RFC] Revert "xmlprepocess: search and replace urls based on ELBE_MIRROR_SED"

Thomas Weißschuh thomas.weissschuh at linutronix.de
Wed Jun 19 11:02:29 CEST 2024


The "mirror sed" feature is very specialised and
modifying the source XML based on environment variables is non-obvious.

If somebody needs this feature it can be easily implemented outside of
elbe, see contrib/replace-initvm-repository.py.

To simplify a future refactoring of the configuration handling,
drop the feature and its configuration.

This reverts commit 07179801530b15211fae77710a00348ada73d533.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/config.py                   |  4 ----
 elbepack/xmlpreprocess.py            | 34 ----------------------------------
 newsfragments/+mirrorsed.removal.rst |  1 +
 3 files changed, 1 insertion(+), 38 deletions(-)

diff --git a/elbepack/config.py b/elbepack/config.py
index 54a1603ee0d7..446a3549e160 100644
--- a/elbepack/config.py
+++ b/elbepack/config.py
@@ -16,7 +16,6 @@ class Config(dict):
         self['elbepass'] = 'foo'
         self['pbuilder_jobs'] = 'auto'
         self['initvm_domain'] = 'initvm'
-        self['mirrorsed'] = ''
 
         if 'ELBE_SOAPPORT' in os.environ:
             self['soapport'] = os.environ['ELBE_SOAPPORT']
@@ -42,8 +41,5 @@ class Config(dict):
         if 'ELBE_INITVM_DOMAIN' in os.environ:
             self['initvm_domain'] = os.environ['ELBE_INITVM_DOMAIN']
 
-        if 'ELBE_MIRROR_SED' in os.environ:
-            self['mirrorsed'] = os.environ['ELBE_MIRROR_SED']
-
 
 cfg = Config()
diff --git a/elbepack/xmlpreprocess.py b/elbepack/xmlpreprocess.py
index 6b6afdcf4e89..1392ebbd70ba 100644
--- a/elbepack/xmlpreprocess.py
+++ b/elbepack/xmlpreprocess.py
@@ -10,7 +10,6 @@ import subprocess
 import sys
 import tempfile
 import time
-from itertools import islice
 from optparse import OptionGroup
 from urllib.error import HTTPError, URLError
 from urllib.request import urlopen
@@ -217,37 +216,6 @@ def preprocess_proxy_add(xml, opt_proxy=None):
         mirror.append(proxy_e)
 
 
-def preprocess_mirror_replacement(xml):
-    """Do search and replace on mirror urls
-       The sed patterns are a space separate list
-       in cfg['mirrorsed']
-    """
-
-    ms = cfg['mirrorsed'].split()
-    if (len(ms) % 2) == 1:
-        raise XMLPreprocessError('Uneven number of (search, replace) Values !')
-
-    # now zip even and uneven elements of mirrorsed.split()
-    replacements = list(zip(islice(ms, 0, None, 2), islice(ms, 1, None, 2)))
-
-    # do the replace in the text nodes
-    victims = ['.//mirror/url-list/url/binary',
-               './/mirror/url-list/url/source',
-               './/mirror/url-list/url/key',
-               './/mirror/primary_host']
-
-    for v in victims:
-        for u in xml.iterfind(v):
-            for r in replacements:
-                u.text = u.text.replace(r[0], r[1])
-
-    # mirrorsite is special, because the url to be replaced is
-    # in the 'value' attrib
-    for u in xml.iterfind('//initvm/preseed/conf[@key="pbuilder/mirrorsite"]'):
-        for r in replacements:
-            u.attrib['value'] = u.attrib['value'].replace(r[0], r[1])
-
-
 def preprocess_mirrors(xml):
     """Insert a trusted=yes mirror option for all mirrors if <noauth> is
     present.  Also convert binary option <binary> [opts] url </binary>
@@ -418,8 +386,6 @@ def xmlpreprocess(xml_input_file, xml_output_file, variants=None, proxy=None, gz
         # handle archivedir elements
         xml = combinearchivedir(xml)
 
-        preprocess_mirror_replacement(xml)
-
         preprocess_proxy_add(xml, proxy)
 
         # Change public PGP url key to raw key
diff --git a/newsfragments/+mirrorsed.removal.rst b/newsfragments/+mirrorsed.removal.rst
new file mode 100644
index 000000000000..fae0f9eddc97
--- /dev/null
+++ b/newsfragments/+mirrorsed.removal.rst
@@ -0,0 +1 @@
+Drop `$ELBE_MIRROR_SED` support.

---
base-commit: 1c26a54d115b5072918f74a80e649687d4820e24
change-id: 20240619-mirrorsed-a925943fd27e

Best regards,
-- 
Thomas Weißschuh <thomas.weissschuh at linutronix.de>



More information about the elbe-devel mailing list