[elbe-devel] [PATCH v2 20/22] virtapt: add package downloading code
Torben Hohn
torben.hohn at linutronix.de
Tue Jul 2 12:55:42 CEST 2019
use code based on lookup_uri to lookup package urls, then use the Acquire
functionality to download the packages.
This special implemention is not able to resolve provides, which is
not needed, when only packages shall be downloaded, that are listed
in the full package list.
Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
elbepack/virtapt.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/elbepack/virtapt.py b/elbepack/virtapt.py
index 71d7d54c0..f74facd0c 100644
--- a/elbepack/virtapt.py
+++ b/elbepack/virtapt.py
@@ -147,6 +147,9 @@ class VirtApt(object):
except BaseException as e:
print(e)
+ self.downloads = {}
+ self.acquire = apt_pkg.Acquire(self)
+
def add_key(self, key):
cmd = 'echo "%s" > %s' % (key, self.basefs.fname("tmp/key.pub"))
clean = 'rm -f %s' % self.basefs.fname("tmp/key.pub")
@@ -217,6 +220,49 @@ class VirtApt(object):
def has_pkg(self, pkgname):
return pkgname in self.cache
+ def mark_pkg_download(self, pkgname):
+ pkg = self.cache[pkgname]
+ c = self.depcache.get_candidate_ver(pkg)
+
+ r = apt_pkg.PackageRecords(self.cache)
+ r.lookup(c.file_list[0])
+
+ x = self.source.find_index(c.file_list[0][0])
+ uri = x.archive_uri(r.filename)
+ hashval = str(r.hashes.find('SHA256'))
+
+ acq = apt_pkg.AcquireFile(self.acquire,
+ uri,
+ hash=hashval,
+ size=c.size,
+ descr=r.long_desc,
+ short_descr=r.short_desc,
+ destdir=self.basefs.fname('/cache/archives'))
+ self.downloads[pkgname] = acq
+
+ def do_downloads(self):
+ res = self.acquire.run()
+ print(res)
+
+ def get_downloaded_files(self):
+ ret = []
+ for _, d in self.downloads.iteritems():
+ if d.complete:
+ ret.append(d.destfile)
+ else:
+ print('incomplete download "%s"' % d.desc_uri)
+
+ return ret
+
+ def get_downloaded_pkg(self, pkgname):
+ d = self.downloads[pkgname]
+
+ if not d.complete:
+ print('incomplete download "%s"' % d.desc_uri)
+ raise KeyError
+
+ return d.destfile
+
def get_uri(self, target_pkg, incl_deps=False):
d = apt_pkg.DepCache(self.cache)
--
2.11.0
More information about the elbe-devel
mailing list