Started the scrubInstRoot() function in instroot.py.

The scrubInstRoot() function will do a large part of the work
previously done by upd-instroot.
This commit is contained in:
David Cantrell 2008-10-05 14:32:41 -10:00
parent 21ff7ce04b
commit 90e58c56ab

View File

@ -95,7 +95,9 @@ def createInstRoot(yumconf=None, arch=None, treedir=None, updates=None):
sys.stderr.write("ERROR: Could not install packages.\n") sys.stderr.write("ERROR: Could not install packages.\n")
sys.exit(1) sys.exit(1)
# XXX: more coming! if not scrubInstRoot(destdir=destdir):
sys.stderr.write("ERROR: Could not scrub instroot.\n")
sys.exit(1)
return True return True
@ -124,13 +126,129 @@ def installPackages(yumconf=None, destdir=None, packages=None):
arglist += ['install', '-y'] + packages arglist += ['install', '-y'] + packages
# do some prep work on the destdir before calling yum # do some prep work on the destdir before calling yum
os.makedirs(os.path.join(destdir, 'var', 'lib'))
os.makedirs(os.path.join(destdir, 'tmp')) os.makedirs(os.path.join(destdir, 'tmp'))
os.makedirs(os.path.join(destdir, 'var', 'log')) os.makedirs(os.path.join(destdir, 'var', 'log'))
os.makedirs(os.path.join(destdir, 'var', 'lib', 'yum')) os.makedirs(os.path.join(destdir, 'var', 'lib'))
os.symlink(os.path.join(os.path.sep, 'tmp'), os.path.join(destdir, 'var', 'lib', 'xkb')) os.symlink(os.path.join(os.path.sep, 'tmp'), os.path.join(destdir, 'var', 'lib', 'xkb'))
# XXX: sort through yum errcodes and return False for actual bad things # XXX: sort through yum errcodes and return False for actual bad things
# we care about # we care about
errcode = yummain.user_main(arglist, exit_code=False) errcode = yummain.user_main(arglist, exit_code=False)
return True return True
# Scrub the instroot tree (remove files we don't want, modify settings, etc)
def scrubInstRoot(destdir=None):
"""scrubInstRoot(destdir=None)
Clean up the newly created instroot and make the tree more suitable to
run the installer.
destdir is the path to the instroot and is the only required argument.
"""
if destdir is None or not os.path.isdir(destdir):
return False
# drop custom configuration files in to the instroot
dogtailconf = os.path.join(pylorax.conf['datadir'], 'dogtail-%conf.xml')
if os.path.isfile(dogtailconf):
os.makedirs(os.path.join(destdir, '.gconf', 'desktop', 'gnome', 'interface'))
f = open(os.path.join(destdir, '.gconf', 'desktop', '%gconf.xml'), 'w')
f.close()
f = open(os.path.join(destdir, '.gconf', 'desktop', 'gnome', '%gconf.xml'), 'w')
f.close()
dest = os.path.join(destdir, '.gconf', 'desktop', 'gnome', 'interface', '%gconf.xml')
shutil.copy(dogtailconf, dest)
# create selinux config
if os.path.isfile(os.path.join(destdir, 'etc', 'selinux', 'targeted')):
src = os.path.join(pylorax.conf['datadir'], 'selinux-config')
if os.path.isfile(src):
dest = os.path.join(destdir, 'etc', 'selinux', 'config')
shutil.copy(src, dest)
# create libuser.conf
src = os.path.join(pylorax.conf['datadir'], 'libuser.conf')
dest = os.path.join(destdir, 'etc', 'libuser.conf')
if os.path.isfile(src):
shutil.copy(src, dest)
# figure out the gtk+ theme to keep
gtkrc = os.path.join(destdir, 'etc', 'gtk-2.0', 'gtkrc')
gtk_theme_name = None
gtk_icon_themes = []
gtk_engine = None
if os.path.isfile(gtkrc):
f = open(gtkrc, 'r')
lines = f.readlines()
f.close()
for line in lines:
line = line.strip()
if line.startswith('gtk-theme-name'):
gtk_theme_name = line[line.find('=') + 1:].replace('"', '').strip()
# find the engine for this theme
gtkrc = os.path.join(destdir, 'usr', 'share', 'themes', gtk_theme_name, 'gtk-2.0', 'gtkrc')
if os.path.isfile(gtkrc):
f = open(gtkrc, 'r')
engine_lines = f.readlines()
f.close()
for engine_line in engine_lines:
engine_line = engine_line.strip()
if engine_line.find('engine') != -1:
gtk_engine = engine_line[engine_line.find('"') + 1:].replace('"', '')
break
if line.startswith('gtk-icon-theme-name'):
icon_theme = line[line.find('=') + 1:].replace('"', '').strip()
gtk_icon_themes.append(icon_theme)
# bring in all inherited themes
while icon_theme != '':
icon_theme_index = os.path.join(destdir, 'usr', 'share', 'icons', icon_theme, 'index.theme')
if os.path.isfile(icon_theme_index):
f = open(icon_theme_index, 'r')
icon_lines = f.readlines()
f.close()
for icon_line in icon_lines:
icon_line = icon_line.strip()
if icon_line.startswith('Inherits='):
icon_theme = line[line.find('=') + 1:].replace('"', '')
gtk_icon_themes.append(icon_theme)
break
else:
icon_theme = ''
theme_path = os.path.join(destdir, 'usr', 'share', 'themes')
if os.path.isdir(theme_path):
for theme in os.listdir(theme_path):
if theme != gtk_theme_name:
theme = os.path.join(theme_path, theme)
shutil.rmtree(theme, ignore_error=True)
icon_path = os.path.join(destdir, 'usr', 'share', 'icons')
if os.path.isdir(icon_path):
for icon in os.listdir(icon_path):
try:
if gtk_icon_themes.index(icon):
continue
except ValueError:
icon = os.path.join(icon_path, icon)
shutil.rmtree(icon, ignore_errors=True)
tmp_path = os.path.join(destdir, 'usr', libdir, 'gtk-2.0')
if os.path.isdir(tmp_path):
for subdir in os.listdir(tmp_path):
new_path = os.path.join(tmp_path, subdir, 'engines')
if os.path.isdir(new_path):
for engine in os.listdir(new_path):
if engine.find(gtk_engine) == -1:
tmp_engine = os.path.join(new_path, engine)
os.unlink(tmp_engine)
return True