[elbe-devel] [PATCH v4 4/5] Changes to preprocessor and add archive_tmpfile function

Akash Satamkar akash at linutronix.de
Wed Sep 18 12:17:21 CEST 2019


Changes to the preprocessor are addded in
_combinearchivedir.

Add archive_tmpfile function to archivedir, which was
previously in elbexml.

Signed-off-by: Akash Satamkar <akash at linutronix.de>
---
 elbepack/archivedir.py | 63 ++++++++++++++++++++++++++++++------------
 1 file changed, 46 insertions(+), 17 deletions(-)

diff --git a/elbepack/archivedir.py b/elbepack/archivedir.py
index 10155228..925aeb95 100644
--- a/elbepack/archivedir.py
+++ b/elbepack/archivedir.py
@@ -13,12 +13,14 @@ try:
 except ImportError:
     from urlparse import urljoin,urlparse
 
-from base64 import standard_b64encode
+from base64 import standard_b64encode, standard_b64decode
 from bz2 import compress as bz2compress
 from subprocess import CalledProcessError
-
+from tempfile import NamedTemporaryFile
 from elbepack.treeutils import etree
 from elbepack.shellhelper import system
+from elbepack.filesystem import TmpdirFilesystem
+
 
 class ArchivedirError(Exception):
     pass
@@ -67,6 +69,14 @@ def chg_archive(xml, path, keep):
 
     return xml
 
+
+def archive_tmpfile(arch_elem):
+    fp = NamedTemporaryFile()
+    fp.write(standard_b64decode(arch_elem))
+    fp.file.flush()
+    return fp
+
+
 def prepare_path(url):
     url = urlparse(url)
     path = url.geturl().replace("%s://"%url.scheme, '', 1)
@@ -90,32 +100,51 @@ def get_and_append_method(url):
         'file': get_and_append_local,
     }.get(urlparse(url).scheme, get_and_append_unknown)
 
-def _combinearchivedir(xml):
+def _combinearchivedir(xml, xpath, use_volume):
     elbexml = etree(None)
     elbexml.et = xml
 
-    archive = '.combinedarchive.tar'
-    for archivedir in xml.iterfind("archivedir"):
+    tmp = TmpdirFilesystem()
+    for archivedir in elbexml.all(xpath):
+
         try:
-            archiveurl = urljoin(archivedir.base, archivedir.text)
-            keep = elbexml.check_boolean(archivedir, "keep-attributes")
+            archiveurl = urljoin(archivedir.et.base, archivedir.et.text)
+            keep = archivedir.bool_attr("keep-attributes")
+            parent = archivedir.get_parent()
+
+            if use_volume:
+                volume_attr = archivedir.et.get('volume', default='all')
+                fname_suffix = volume_attr
+
+                arch = parent.node("archive[@volume='%s']" % volume_attr)
+
+                if arch is None:
+                    arch = parent.append("archive")
+                    arch.et.set("volume", volume_attr)
+
+            else:
+                arch = parent.ensure_child("archive")
+                fname_suffix = ''
+
+
             get_and_append = get_and_append_method(archiveurl)
-            get_and_append(archiveurl, archive, keep)
-            archivedir.getparent().remove(archivedir)
+
+            archname = tmp.fname('archive%s.tar.bz2' % fname_suffix)
+            get_and_append(archiveurl, archname, keep)
+            arch.set_text(enbase(archname, True))
+
+            parent.remove_child(archivedir)
         except (CalledProcessError, OSError):
             msg = "Failure while processing \"" + archivedir.text + "\":\n"
             msg += str(sys.exc_info()[1])
             raise ArchivedirError(msg)
 
-    arch = elbexml.ensure_child("archive")
-    arch.set_text(enbase(archive, True))
-
-    os.remove(archive)
-
-    return xml
 
 def combinearchivedir(xml):
-    if xml.find("archivedir") is None:
+    if xml.find("//archivedir") is None:
         return xml
 
-    return _combinearchivedir(xml)
+    _combinearchivedir(xml, "archivedir", False)
+    _combinearchivedir(xml, "src-cdrom/archivedir", True)
+
+    return xml
-- 
2.20.1




More information about the elbe-devel mailing list