Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running on Centos 8/Convert to python3 #42

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions bin/yumbootstrap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3

import os
import sys
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)

#-----------------------------------------------------------

Expand All @@ -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)

#-----------------------------------------------------------

Expand Down Expand Up @@ -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)

#-----------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ Source: yumbootstrap
Maintainer: Stanislaw Klekot <[email protected]>
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
Expand Down
6 changes: 3 additions & 3 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion debian/yumbootstrap.install
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/etc/yumbootstrap
/usr/sbin/yumbootstrap
/usr/lib/python2.*
/usr/lib/python3.*
4 changes: 2 additions & 2 deletions distros/scripts/clean_yumbootstrap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3

import os
import time
Expand All @@ -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))
2 changes: 1 addition & 1 deletion distros/scripts/fix_rpmdb.old-rpm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3

import os
import time
Expand Down
2 changes: 1 addition & 1 deletion distros/scripts/fix_rpmdb.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3

import os
import time
Expand Down
4 changes: 2 additions & 2 deletions examples/scripts/clean_yumbootstrap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3

import os
import time
Expand All @@ -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))
2 changes: 1 addition & 1 deletion examples/scripts/fix_rpmdb.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3

import os
import time
Expand Down
2 changes: 0 additions & 2 deletions lib/yumbootstrap/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/python

#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
Expand Down
37 changes: 0 additions & 37 deletions lib/yumbootstrap/bdb.py

This file was deleted.

2 changes: 0 additions & 2 deletions lib/yumbootstrap/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/python

#-----------------------------------------------------------------------------

# usage:
Expand Down
4 changes: 1 addition & 3 deletions lib/yumbootstrap/fs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/python

import os
import stat

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions lib/yumbootstrap/log.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#!/usr/bin/python

import logging
import time

#-----------------------------------------------------------------------------

class ProgressHandler(logging.Handler):
def emit(self, record):
print time.strftime('[%T] ') + record.getMessage()
print(time.strftime('[%T] ') + record.getMessage())

#-----------------------------------------------------------------------------
# vim:ft=python
7 changes: 4 additions & 3 deletions lib/yumbootstrap/sh.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)

Expand Down
8 changes: 3 additions & 5 deletions lib/yumbootstrap/suites.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/python

import re
import os
import errno
from exceptions import YBError
from yumbootstrap.exceptions import YBError

#-----------------------------------------------------------------------------

Expand All @@ -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)
Expand All @@ -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)

#-----------------------------------------------------------------------------
Expand Down
35 changes: 26 additions & 9 deletions lib/yumbootstrap/yum.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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,
Expand All @@ -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('/'))
Expand Down
Loading