[elbe-devel] [PATCH v2 4/6] Add 'plain/raw' encodings for finetuning 'add <file>'

Torben Hohn torben.hohn at linutronix.de
Tue May 21 10:42:47 CEST 2019


On Fri, May 17, 2019 at 04:36:57PM +0200, dion at linutronix.de wrote:
> From: Olivier Dion <dion at linutronix.de>
> 
> Even though the default encoding is plain text, we should put the
> option 'encoding="plain"' if the user wants to be more explicit.  The
> plain encoding will strip any whitespaces/tabs from the XML tag.  It
> will also strip the first and last line of the tag.
> 
> Examples
> ========
> 
> ------------------------------------------------------------
> <file>
> 	Hello World!
> </file>
> ------------------------------------------------------------
> 
> will output as
> ------------------------------------------------------------
> "Hello World!"
> ------------------------------------------------------------
> 
> and
> ------------------------------------------------------------
> <file>
> 	Hello World!
> Foo
> </file>
> 
> will output as
> ------------------------------------------------------------
> "Hello World!\nFoo"
> ------------------------------------------------------------
> 
> As for'encoding="raw"', what you see is what you get.  Thus, nothing
> expected the first and last line of the tag are stripped.
> 
> Examples
> ========
> 
> ------------------------------------------------------------
> <file>
> 	Hello World!
> </file>
> ------------------------------------------------------------
> 
> will output as
> ------------------------------------------------------------
> "\tHello World!"
> ------------------------------------------------------------
> 
> and
> ------------------------------------------------------------
> <file>
> 	Hello World!
> Foo
> </file>
> ------------------------------------------------------------
> 
> will output as
> ------------------------------------------------------------
> "\tHello World!\nFoo"
> ------------------------------------------------------------
> 
> Signed-off-by: Olivier Dion <dion at linutronix.de>

Reviewed-by: Torben Hohn <torben.hohn at linutronix.de>

> ---
>  elbepack/finetuning.py | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/elbepack/finetuning.py b/elbepack/finetuning.py
> index 7f6c4a6b..b508397b 100644
> --- a/elbepack/finetuning.py
> +++ b/elbepack/finetuning.py
> @@ -355,20 +355,27 @@ class AddFileAction(FinetuningAction):
>  
>      @staticmethod
>      def decode(text, encoding):
> -        if encoding == "base64":
> -            return base64.standard_b64decode(text)
> +        if encoding == "plain":
> +            msg = "\n".join([line.lstrip(" \t") for line in text.splitlines()[1:-1]])
> +        elif encoding == "raw":
> +            msg = "\n".join(text.splitlines()[1:-1])
> +        elif encoding == "base64":
> +            msg = base64.standard_b64decode(text)
>          else:
>              raise FinetuningException("Invalid encoding %s" % encoding)
> +        return msg
>  
>      def execute(self, log, _buildenv, target):
>  
>          att = self.node.et.attrib
>          dst = att["dst"]
>          content = self.node.et.text
> +        encoding = "plain"
>          owner = None
>          group = None
>          mode = None
>  
> +        if "encoding" in att: encoding = att["encoding"]
>          if "owner" in att: owner = att["owner"]
>          if "group" in att: group = att["group"]
>          if "mode"  in att: mode  = att["mode"]
> @@ -379,8 +386,7 @@ class AddFileAction(FinetuningAction):
>              if E.errno is not errno.EEXIST:
>                  raise
>  
> -        if "encoding" in att:
> -            content = AddFileAction.decode(content, att["encoding"])
> +        content = AddFileAction.decode(content, encoding)
>  
>          if "append" in att and att["append"] == "true":
>              target.append_file(dst, content)
> -- 
> 2.21.0
> 
> 
> _______________________________________________
> elbe-devel mailing list
> elbe-devel at linutronix.de
> https://lists.linutronix.de/mailman/listinfo/elbe-devel

-- 
Torben Hohn
Linutronix GmbH | Bahnhofstrasse 3 | D-88690 Uhldingen-Mühlhofen
Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99

Hinweise zum Datenschutz finden Sie hier (Informations on data privacy 
can be found here): https://linutronix.de/kontakt/Datenschutz.php

Linutronix GmbH | Firmensitz (Registered Office): Uhldingen-Mühlhofen | 
Registergericht (Registration Court): Amtsgericht Freiburg i.Br., HRB700 
806 | Geschäftsführer (Managing Directors): Heinz Egger, Thomas Gleixner



More information about the elbe-devel mailing list