[elbe-devel] [PATCH 4/7] Add implementation of 'finetuning/file' XML tag
Torben Hohn
torben.hohn at linutronix.de
Fri May 17 14:55:03 CEST 2019
On Fri, May 17, 2019 at 11:16:58AM +0200, dion at linutronix.de wrote:
> From: Olivier Dion <dion at linutronix.de>
>
> The implementation will ensure that the path to the destination
> exists by using 'mkdir_p'.
>
> The user can provide the attribute 'append="true"' if she wants to
> append to the destination instead of truncate it (the default).
>
> The user can also provide the attribute 'encoding'. If that's the
> case, the content of the XML tag is decode according to the type of
> encoding before written to the file. As for now, the only encoding
> supported are plain text (the default) and base64.
>
> The user can provide the attribute 'owner', 'group' or 'mode' to the
> XML tag, using the 'chown', 'chgrp' and 'chmod' syntaxes.
>
> NOTE!
> =====
> - Whitespaces/tabs are not trimmed from the XML tag
>
> - The 'owner' and 'group' attributes might stop the operation if the
> user or group doesn't exist. e.g. if the group doesn't exist and
> thus 'chgrp' failed, 'chmod' will never be done because of the
> exception throwed by Python
>
> - The whole operation can failed if destination is an existing
> directory
>
> Signed-off-by: Olivier Dion <dion at linutronix.de>
when this is folded with PATCH 3 ...
Reviewed-by: Torben Hohn <torben.hohn at linutronix.de>
I am not sure, how we want to handle whitespace at the end
of content.
maybe we need raw encoding and default to strip leading and trailing
whitespace ?
> ---
> elbepack/finetuning.py | 55 ++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 55 insertions(+)
>
> diff --git a/elbepack/finetuning.py b/elbepack/finetuning.py
> index 97342862..7f6c4a6b 100644
> --- a/elbepack/finetuning.py
> +++ b/elbepack/finetuning.py
> @@ -9,6 +9,8 @@
> from __future__ import print_function
>
> import os
> +import errno
> +import base64
>
> from shutil import rmtree
> from gpg import core
> @@ -344,6 +346,59 @@ class AddGroupAction(FinetuningAction):
> FinetuningAction.register(AddGroupAction)
>
>
> +class AddFileAction(FinetuningAction):
> +
> + tag = 'file'
> +
> + def __init__(self, node):
> + FinetuningAction.__init__(self, node)
> +
> + @staticmethod
> + def decode(text, encoding):
> + if encoding == "base64":
> + return base64.standard_b64decode(text)
> + else:
> + raise FinetuningException("Invalid encoding %s" % encoding)
> +
> + def execute(self, log, _buildenv, target):
> +
> + att = self.node.et.attrib
> + dst = att["dst"]
> + content = self.node.et.text
> + owner = None
> + group = None
> + mode = None
> +
> + if "owner" in att: owner = att["owner"]
> + if "group" in att: group = att["group"]
> + if "mode" in att: mode = att["mode"]
> +
> + try:
> + target.mkdir_p(os.path.dirname(dst))
> + except OSError as E:
> + if E.errno is not errno.EEXIST:
> + raise
> +
> + if "encoding" in att:
> + content = AddFileAction.decode(content, att["encoding"])
> +
> + if "append" in att and att["append"] == "true":
> + target.append_file(dst, content)
> + else:
> + target.write_file(dst, None, content)
> +
> + if owner is not None:
> + log.chroot(target.path, 'chown "%s" "%s"' % (owner, dst))
> +
> + if group is not None:
> + log.chroot(target.path, 'chgrp "%s" "%s"' % (group, dst))
> +
> + if mode is not None:
> + log.chroot(target.path, 'chmod "%s" "%s"' % (mode, dst))
> +
> +FinetuningAction.register(AddFileAction)
> +
> +
> class RawCmdAction(FinetuningAction):
>
> tag = 'raw_cmd'
> --
> 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.linutronix.de/pipermail/elbe-devel/attachments/20190517/adb1eb69/attachment.sig>
More information about the elbe-devel
mailing list