[elbe-devel] [PATCH v2 2/3] preprocess: extend variant management functionality
Manuel Traut
manuel.traut at linutronix.de
Fri Dec 22 10:14:51 CET 2017
On Thu, Dec 21, 2017 at 07:09:46PM +0100, Manuel Traut wrote:
> It is not possible to use multiple sections with variant attributes like this:
>
> <pkg-list variant='audio>
> <pkg>alsa</pkg>
> <pkg>pavucontrol</pkg>
> </pkg-list>
> <pkg-list variant='video>
> <pkg>totem</pkg>
> <pkg>ffmpeg</pkg>
> </pkg-list>
>
> It will work, if just --variant=audio OR --variant=video is used, but if
> --variant=audio,video is specified it results in two <pkg-list> sections
> and that's not allowed by dbsfed.xsd.
>
> Allow defining mergeable sections (hardcoded in elbepack/xmlpreprocess.py) and
> if one of these sections occure multiple times the contents are merged
> into a single section.
This breaks rebuilding from bin-cdrom.iso !
If there is a XML with initvm and target section, it's not OK to merge e.g.
the pkg-list of the initvm with the pkg-list of the target. But this is was
actually happens with this code.
> Signed-off-by: Manuel Traut <manut at linutronix.de>
> ---
> elbepack/xmlpreprocess.py | 24 ++++++++++++++++++++++++
> 1 file changed, 24 insertions(+)
>
> diff --git a/elbepack/xmlpreprocess.py b/elbepack/xmlpreprocess.py
> index 8e4c190e..208f2da8 100644
> --- a/elbepack/xmlpreprocess.py
> +++ b/elbepack/xmlpreprocess.py
> @@ -8,6 +8,11 @@ from lxml import etree
> from lxml.etree import XMLParser, parse
> from numpy import intersect1d
>
> +# dictionary of sections that are allowed to exists multiple times before
> +# preprocess and that childrens are merge into one section during finetuning
> +mergetags = {'finetuning': [],
> + 'pkg-list': []}
> +
>
> class XMLPreprocessError(Exception):
> def __init__(self, message):
> @@ -42,11 +47,30 @@ def xmlpreprocess(fname, output, variants=[]):
> # specified remove the tag
> else:
> rmlist.append(tag)
> + # remember mergeable sections, sections that are deleted soon don't
> + # need to be remembered
> + if tag.tag in mergetags.keys() and tag not in rmlist:
> + mergetags[tag.tag].append(tag)
>
> # postponed tag deletion
> for tag in rmlist:
> tag.getparent().remove(tag)
>
> + # if there are multiple sections because of sth like '<finetuning
> + # variant='A'> ... and <finetuning variant='B'> and running preprocess
> + # with --variant=A,B the two sections need to be merged
> + for mergetag in mergetags.keys():
> + # if there is just one section of a type nothing needs to be done
> + if len(mergetags[mergetag]) < 2:
> + continue
> + # append all childrens of section[1..n] to section[0] and delete
> + # section[1..n]
> + for section in mergetags[mergetag]:
> + if section != mergetags[mergetag][0]:
> + for child in section.getchildren():
> + mergetags[mergetag][0].append(child)
> + section.getparent().remove(section)
> +
> if schema.validate(xml):
> xml.write(
> output,
> --
> 2.15.1
>
More information about the elbe-devel
mailing list