[elbe-devel] [PATCH v3 4/6] xmlpreprocess: Add mirrors options preprocess rule
Bastian Germann
bage at linutronix.de
Mon Jul 27 15:12:52 CEST 2020
Am 23.07.20 um 18:31 schrieb Olivier Dion:
> When <noauth> is used, emit a warning and add the option 'trusted=yes'
> to all mirrors. Some binary mirrors contain embedded options in their
> URL. This is also handle by the preprocessor that will move these
handle -> handled
> option out of the URL and create proper option nodes for the mirror.
these option -> these options
>
> For now, the node <noauth> is not removed from the XML because some
> path still use 'prj.has("noauth")'. In the future, simply uncomment
path -> execution paths
> after the TODO to get rid of noauth for good.
>
> Signed-off-by: Olivier Dion <dion at linutronix.de>
> ---
> elbepack/xmlpreprocess.py | 86 +++++++++++++++++++++++++++++++++++++++
> 1 file changed, 86 insertions(+)
>
> diff --git a/elbepack/xmlpreprocess.py b/elbepack/xmlpreprocess.py
> index 93fca7b1..ec1be76d 100644
> --- a/elbepack/xmlpreprocess.py
> +++ b/elbepack/xmlpreprocess.py
> @@ -157,6 +157,90 @@ def preprocess_mirror_replacement(xml):
> 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>
> + to <option> tags.
> +
> + """
> +
> + # global noauth
> + for node in xml.iterfind(".//noauth"):
> + print("[WARN] <noauth> is deprecated. "
> + "Use <option>trusted=yes</option> instead.")
> +
> + parent = node.getparent()
> +
> + # Add trusted=yes to primary mirror
> + poptions = parent.find(".//mirror/options")
> + if poptions is None:
> + poptions = etree.Element("options")
> + parent.find(".//mirror").append(poptions)
> +
> + ptrusted = etree.Element("option")
> + ptrusted.text = "trusted=yes"
> + poptions.append(ptrusted)
> +
> + # Add trusted=yes to all secondary mirrors
> + for url in parent.iterfind(".//mirror/url-list/url"):
> + options = url.find("options")
> + if options is None:
> + options = etree.Element("options")
> + url.append(options)
> +
> + trusted = etree.Element("option")
> + trusted.text = "trusted=yes"
> + options.append(trusted)
> +
> + # TODO:old - Uncomment the following whenever there's no more
> + # prj.has("noauth") in Elbe. When this is done, also remove
> + # noauth from dbsfed.xsd
> + #
> + # parent.remove(node)
> +
> +
> + # binarie's options
binarie's -> binary's
> + for node in xml.iterfind(".//mirror/url-list/url/binary"):
> +
> + # Find [*]
> + has_option = False
> + for i in range(len(node.text)):
> +
> + if node.text[i] == '[':
> +
> + for j in range(i+1, len(node.text)):
> + if node.text[j] == ']':
> + has_option = True
> + break
> +
> + # And this is why goto are nice Guido van Rossum
Duh! Please remove this comment. We do not want to bloat elbe with such
stuff.
Why don't you use a regex (with group) for this?
Do the options only work for binary urls? I guess at least a subset
should also work for deb-src.
There is a aptsources.sourceslist.SourceEntry.mysplit. Why don't you use
this?
> + if has_option:
> + start = i
> + end = j
> + break
> +
> + if not has_option:
> + continue
> +
> + # For example: <binary> [arch=amd64] http://LOCALMACHINE/something </binary>
> +
> + # arch=amd64 ([] are not included here)
> + bin_opt = node.text[start+1:end]
> +
> + # http://LOCALMACHINE/something
> + node.text = node.text[:start] + node.text[end+1:]
> +
> + # No <options>? Create it
> + parent = node.getparent()
> + options = parent.find("options")
> + if options is None:
> + options = etree.Element("options")
> + parent.append(options)
> +
> + # Adding subelement <option>
> + option = etree.Element("option")
> + option.text = bin_opt
> + options.append(option)
>
> def xmlpreprocess(fname, output, variants=None, proxy=None):
>
> @@ -236,6 +320,8 @@ def xmlpreprocess(fname, output, variants=None, proxy=None):
>
> preprocess_initvm_ports(xml)
>
> + preprocess_mirrors(xml)
> +
> if schema.validate(xml):
> # if validation succedes write xml file
> xml.write(
>
More information about the elbe-devel
mailing list