From 33d0d9e18ffa7e65c31749c2635533e6ba39ceb7 Mon Sep 17 00:00:00 2001 From: Peter Verraedt Date: Thu, 5 Dec 2019 13:27:27 +0100 Subject: [PATCH] Use db_dump --- lib/yumbootstrap/bdb.py | 35 ----------------------------------- lib/yumbootstrap/yum.py | 15 +++++++++++---- redhat/yumbootstrap.spec | 2 -- 3 files changed, 11 insertions(+), 41 deletions(-) delete mode 100644 lib/yumbootstrap/bdb.py diff --git a/lib/yumbootstrap/bdb.py b/lib/yumbootstrap/bdb.py deleted file mode 100644 index 42d4704..0000000 --- a/lib/yumbootstrap/bdb.py +++ /dev/null @@ -1,35 +0,0 @@ -import sys -import bsddb3 - -#----------------------------------------------------------------------------- - -# poor man's BDB database dumper -# this function makes dependencies on host a little lower (BDB in Python -# should be the same as Yum/RPM use) -def db_dump(filename, outfile = sys.stdout): - try: - f = bsddb3.hashopen(filename, 'r') - db_type = "hash" - except: - f = bsddb3.btopen(filename, 'r') - db_type = "btree" - - outfile.write("VERSION=3\n") # magic - outfile.write("format=bytevalue\n") - outfile.write("type=%s\n" % (db_type)) - - outfile.write("HEADER=END\n") - for (key,value) in f.iteritems(): - outfile.write(" ") - for c in key: - outfile.write("%02x" % c) - outfile.write("\n") - - outfile.write(" ") - for c in value: - outfile.write("%02x" % c) - outfile.write("\n") - outfile.write("DATA=END\n") - -#----------------------------------------------------------------------------- -# vim:ft=python diff --git a/lib/yumbootstrap/yum.py b/lib/yumbootstrap/yum.py index 25804e7..e78cef0 100644 --- a/lib/yumbootstrap/yum.py +++ b/lib/yumbootstrap/yum.py @@ -1,7 +1,6 @@ import os import shutil -import yumbootstrap.bdb as bdb import yumbootstrap.sh as sh import yumbootstrap.fs as fs @@ -146,13 +145,12 @@ def fix_rpmdb(self, expected_rpmdb_dir = None, db_load = 'db_load', rpm = 'rpm'): logger.info("fixing RPM database for guest") + # use platform-python if available to read rpm dbpath if os.path.exists('/usr/libexec/platform-python'): platform_python = '/usr/libexec/platform-python' else: - # On debian-based systems, use default python platform_python = 'python' - # Call platform-python to be sure that rpm module can be loaded current_rpmdb_dir = sh.run( [platform_python, '-c', 'import rpm; print(rpm.expandMacro("%{_dbpath}"))'], pipe = sh.READ, @@ -171,16 +169,25 @@ def fix_rpmdb(self, expected_rpmdb_dir = None, rpmdb_dir = os.path.join(self.chroot, current_rpmdb_dir.lstrip('/')) logger.info('converting "Packages" file') + in_pkg_db = os.path.join(rpmdb_dir, 'Packages') tmp_pkg_db = os.path.join(expected_rpmdb_dir, 'Packages.tmp') out_pkg_db = os.path.join(expected_rpmdb_dir, 'Packages') + + in_command = sh.run( + ['db_dump', in_pkg_db], + pipe = sh.READ, + env = self.yum_conf.env, + ) out_command = sh.run( [db_load, tmp_pkg_db], chroot = self.chroot, pipe = sh.WRITE, env = self.yum_conf.env, ) - bdb.db_dump(in_pkg_db, out_command) + for line in in_command: + out_command.write(line) out_command.close() + os.rename( os.path.join(self.chroot, tmp_pkg_db.lstrip('/')), os.path.join(self.chroot, out_pkg_db.lstrip('/')) diff --git a/redhat/yumbootstrap.spec b/redhat/yumbootstrap.spec index 5689ef0..9914f42 100644 --- a/redhat/yumbootstrap.spec +++ b/redhat/yumbootstrap.spec @@ -19,8 +19,6 @@ Packager: %{_packager} Prefix: %{_prefix} BuildRequires: python3-setuptools Requires: yum >= 3.0 -%{?el7:Requires: python36-bsddb3} -%{?el8:Requires: python3-bsddb3} %description yumbootstrap is a tool for installing Yum-based distributions (Red Hat,