diff --git a/Makefile b/Makefile index 1b2bbef..61fb32d 100644 --- a/Makefile +++ b/Makefile @@ -15,13 +15,13 @@ install-notmodule: cp -R distros/* $(DESTDIR)$(SYSCONFDIR)/yumbootstrap/suites tarball: - python setup.py sdist --formats=zip + python3 setup.py sdist --formats=zip egg: - python setup.py bdist_egg + python3 setup.py bdist_egg clean: - python setup.py clean --all + python3 setup.py clean --all rm -rf dist lib/*.egg-info # rm -rf $(SPHINX_DOCTREE) $(SPHINX_OUTPUT) diff --git a/README.md b/README.md index b5d46ef..8e9fa65 100644 --- a/README.md +++ b/README.md @@ -50,13 +50,13 @@ Installing yumbootstrap ----------------------- For Debian-based distributions, *dpkg-dev*, *fakeroot*, *debhelper* (9+), -*python*, and *python-setuptools*. For installing the package, *yum* is also +*python3*, and *python3-setuptools*. For installing the package, *yum* is also required. dpkg-buildpackage -b -uc dpkg -i ../yumbootstrap*.deb -For Red Hat derivatives you need *rpm-build*. +For Red Hat derivatives you need *rpm-build* and *python3-setuptools*. make srpm rpmbuild --rebuild yumbootstrap-*.src.rpm diff --git a/bin/yumbootstrap b/bin/yumbootstrap index 6b27bd2..fb5b04c 100755 --- a/bin/yumbootstrap +++ b/bin/yumbootstrap @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import os import sys @@ -236,7 +236,7 @@ def read_cached_suite(target): suite_location['suite_name'], ) return suite - except IOError, e: + except IOError as e: if e.errno == errno.ENOENT: raise YBError("\"%s\" is not a prepared target", target, exit = 1) else: @@ -286,17 +286,17 @@ def do_install(opts, suite_name, target): suite.name, suite.release, target) logger.info("preparing empty /etc/fstab and /etc/mtab") - os.umask(022) + os.umask(0o22) # prepare target directory with an empty /etc/fstab touch(target, 'etc/fstab', text = '# empty fstab') touch(target, 'etc/mtab') mkdir(target, "dev/pts") - mkchardev(target, "dev/null", mode = 0666, major = 1, minor = 3) - mkchardev(target, "dev/zero", mode = 0666, major = 1, minor = 5) - mkchardev(target, "dev/full", mode = 0666, major = 1, minor = 7) - mkchardev(target, "dev/random", mode = 0666, major = 1, minor = 8) - mkchardev(target, "dev/urandom", mode = 0666, major = 1, minor = 9) - mkchardev(target, "dev/tty", mode = 0666, major = 5, minor = 0) + mkchardev(target, "dev/null", mode = 0o666, major = 1, minor = 3) + mkchardev(target, "dev/zero", mode = 0o666, major = 1, minor = 5) + mkchardev(target, "dev/full", mode = 0o666, major = 1, minor = 7) + mkchardev(target, "dev/random", mode = 0o666, major = 1, minor = 8) + mkchardev(target, "dev/urandom", mode = 0o666, major = 1, minor = 9) + mkchardev(target, "dev/tty", mode = 0o666, major = 5, minor = 0) if len(opts.repositories) > 0: logger.info("using custom repositories: %s", @@ -361,7 +361,7 @@ def do_install(opts, suite_name, target): def do_list_suites(opts): for suite in yumbootstrap.suites.list_suites(opts.suite_dir): - print suite + print(suite) #----------------------------------------------------------- @@ -371,7 +371,7 @@ def do_list_scripts(opts, target): else: suite = read_cached_suite(target) for name in suite.post_install.names(): - print name + print(name) #----------------------------------------------------------- @@ -424,8 +424,8 @@ try: o.error("unrecognized action: %s" % (opts.action,)) except KeyboardInterrupt: pass -except YBError, e: - print >>sys.stderr, e +except YBError as e: + print(e, file=sys.stderr) sys.exit(e.code) #----------------------------------------------------------------------------- diff --git a/debian/control b/debian/control index 4c9f55e..292f105 100644 --- a/debian/control +++ b/debian/control @@ -2,13 +2,13 @@ Source: yumbootstrap Maintainer: Stanislaw Klekot Section: admin Priority: extra -Build-Depends: debhelper (>> 9.0.0), make, python, python-setuptools +Build-Depends: debhelper (>> 9.0.0), make, python3, python3-setuptools # the version is just a wild guess -X-Python-Version: >= 2.3 +X-Python-Version: >= 3.4 Package: yumbootstrap Architecture: all -Depends: ${shlibs:Depends}, ${misc:Depends}, ${python:Depends}, yum (>> 3.0) +Depends: ${shlibs:Depends}, ${misc:Depends}, ${python3:Depends}, yum (>> 3.0) Description: Yum-based distributions chroot installer yumbootstrap is a tool for installing Yum-based distributions (Red Hat, CentOS, Fedora) in a chroot directory. Idea behind it is stolen from Debian's diff --git a/debian/rules b/debian/rules index 50f9797..39c9436 100755 --- a/debian/rules +++ b/debian/rules @@ -1,11 +1,11 @@ #!/usr/bin/make -f %: - dh $@ --with=python2 + dh $@ --with=python3 override_dh_auto_build: - python setup.py build + python3 setup.py build override_dh_auto_install: make install-notmodule DESTDIR=$(CURDIR)/debian/tmp BINDIR=/usr/sbin SYSCONFDIR=/etc - python setup.py install --root=$(CURDIR)/debian/tmp --install-layout=deb --no-compile + python3 setup.py install --root=$(CURDIR)/debian/tmp --install-layout=deb --no-compile diff --git a/debian/yumbootstrap.install b/debian/yumbootstrap.install index 17fb562..a21416c 100644 --- a/debian/yumbootstrap.install +++ b/debian/yumbootstrap.install @@ -1,3 +1,3 @@ /etc/yumbootstrap /usr/sbin/yumbootstrap -/usr/lib/python2.* +/usr/lib/python3.* diff --git a/distros/scripts/clean_yumbootstrap.py b/distros/scripts/clean_yumbootstrap.py index 29c5e84..78ae896 100755 --- a/distros/scripts/clean_yumbootstrap.py +++ b/distros/scripts/clean_yumbootstrap.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import os import time @@ -7,5 +7,5 @@ target = os.environ['TARGET'] yumbootstrap_dir = os.environ['YUMBOOTSTRAP_DIR'] if os.environ['VERBOSE'] == 'true': - print time.strftime('[%T] ') + 'removing yumbootstrap directory from target' + print(time.strftime('[%T] ') + 'removing yumbootstrap directory from target') shutil.rmtree(os.path.join(target, yumbootstrap_dir)) diff --git a/distros/scripts/fix_rpmdb.old-rpm.py b/distros/scripts/fix_rpmdb.old-rpm.py index 396163d..a5828cf 100755 --- a/distros/scripts/fix_rpmdb.old-rpm.py +++ b/distros/scripts/fix_rpmdb.old-rpm.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import os import time diff --git a/distros/scripts/fix_rpmdb.py b/distros/scripts/fix_rpmdb.py index 8ac1c3d..5a1d6e4 100755 --- a/distros/scripts/fix_rpmdb.py +++ b/distros/scripts/fix_rpmdb.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import os import time diff --git a/examples/scripts/clean_yumbootstrap.py b/examples/scripts/clean_yumbootstrap.py index 29c5e84..78ae896 100755 --- a/examples/scripts/clean_yumbootstrap.py +++ b/examples/scripts/clean_yumbootstrap.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import os import time @@ -7,5 +7,5 @@ target = os.environ['TARGET'] yumbootstrap_dir = os.environ['YUMBOOTSTRAP_DIR'] if os.environ['VERBOSE'] == 'true': - print time.strftime('[%T] ') + 'removing yumbootstrap directory from target' + print(time.strftime('[%T] ') + 'removing yumbootstrap directory from target') shutil.rmtree(os.path.join(target, yumbootstrap_dir)) diff --git a/examples/scripts/fix_rpmdb.py b/examples/scripts/fix_rpmdb.py index ead99dc..a7a8031 100755 --- a/examples/scripts/fix_rpmdb.py +++ b/examples/scripts/fix_rpmdb.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import os import time diff --git a/lib/yumbootstrap/__init__.py b/lib/yumbootstrap/__init__.py index 6e7e1fe..c51147a 100644 --- a/lib/yumbootstrap/__init__.py +++ b/lib/yumbootstrap/__init__.py @@ -1,5 +1,3 @@ -#!/usr/bin/python - #----------------------------------------------------------------------------- #----------------------------------------------------------------------------- diff --git a/lib/yumbootstrap/bdb.py b/lib/yumbootstrap/bdb.py deleted file mode 100644 index fb5744a..0000000 --- a/lib/yumbootstrap/bdb.py +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/python - -import sys -import bsddb - -#----------------------------------------------------------------------------- - -# 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 = bsddb.hashopen(filename, 'r') - db_type = "hash" - except: - f = bsddb.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" % ord(c)) - outfile.write("\n") - - outfile.write(" ") - for c in value: - outfile.write("%02x" % ord(c)) - outfile.write("\n") - outfile.write("DATA=END\n") - -#----------------------------------------------------------------------------- -# vim:ft=python diff --git a/lib/yumbootstrap/exceptions.py b/lib/yumbootstrap/exceptions.py index 3a6a321..0cac1ef 100644 --- a/lib/yumbootstrap/exceptions.py +++ b/lib/yumbootstrap/exceptions.py @@ -1,5 +1,3 @@ -#!/usr/bin/python - #----------------------------------------------------------------------------- # usage: diff --git a/lib/yumbootstrap/fs.py b/lib/yumbootstrap/fs.py index ce15807..767fcca 100644 --- a/lib/yumbootstrap/fs.py +++ b/lib/yumbootstrap/fs.py @@ -1,5 +1,3 @@ -#!/usr/bin/python - import os import stat @@ -29,7 +27,7 @@ def mkchardev(*path, **kwargs): mkdir(os.path.dirname(new_file)) major = kwargs["major"] minor = kwargs["minor"] - mode = kwargs.get("mode", 0666) + mode = kwargs.get("mode", 0o666) try: info = os.stat(new_file) diff --git a/lib/yumbootstrap/log.py b/lib/yumbootstrap/log.py index d86a695..a4f0fa3 100644 --- a/lib/yumbootstrap/log.py +++ b/lib/yumbootstrap/log.py @@ -1,5 +1,3 @@ -#!/usr/bin/python - import logging import time @@ -7,7 +5,7 @@ class ProgressHandler(logging.Handler): def emit(self, record): - print time.strftime('[%T] ') + record.getMessage() + print(time.strftime('[%T] ') + record.getMessage()) #----------------------------------------------------------------------------- # vim:ft=python diff --git a/lib/yumbootstrap/sh.py b/lib/yumbootstrap/sh.py index 0949d07..26f6fae 100644 --- a/lib/yumbootstrap/sh.py +++ b/lib/yumbootstrap/sh.py @@ -1,8 +1,6 @@ -#!/usr/bin/python - import os import subprocess -from exceptions import YBError +from yumbootstrap.exceptions import YBError READ = object() # read from WRITE = object() # write to @@ -75,6 +73,7 @@ def chroot_fun(*args): env = env, stdin = open('/dev/null'), preexec_fn = chroot_fun, + encoding = "utf-8", ) proc.wait() check_error(command[0], proc.returncode) @@ -85,6 +84,7 @@ def chroot_fun(*args): stdin = open('/dev/null'), stdout = subprocess.PIPE, preexec_fn = chroot_fun, + encoding = "utf-8", ) (result,_) = proc.communicate() check_error(command[0], proc.returncode) @@ -95,6 +95,7 @@ def chroot_fun(*args): env = env, stdin = subprocess.PIPE, preexec_fn = chroot_fun, + encoding = "utf-8", ) return OutPipe(command[0], proc) diff --git a/lib/yumbootstrap/suites.py b/lib/yumbootstrap/suites.py index 5f81816..4d1c9bb 100644 --- a/lib/yumbootstrap/suites.py +++ b/lib/yumbootstrap/suites.py @@ -1,9 +1,7 @@ -#!/usr/bin/python - import re import os import errno -from exceptions import YBError +from yumbootstrap.exceptions import YBError #----------------------------------------------------------------------------- @@ -12,7 +10,7 @@ def list_suites(directory): result = [fn[:-6] for fn in os.listdir(directory) if fn.endswith('.suite')] result.sort() return result - except OSError, e: + except OSError as e: if e.errno == errno.ENOENT: return [] raise YBError("Can't access %s: %s", directory, e.args[1], exit = 1) @@ -28,7 +26,7 @@ def load_suite(directory, suite_name): try: return Suite(suite_name, suite_file) - except OSError, e: + except OSError as e: raise YBError("Can't access %s: %s", directory, e.args[1], exit = 1) #----------------------------------------------------------------------------- diff --git a/lib/yumbootstrap/yum.py b/lib/yumbootstrap/yum.py index 99bffe2..e78cef0 100644 --- a/lib/yumbootstrap/yum.py +++ b/lib/yumbootstrap/yum.py @@ -1,12 +1,8 @@ -#!/usr/bin/python - -import rpm as rpm_mod import os import shutil -import bdb -import sh -import fs +import yumbootstrap.sh as sh +import yumbootstrap.fs as fs import logging logger = logging.getLogger("yum") @@ -148,10 +144,22 @@ def clean(self): def fix_rpmdb(self, expected_rpmdb_dir = None, db_load = 'db_load', rpm = 'rpm'): logger.info("fixing RPM database for guest") - current_rpmdb_dir = rpm_mod.expandMacro('%{_dbpath}') + + # use platform-python if available to read rpm dbpath + if os.path.exists('/usr/libexec/platform-python'): + platform_python = '/usr/libexec/platform-python' + else: + platform_python = 'python' + + current_rpmdb_dir = sh.run( + [platform_python, '-c', 'import rpm; print(rpm.expandMacro("%{_dbpath}"))'], + pipe = sh.READ, + env = self.yum_conf.env, + ).strip() + if expected_rpmdb_dir is None: expected_rpmdb_dir = sh.run( - ['python', '-c', 'import rpm; print rpm.expandMacro("%{_dbpath}")'], + ['/usr/libexec/platform-python', '-c', 'import rpm; print(rpm.expandMacro("%{_dbpath}"))'], chroot = self.chroot, pipe = sh.READ, env = self.yum_conf.env, @@ -161,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 8bd5913..9914f42 100644 --- a/redhat/yumbootstrap.spec +++ b/redhat/yumbootstrap.spec @@ -2,7 +2,8 @@ %define _release 1 %define _packager Stanislaw Klekot -%define python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()") +%{!?__python3: %global __python3 /usr/bin/python3} +%{!?python3_sitelib: %global python3_sitelib %(%{__python3} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")} Summary: yumbootstrap - chroot installer for Red Hat derivatives Name: yumbootstrap @@ -16,7 +17,7 @@ URL: http://dozzie.jarowit.net/trac/wiki/yumbootstrap BuildArch: noarch Packager: %{_packager} Prefix: %{_prefix} -BuildRequires: python-setuptools +BuildRequires: python3-setuptools Requires: yum >= 3.0 %description @@ -28,11 +29,11 @@ debootstrap. %setup -q %build -CFLAGS="$RPM_OPT_FLAGS" %{__python} setup.py build +CFLAGS="$RPM_OPT_FLAGS" %{__python3} setup.py build %install [ "$RPM_BUILD_ROOT" != "/" ] && rm -rf "$RPM_BUILD_ROOT" -%{__python} setup.py install --root "$RPM_BUILD_ROOT" +%{__python3} setup.py install --root "$RPM_BUILD_ROOT" make install-notmodule \ DESTDIR="$RPM_BUILD_ROOT" \ BINDIR=%{_sbindir} SYSCONFDIR=%{_sysconfdir} @@ -51,8 +52,8 @@ cp KNOWN_ISSUES.md LICENSE README.md SUITES.md TODO \ %{_sysconfdir}/yumbootstrap #%{_mandir}/man8 %{_docdir}/yumbootstrap-%{_version} -%{python_sitearch}/yumbootstrap -%{python_sitearch}/yumbootstrap-*.egg-info +%{python3_sitelib}/yumbootstrap +%{python3_sitelib}/yumbootstrap-*.egg-info # %changelog diff --git a/setup.py b/setup.py index 52aa8e9..b0305ab 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 from setuptools import setup, find_packages from glob import glob