[elbe-devel] [PATCH v2 10/24] run virtapt in a forked process
Manuel Traut
manut at linutronix.de
Thu Feb 8 14:16:56 CET 2018
virtapt uses libapt (via python-apt). In libapt settings are stored in
global variables (path to apt cache, suite, arch, ..).
To ensure to work with well defined settings host each virtapt instance in a
seperate process.
Also improve the warnings that are printed if python-apt is missing on
the system.
Signed-off-by: Manuel Traut <manut at linutronix.de>
---
elbepack/pkgutils.py | 61 ++++++++-----------------------------------------
elbepack/rpcaptcache.py | 11 +++++++++
elbepack/virtapt.py | 54 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 75 insertions(+), 51 deletions(-)
diff --git a/elbepack/pkgutils.py b/elbepack/pkgutils.py
index 5ba1fb16..e062396e 100644
--- a/elbepack/pkgutils.py
+++ b/elbepack/pkgutils.py
@@ -34,10 +34,11 @@ from tempfile import mkdtemp
from elbepack.shellhelper import CommandError, system
try:
- from elbepack import virtapt
from apt_pkg import TagFile
+ from elbepack.rpcaptcache import get_virtaptcache
virtapt_imported = True
-except ImportError:
+except ImportError as e:
+ print(e)
print("WARNING - python-apt not available:")
print("If there are multiple versions of elbe-bootstrap packages on the "
"mirror(s) elbe selects the first package it has found.")
@@ -132,33 +133,6 @@ def get_uri_nonvirtapt(apt_sources, target_pkg, arch):
if pkg:
return "", pkg
-def getdeps(pkg):
- for dd in pkg.depends_list.get("Depends", []):
- for d in dd:
- yield d.target_pkg.name
-
-def lookup_uri(v, d, target_pkg):
-
- pkg = v.cache[target_pkg]
-
- c = d.get_candidate_ver(pkg)
-
- x = v.source.find_index(c.file_list[0][0])
-
- r = virtapt.apt_pkg.PackageRecords(v.cache)
- r.lookup(c.file_list[0])
- uri = x.archive_uri(r.filename)
-
- if not x.is_trusted:
- return target_pkg, uri, ""
-
- # TODO remove r.sha256_hash path as soon as initvm is stretch or later
- try:
- hashval = r.sha256_hash
- except DeprecationWarning:
- hashval = str(r.hashes.find('SHA256')).split(':')[1]
-
- return target_pkg, uri, hashval
def get_uri(prj, defs, arch, target_pkg, incl_deps=False):
if arch == "default":
@@ -170,31 +144,16 @@ def get_uri(prj, defs, arch, target_pkg, incl_deps=False):
if virtapt_imported:
try:
- v = virtapt.VirtApt(arch, suite, apt_sources, "", apt_keys)
+ if arch == "default":
+ arch = prj.text("buildimage/arch", default=defs, key="arch")
+ suite = prj.text("suite")
+ v = get_virtaptcache(arch, suite, apt_sources, "", apt_keys)
except Exception as e:
+ print("python-apt failed, using fallback code")
return get_uri_nonvirtapt(apt_sources, target_pkg, arch)
- d = virtapt.apt_pkg.DepCache(v.cache)
-
- if not incl_deps:
- return [lookup_uri(v, d, target_pkg)]
-
- if incl_deps:
- deps = [lookup_uri(v, d, target_pkg)]
- togo = [target_pkg]
- while len(togo):
- pp = togo.pop()
- pkg= v.cache[pp]
- c = d.get_candidate_ver(pkg)
- for p in getdeps(c):
- if len([y for y in deps if y[0] == p]):
- continue
- if p != target_pkg and p == pp:
- continue
- deps.append(lookup_uri(v, d, p))
- togo.append(p)
-
- return deps
+ ret = v.get_uri(suite, arch, target_pkg, incl_deps)
+ return ret
else:
return get_uri_nonvirtapt(apt_sources, target_pkg, arch)
diff --git a/elbepack/rpcaptcache.py b/elbepack/rpcaptcache.py
index 8577abed..7a90e838 100644
--- a/elbepack/rpcaptcache.py
+++ b/elbepack/rpcaptcache.py
@@ -287,3 +287,14 @@ def get_rpcaptcache(
mm.start()
return mm.RPCAPTCache(rfs, log, arch, notifier, norecommend, noauth)
+
+
+from elbepack.virtapt import VirtApt
+
+MyMan.register("VirtRPCAPTCache", VirtApt)
+
+def get_virtaptcache(arch, suite, sources, prefs, keylist=[]):
+ mm = MyMan()
+ mm.start()
+
+ return mm.VirtRPCAPTCache(arch, suite, sources, prefs)
diff --git a/elbepack/virtapt.py b/elbepack/virtapt.py
index 3443e477..15827183 100644
--- a/elbepack/virtapt.py
+++ b/elbepack/virtapt.py
@@ -31,6 +31,37 @@ from elbepack.shellhelper import system
from elbepack.directories import elbe_pubkey_fname
+def getdeps(pkg):
+ for dd in pkg.depends_list.get("Depends", []):
+ for d in dd:
+ yield d.target_pkg.name
+
+
+def lookup_uri(v, d, target_pkg):
+
+ pkg = v.cache[target_pkg]
+
+ c = d.get_candidate_ver(pkg)
+
+ x = v.source.find_index(c.file_list[0][0])
+
+ r = apt_pkg.PackageRecords(v.cache)
+ r.lookup(c.file_list[0])
+ uri = x.archive_uri(r.filename)
+
+ if not x.is_trusted:
+ return target_pkg, uri, ""
+
+ # TODO remove r.sha256_hash path as soon as initvm is stretch or later
+ try:
+ hashval = r.sha256_hash
+ except DeprecationWarning:
+ hashval = str(r.hashes.find('SHA256')).split(':')[1]
+
+ return target_pkg, uri, hashval
+
+
+
class VirtApt:
def __init__(self, arch, suite, sources, prefs, keylist=[]):
@@ -183,3 +214,26 @@ class VirtApt:
file = open(filename, "w")
file.write(prefs)
file.close()
+
+ def get_uri(self, suite, arch, target_pkg, incl_deps=False):
+
+ d = apt_pkg.DepCache(self.cache)
+
+ if not incl_deps:
+ return [lookup_uri(self, d, target_pkg)]
+
+ deps = [lookup_uri(self, d, target_pkg)]
+ togo = [target_pkg]
+ while len(togo):
+ pp = togo.pop()
+ pkg= self.cache[pp]
+ c = d.get_candidate_ver(pkg)
+ for p in getdeps(c):
+ if len([y for y in deps if y[0] == p]):
+ continue
+ if p != target_pkg and p == pp:
+ continue
+ deps.append(lookup_uri(self, d, p))
+ togo.append(p)
+
+ return deps
--
2.15.1
More information about the elbe-devel
mailing list