[elbe-devel] [PATCH v2 02/12] fetch_initvm_pkgs: first version of fetch_initvm_pkgs
Torben Hohn
torben.hohn at linutronix.de
Mon Nov 12 17:43:03 CET 2018
when the initvm is setup, it is necessary to download the sources,
used by the binary packages in the initvm. "elbe fetch_initvm_pkgs" is
supposed to build up a debian repo, that contains all the binaries and
sources used in the initvm.
Later on, this repo will be used to seed the initvm related packages and
sources in the generated cdroms.
Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
Signed-off-by: Manuel Traut <manut at linutronix.de>
---
elbepack/commands/fetch_initvm_pkgs.py | 132 +++++++++++++++++++++++++++++++++
1 file changed, 132 insertions(+)
create mode 100644 elbepack/commands/fetch_initvm_pkgs.py
diff --git a/elbepack/commands/fetch_initvm_pkgs.py b/elbepack/commands/fetch_initvm_pkgs.py
new file mode 100644
index 00000000..d681a6a5
--- /dev/null
+++ b/elbepack/commands/fetch_initvm_pkgs.py
@@ -0,0 +1,132 @@
+# ELBE - Debian Based Embedded Rootfilesystem Builder
+# Copyright (c) 2018 Torben Hohn <torbenh at linutronix.de>
+# Copyright (c) 2018 Manuel Traut <manut at linutronix.de>
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+from __future__ import print_function
+
+import sys
+from optparse import OptionParser
+
+from apt.package import FetchError
+from apt import Cache
+
+from elbepack.elbexml import ElbeXML, ValidationError
+from elbepack.repomanager import CdromInitRepo, CdromSrcRepo
+from elbepack.asciidoclog import StdoutLog
+from elbepack.dump import get_initvm_pkglist
+from elbepack.aptprogress import ElbeAcquireProgress
+from elbepack.filesystem import hostfs
+
+
+def run_command(argv):
+ oparser = OptionParser(
+ usage="usage: %prog fetch_initvm_pkgs [options] <xmlfile>")
+
+ oparser.add_option("-b", "--binrepo", dest="binrepo",
+ default="/var/cache/elbe/initvm-bin-repo",
+ help="directory where the bin repo should reside")
+
+ oparser.add_option("-s", "--srcrepo", dest="srcrepo",
+ default="/var/cache/elbe/initvm-src-repo",
+ help="directory where the src repo should reside")
+
+ oparser.add_option("--skip-validation", action="store_true",
+ dest="skip_validation", default=False,
+ help="Skip xml schema validation")
+
+ oparser.add_option("--cdrom-mount-path", dest="cdrom",
+ help="path where cdrom is mounted")
+
+ oparser.add_option("--apt-archive", dest="archive",
+ default="/var/cache/elbe/binaries/main",
+ help="path where binary packages are downloaded to.")
+
+ oparser.add_option("--src-archive", dest="srcarchive",
+ default="/var/cache/elbe/sources",
+ help="path where src packages are downloaded to.")
+
+ (opt, args) = oparser.parse_args(argv)
+
+ if len(args) != 1:
+ print("wrong number of arguments")
+ oparser.print_help()
+ sys.exit(20)
+
+ try:
+ xml = ElbeXML(args[0], skip_validate=opt.skip_validation)
+ except ValidationError as e:
+ print(str(e))
+ print("xml validation failed. Bailing out")
+ sys.exit(20)
+
+ log = StdoutLog()
+ mirror = xml.get_initvm_primary_mirror(opt.cdrom)
+ init_codename = xml.get_initvm_codename()
+
+ # Binary Repo
+ #
+ repo = CdromInitRepo(init_codename, opt.binrepo, log, 0, mirror)
+ hostfs.mkdir_p(opt.archive)
+
+ pkglist = get_initvm_pkglist()
+ cache = Cache()
+ cache.open()
+ for pkg in pkglist:
+ try:
+ p = cache[pkg.name]
+ pkgver = p.installed
+ deb = pkgver.fetch_binary(opt.archive,
+ ElbeAcquireProgress(cb=None))
+ repo.includedeb(deb, 'main')
+ except ValueError:
+ log.printo("No Package " + pkg.name +
+ "-" + str(pkg.installed_version))
+ except FetchError:
+ log.printo(
+ "Package " +
+ pkg.name +
+ "-" +
+ pkgver.version +
+ " could not be downloaded")
+ except TypeError:
+ log.printo("Package " +
+ pkg.name +
+ "-" +
+ str(pkg.installed_version) +
+ " missing name or version")
+
+ repo.finalize()
+
+ # Source Repo
+ #
+ repo = CdromSrcRepo(init_codename, init_codename, opt.srcrepo, log, 0, mirror)
+ hostfs.mkdir_p(opt.srcarchive)
+
+ for pkg in pkglist:
+ try:
+ p = cache[pkg.name]
+ pkgver = p.installed
+ dsc = pkgver.fetch_source(opt.srcarchive,
+ ElbeAcquireProgress(cb=None),
+ unpack=False)
+ repo.includedsc(dsc, 'main')
+ except ValueError:
+ log.printo("No Package " + pkg.name +
+ "-" + str(pkg.installed_version))
+ except FetchError:
+ log.printo(
+ "Package " +
+ pkg.name +
+ "-" +
+ pkgver.version +
+ " could not be downloaded")
+ except TypeError:
+ log.printo("Package " +
+ pkg.name +
+ "-" +
+ str(pkg.installed_version) +
+ " missing name or version")
+
+ repo.finalize()
--
2.11.0
More information about the elbe-devel
mailing list