[elbe-devel] [PATCH 1/3] Use tar append to create archives
Benedikt Spranger
b.spranger at linutronix.de
Thu Jul 5 10:44:35 CEST 2018
The new element <archivedir> which will be introduced in the next patch
may occur multiple times to generate an archive from a set of different
directories.
The existing chg_archive implementation uses the "-j" flag while calling
tar to compress the archive. Compressed archives can not be extended, but
the upcoming <archivedir> feature depends on it.
Generating the 'tar' archive needs to be split up into two parts:
a) generating the archive (may be called multiple times; implented in
the collect function)
b) compressing the archive is not done with 'tar -j' but in python during
enbasing the .tar archive.
Signed-off-by: Benedikt Spranger <b.spranger at linutronix.de>
Reviewed-by: Manuel Traut <manut at linutronix.de>
---
elbepack/archivedir.py | 31 +++++++++++++++++++++----------
1 file changed, 21 insertions(+), 10 deletions(-)
diff --git a/elbepack/archivedir.py b/elbepack/archivedir.py
index 9b3b307a..5a363b81 100644
--- a/elbepack/archivedir.py
+++ b/elbepack/archivedir.py
@@ -6,15 +6,18 @@
import os
from base64 import standard_b64encode
+from bz2 import compress as bz2compress
from subprocess import check_call
from elbepack.treeutils import etree
-def enbase(fname):
+def enbase(fname, compress=True):
infile = file(fname, "r")
s = infile.read()
- enc = standard_b64encode(s)
+ if compress:
+ s = bz2compress(s)
+ enc = standard_b64encode(s)
splited = ""
i = 0
l_enc = len(enc)
@@ -24,20 +27,28 @@ def enbase(fname):
return splited
+def collect(tararchive, path, keep):
+ if keep:
+ cmd = 'tar rf ' + tararchive + ' -C '
+ else:
+ cmd = 'tar rf ' + tararchive + ' --owner=root --group=root -C '
+ cmd += path + ' .'
+ check_call(cmd, shell=True)
+
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 + ' .'
- check_call(cmd, shell=True)
+ archive = '.archive.tar'
+ if os.path.exists(archive):
+ os.remove(archive)
+
+ collect(archive, path, keep)
+ compress = True
else:
archive = path
+ compress = False
arch = xml.ensure_child("archive")
- arch.set_text(enbase(archive))
+ arch.set_text(enbase(archive, compress))
if os.path.isdir(path):
os.remove(archive)
--
2.18.0
More information about the elbe-devel
mailing list