[elbe-devel] [PATCH] Split out change archive functionality
Manuel Traut
manut at linutronix.de
Tue Jun 19 15:56:08 CEST 2018
On Tue, Jun 19, 2018 at 03:55:00PM +0200, Manuel Traut wrote:
> From: Benedikt Spranger <b.spranger at linutronix.de>
>
> The new <archivedir> feature has common task equal to chg_archive.
> This preperatory patch split out the change archive functionality from
> the chg_archive command into a module.
>
> Signed-off-by: Benedikt Spranger <b.spranger at linutronix.de>
> Signed-off-by: Manuel Traut <manut at linutronix.de>
integrated into devel/elbe-3.0
> ---
> debian/python-elbe-common.install | 1 +
> debian/python3-elbe-common.install | 1 +
> elbepack/archivedir.py | 42 ++++++++++++++++++++++++++++++
> elbepack/commands/chg_archive.py | 36 ++-----------------------
> 4 files changed, 46 insertions(+), 34 deletions(-)
> create mode 100644 elbepack/archivedir.py
>
> diff --git a/debian/python-elbe-common.install b/debian/python-elbe-common.install
> index 00757619..bc9f72e4 100644
> --- a/debian/python-elbe-common.install
> +++ b/debian/python-elbe-common.install
> @@ -8,6 +8,7 @@
> ./usr/lib/python2.*/*-packages/elbepack/__init__.py
> ./usr/lib/python2.*/*-packages/elbepack/commands/__init__.py
> ./usr/lib/python2.*/*-packages/elbepack/aptprogress.py
> +./usr/lib/python2.*/*-packages/elbepack/archivedir.py
> ./usr/lib/python2.*/*-packages/elbepack/config.py
> ./usr/lib/python2.*/*-packages/elbepack/default-preseed.xml
> ./usr/lib/python2.*/*-packages/elbepack/directories.py
> diff --git a/debian/python3-elbe-common.install b/debian/python3-elbe-common.install
> index 1c94cd3b..acd52e1c 100644
> --- a/debian/python3-elbe-common.install
> +++ b/debian/python3-elbe-common.install
> @@ -8,6 +8,7 @@
> ./usr/lib/python3.*/*-packages/elbepack/__init__.py
> ./usr/lib/python3.*/*-packages/elbepack/commands/__init__.py
> ./usr/lib/python3.*/*-packages/elbepack/aptprogress.py
> +./usr/lib/python3.*/*-packages/elbepack/archivedir.py
> ./usr/lib/python3.*/*-packages/elbepack/config.py
> ./usr/lib/python3.*/*-packages/elbepack/default-preseed.xml
> ./usr/lib/python3.*/*-packages/elbepack/directories.py
> diff --git a/elbepack/archivedir.py b/elbepack/archivedir.py
> new file mode 100644
> index 00000000..833e1526
> --- /dev/null
> +++ b/elbepack/archivedir.py
> @@ -0,0 +1,42 @@
> +# ELBE - Debian Based Embedded Rootfilesystem Builder
> +# Copyright (c) 2018 Benedikt Spranger <b.spranger at linutronix.de>
> +#
> +# SPDX-License-Identifier: GPL-3.0-or-later
> +
> +import os
> +
> +from base64 import standard_b64encode
> +from elbepack.treeutils import etree
> +
> +def enbase(fname):
> + infile = file(fname, "r")
> + s = infile.read()
> + enc = standard_b64encode(s)
> +
> + splited = ""
> + i = 0
> + l_enc = len(enc)
> + while i < l_enc:
> + splited += (enc[i:i + 60] + "\n")
> + i += 60
> +
> + return splited
> +
> +def chg_archive(xml, path, keep):
> + if os.path.isdir(path):
> + archive = '.archive.tbz'
> + if keep:
> + cmd = 'tar cfj .archive.tbz -C '
> + else:
> + cmd = 'tar cjf .archive.tbz --owner=root --group=root -C '
> + cmd += path + ' .'
> + os.system(cmd)
> + else:
> + archive = path
> + arch = xml.ensure_child("archive")
> + arch.set_text(enbase(archive))
> +
> + if os.path.isdir(path):
> + os.remove(archive)
> +
> + return xml
> diff --git a/elbepack/commands/chg_archive.py b/elbepack/commands/chg_archive.py
> index 90cc9732..dc4dcdd5 100644
> --- a/elbepack/commands/chg_archive.py
> +++ b/elbepack/commands/chg_archive.py
> @@ -8,27 +8,10 @@ from __future__ import print_function
> import sys
> import os
>
> -from base64 import standard_b64encode
> -
> +from elbepack.archivedir import chg_archive
> from elbepack.treeutils import etree
> from optparse import OptionParser
>
> -
> -def enbase(fname):
> - infile = file(fname, "r")
> - s = infile.read()
> - enc = standard_b64encode(s)
> -
> - splited = ""
> - i = 0
> - l_enc = len(enc)
> - while i < l_enc:
> - splited += (enc[i:i + 60] + "\n")
> - i += 60
> -
> - return splited
> -
> -
> def run_command(argv):
>
> oparser = OptionParser(
> @@ -55,20 +38,8 @@ def run_command(argv):
> print("Error reading xml file!")
> sys.exit(20)
>
> - if os.path.isdir(args[1]):
> - archive = '.archive.tbz'
> - if opt.keep_attributes:
> - cmd = 'tar cfj .archive.tbz -C '
> - else:
> - cmd = 'tar cjf .archive.tbz --owner=root --group=root -C '
> - cmd += args[1] + ' .'
> - os.system(cmd)
> - else:
> - archive = args[1]
> -
> try:
> - arch = xml.ensure_child("archive")
> - arch.set_text(enbase(archive))
> + xml = chg_archive(xml, args[1], opt.keep_attributes)
> except BaseException:
> print("Error reading archive")
> sys.exit(20)
> @@ -78,6 +49,3 @@ def run_command(argv):
> except BaseException:
> print("Unable to write new xml file")
> sys.exit(20)
> -
> - if os.path.isdir(args[1]):
> - os.remove(archive)
> --
> 2.17.1
>
More information about the elbe-devel
mailing list