diff --git a/src/bin/lorax b/src/bin/lorax index a97a5a71..b1cc9c17 100755 --- a/src/bin/lorax +++ b/src/bin/lorax @@ -102,49 +102,25 @@ if __name__ == "__main__": sys.stderr.write("ERROR: Missing repo to use for image generation.\n") sys.exit(1) - print("\n+=======================================================+") - print("| Setting up work directories and configuration data... |") - print("+=======================================================+\n") + lorax = pylorax.Lorax(repos=args, output=output, mirrorlist=mirrorlist) + lorax.run() - # collect all repos specified on the command line. the first repo is - # designated the main repo (I guess) - repo, extrarepos = pylorax.collectRepos(args) - - # create directories that we will be using for image generation - buildinstdir, treedir, cachedir = pylorax.initializeDirs(output) - - # write out yum.conf used for image generation - yumconf = pylorax.writeYumConf(cachedir=cachedir, repo=repo, extrarepos=extrarepos, mirrorlist=mirrorlist) - if yumconf is None: - sys.stderr.write("ERROR: Could not generate temporary yum.conf file.\n") - sys.exit(1) - - buildarch = pylorax.getBuildArch() - - print("\n+================================================+") - print("| Creating instroot tree to build images from... |") - print("+================================================+\n") - - # upd-instroot - if not pylorax.instroot.createInstRoot(yumconf=yumconf, arch=buildarch, treedir=treedir, updates=updates): - sys.stderr.write("ERROR: Could not create inst root.\n") - sys.exit(1) - - print("\n+=======================================+") - print("| Writing meta data to instroot tree... |") - print("+=======================================+\n") - - # write .treeinfo file - if not pylorax.treeinfo.write(family=product, variant=variant, version=version, arch=buildarch, outdir=output): - sys.stderr.write("Error writing %s/.treeinfo file.\n" % (output,)) - - # mk-images - # XXX - - # write .discinfo file - if not pylorax.discinfo.write(release=release, arch=buildarch, outdir=output): - sys.stderr.write("Error writing %s/.discinfo file.\n" % (output,)) - - # clean up if cleanup: - pylorax.cleanup() + lorax.cleanup() + + + +# print("\n+=======================================+") +# print("| Writing meta data to instroot tree... |") +# print("+=======================================+\n") +# +# # write .treeinfo file +# if not pylorax.treeinfo.write(family=product, variant=variant, version=version, arch=buildarch, outdir=output): +# sys.stderr.write("Error writing %s/.treeinfo file.\n" % (output,)) +# +# # mk-images +# # XXX +# +# # write .discinfo file +# if not pylorax.discinfo.write(release=release, arch=buildarch, outdir=output): +# sys.stderr.write("Error writing %s/.discinfo file.\n" % (output,)) diff --git a/src/pylorax/__init__.py b/src/pylorax/__init__.py index af0d43ac..49fc3a2e 100644 --- a/src/pylorax/__init__.py +++ b/src/pylorax/__init__.py @@ -40,190 +40,207 @@ conf['confdir'] = '/etc/lorax' conf['tmpdir'] = tempfile.gettempdir() conf['datadir'] = '/usr/share/lorax' -def show_version(prog): - """show_version(prog) +class Lorax: + def __init__(self, repos=[], output=None, mirrorlist=[], updates=None): + print("\n+=======================================================+") + print("| Setting up work directories and configuration data... |") + print("+=======================================================+\n") - Display program name (prog) and version number. If prog is an empty - string or None, use the value 'pylorax'. + if repos != []: + self.repo, self.extrarepos = self._collectRepos(repos) + else: + self.repo = None + self.extrarepos = [] - """ + self.output = output + self.mirrorlist = mirrorlist + self.updates = updates + self.buildinstdir, self.treedir, self.cachedir = self._initializeDirs() + self.yumconf = self._writeYumConf() + self.buildarch = self.getBuildArch() - if prog is None or prog == '': - prog = 'pylorax' + def run(self): + """run() - print "%s version %d.%d" % (prog, version[0], version[1],) + Generate install images. -def collectRepos(args): - """collectRepos(args) + """ - Get the main repo (the first one) and then build a list of all remaining - repos in the list. Sanitize each repo URL for proper yum syntax. + print("\n+================================================+") + print("| Creating instroot tree to build images from... |") + print("+================================================+\n") - """ + self.instroot = pylorax.instroot.InstRoot(yumconf=self.yumconf, arch=self.buildarch, treedir=self.treedir, updates=self.updates) - if args is None or args == []: - return '', [] + def showVersion(self, driver=None): + """showVersion(driver) - repolist = [] - for repospec in args: - if repospec.startswith('/'): - repo = "file://%s" % (repospec,) - print("Adding local repo:\n %s" % (repo,)) - repolist.append(repo) - elif repospec.startswith('http://') or repospec.startswith('ftp://'): - print("Adding remote repo:\n %s" % (repospec,)) - repolist.append(repospec) + Display program name (driver) and version number. If prog is an empty + string or None, use the value 'pylorax'. - repo = repolist[0] - extrarepos = [] + """ - if len(repolist) > 1: - for extra in repolist[1:]: - print("Adding extra repo:\n %s" % (extra,)) - extrarepos.append(extra) + if prog is None or prog == '': + prog = 'pylorax' - return repo, extrarepos + print "%s version %d.%d" % (prog, version[0], version[1],) -def initializeDirs(output): - """initializeDirs(output) + def cleanup(self, trash=[]): + """cleanup(trash) - Create directories used for image generation. The only required - parameter is the main output directory specified by the user. + Given a list of things to remove, cleanup() will remove them if it can. + Never fails, just tries to remove things and returns regardless of + failures removing things. - """ + """ - if not os.path.isdir(output): - os.makedirs(output, mode=0755) + if trash != []: + for item in trash: + if os.path.isdir(item): + shutil.rmtree(item, ignore_errors=True) + else: + os.unlink(item) - conf['tmpdir'] = tempfile.mkdtemp('XXXXXX', 'lorax.tmp.', conf['tmpdir']) - buildinstdir = tempfile.mkdtemp('XXXXXX', 'buildinstall.tree.', conf['tmpdir']) - treedir = tempfile.mkdtemp('XXXXXX', 'treedir.', conf['tmpdir']) - cachedir = tempfile.mkdtemp('XXXXXX', 'yumcache.', conf['tmpdir']) + if os.path.isdir(conf['tmpdir']): + shutil.rmtree(conf['tmpdir'], ignore_errors=True) - print("Working directories:") - print(" tmpdir = %s" % (conf['tmpdir'],)) - print(" buildinstdir = %s" % (buildinstdir,)) - print(" treedir = %s" % (treedir,)) - print(" cachedir = %s" % (cachedir,)) + def getBuildArch(self): + """getBuildArch() - return buildinstdir, treedir, cachedir + Query the configured yum repositories to determine our build architecture, + which is the architecture of the anaconda package in the repositories. -def writeYumConf(cachedir=None, repo=None, extrarepos=[], mirrorlist=[]): - """writeYumConf(cachedir=None, repo=None, [extrarepos=[], mirrorlist=[]]) + This function is based on a subset of what repoquery(1) does. - Generate a temporary yum.conf file for image generation. The required - parameters are the cachedir that yum should use and the main repo to use. + """ - Optional parameters are a list of extra repositories to add to the - yum.conf file. The mirrorlist parameter is a list of yum mirrorlists - that should be added to the yum.conf file. + uname_arch = os.uname()[4] - Returns the path to the temporary yum.conf file on success, None of failure. - """ + if self.yumconf == '' or self.yumconf is None or not os.path.isfile(self.yumconf): + return uname_arch - if cachedir is None or repo is None: - return None + repoq = yum.YumBase() + repoq.doConfigSetup() - tmpdir = conf['tmpdir'] - (fd, yumconf) = tempfile.mkstemp(prefix='yum.conf', dir=tmpdir) - f = os.fdopen(fd, 'w') + try: + repoq.doRepoSetup() + except yum.Errors.RepoError, e: + sys.stderr.write("ERROR: could not query yum repository for build arch, defaulting to %s\n" % (uname_arch,)) + return uname_arch - f.write("[main]\n") - f.write("cachedir=%s\n" % (cachedir,)) - f.write("keepcache=0\n") - f.write("gpgcheck=0\n") - f.write("plugins=0\n") - f.write("reposdir=\n") - f.write("tsflags=nodocs\n\n") - f.write("[loraxrepo]\n") - f.write("name=lorax repo\n") - f.write("baseurl=%s\n" % (repo,)) - f.write("enabled=1\n\n") + repoq.doSackSetup(rpmUtils.arch.getArchList()) + repoq.doTsSetup() - if extrarepos != []: - n = 1 - for extra in extrarepos: - f.write("[lorax-extrarepo-%d]\n" % (n,)) - f.write("name=lorax extra repo %d\n" % (n,)) - f.write("baseurl=%s\n" % (extra,)) - f.write("enabled=1\n") - n += 1 + ret_arch = None + for pkg in repoq.pkgSack.simplePkgList(): + (n, a, e, v, r) = pkg + if n == 'anaconda': + ret_arch = a + break - if mirrorlist != []: - n = 1 - for mirror in mirrorlist: - f.write("[lorax-mirrorlistrepo-%d]\n" % (n,)) - f.write("name=lorax mirrorlist repo %d\n" % (n,)) - f.write("mirrorlist=%s\n" % (extra,)) - f.write("enabled=1\n") - n += 1 + if ret_arch is None: + ret_arch = uname_arch - f.close() - print("Wrote lorax yum configuration to %s" % (yumconf,)) + print("Building images for %s" % (ret_arch,)) - return yumconf + return ret_arch -def getBuildArch(yumconf=None): - """getBuildArch(yumconf=None) + def _collectRepos(self, repos): + """_collectRepos(repos) - Query the configured yum repositories to determine our build architecture, - which is the architecture of the anaconda package in the repositories. + Get the main repo (the first one) and then build a list of all remaining + repos in the list. Sanitize each repo URL for proper yum syntax. - The required argument is yumconf, which is the path to the yum configuration - file to use. + """ - This function is based on a subset of what repoquery(1) does. + if repos is None or repos == []: + return '', [] - """ + repolist = [] + for repospec in repos: + if repospec.startswith('/'): + repo = "file://%s" % (repospec,) + print("Adding local repo:\n %s" % (repo,)) + repolist.append(repo) + elif repospec.startswith('http://') or repospec.startswith('ftp://'): + print("Adding remote repo:\n %s" % (repospec,)) + repolist.append(repospec) - uname_arch = os.uname()[4] + repo = repolist[0] + extrarepos = [] - if yumconf == '' or yumconf is None or not os.path.isfile(yumconf): - return uname_arch + if len(repolist) > 1: + for extra in repolist[1:]: + print("Adding extra repo:\n %s" % (extra,)) + extrarepos.append(extra) - repoq = yum.YumBase() - repoq.doConfigSetup() + return repo, extrarepos - try: - repoq.doRepoSetup() - except yum.Errors.RepoError, e: - sys.stderr.write("ERROR: could not query yum repository for build arch, defaulting to %s\n" % (uname_arch,)) - return uname_arch + def initializeDirs(self): + """_initializeDirs() - repoq.doSackSetup(rpmUtils.arch.getArchList()) - repoq.doTsSetup() + Create directories used for image generation. - ret_arch = None - for pkg in repoq.pkgSack.simplePkgList(): - (n, a, e, v, r) = pkg - if n == 'anaconda': - ret_arch = a - break + """ - if ret_arch is None: - ret_arch = uname_arch + if not os.path.isdir(self.output): + os.makedirs(self.output, mode=0755) - print("Building images for %s" % (ret_arch,)) + conf['tmpdir'] = tempfile.mkdtemp('XXXXXX', 'lorax.tmp.', conf['tmpdir']) + buildinstdir = tempfile.mkdtemp('XXXXXX', 'buildinstall.tree.', conf['tmpdir']) + treedir = tempfile.mkdtemp('XXXXXX', 'treedir.', conf['tmpdir']) + cachedir = tempfile.mkdtemp('XXXXXX', 'yumcache.', conf['tmpdir']) - return ret_arch + print("Working directories:") + print(" tmpdir = %s" % (conf['tmpdir'],)) + print(" buildinstdir = %s" % (buildinstdir,)) + print(" treedir = %s" % (treedir,)) + print(" cachedir = %s" % (cachedir,)) -def cleanup(trash=[]): - """cleanup(trash) + return buildinstdir, treedir, cachedir - Given a list of things to remove, cleanup() will remove them if it can. - Never fails, just tries to remove things and returns regardless of - failures removing things. + def _writeYumConf(): + """_writeYumConf() - """ + Generate a temporary yum.conf file for image generation. Returns the path + to the temporary yum.conf file on success, None of failure. + """ - if trash != []: - for item in trash: - if os.path.isdir(item): - shutil.rmtree(item, ignore_errors=True) - else: - os.unlink(item) + tmpdir = conf['tmpdir'] + (fd, yumconf) = tempfile.mkstemp(prefix='yum.conf', dir=tmpdir) + f = os.fdopen(fd, 'w') - if os.path.isdir(conf['tmpdir']): - shutil.rmtree(conf['tmpdir'], ignore_errors=True) + f.write("[main]\n") + f.write("cachedir=%s\n" % (self.cachedir,)) + f.write("keepcache=0\n") + f.write("gpgcheck=0\n") + f.write("plugins=0\n") + f.write("reposdir=\n") + f.write("tsflags=nodocs\n\n") + f.write("[loraxrepo]\n") + f.write("name=lorax repo\n") + f.write("baseurl=%s\n" % (self.repo,)) + f.write("enabled=1\n\n") - return + if self.extrarepos != []: + n = 1 + for extra in self.extrarepos: + f.write("[lorax-extrarepo-%d]\n" % (n,)) + f.write("name=lorax extra repo %d\n" % (n,)) + f.write("baseurl=%s\n" % (extra,)) + f.write("enabled=1\n") + n += 1 + + if self.mirrorlist != []: + n = 1 + for mirror in self.mirrorlist: + f.write("[lorax-mirrorlistrepo-%d]\n" % (n,)) + f.write("name=lorax mirrorlist repo %d\n" % (n,)) + f.write("mirrorlist=%s\n" % (mirror,)) + f.write("enabled=1\n") + n += 1 + + f.close() + print("Wrote lorax yum configuration to %s" % (yumconf,)) + + return yumconf diff --git a/src/pylorax/instroot.py b/src/pylorax/instroot.py index a5d2f064..be0c66d7 100644 --- a/src/pylorax/instroot.py +++ b/src/pylorax/instroot.py @@ -29,9 +29,8 @@ import pylorax sys.path.insert(0, '/usr/share/yum-cli') import yummain -# Create inst root from which stage 1 and stage 2 images are built. -def createInstRoot(yumconf=None, arch=None, treedir=None, updates=None): - """createInstRoot(yumconf=None, arch=None, treedir=None, [updates=None]) +class InstRoot: + """InstRoot(yumconf=None, arch=None, treedir=None, [updates=None]) Create a instroot tree for the specified architecture. The list of packages to install are specified in the /etc/lorax/packages and @@ -50,335 +49,310 @@ def createInstRoot(yumconf=None, arch=None, treedir=None, updates=None): """ - if yumconf is None or arch is None or treedir is None: - return False + # Create inst root from which stage 1 and stage 2 images are built. + def __init__(self, yumconf=None, arch=None, treedir=None, updates=None): + self.yumconf = yumconf + self.arch = arch + self.treedir = treedir + self.updates = updates - # on 64-bit systems, make sure we use lib64 as the lib directory - if arch.endswith('64') or arch == 's390x': - libdir = 'lib64' - else: - libdir = 'lib' + # XXX: these tests should raise exceptions + if yumconf is None or arch is None or treedir is None: + return False - # the directory where the instroot will be created - destdir = os.path.join(treedir, 'install') - os.makedirs(destdir) + # on 64-bit systems, make sure we use lib64 as the lib directory + if self.arch.endswith('64') or self.arch == 's390x': + self.libdir = 'lib64' + else: + self.libdir = 'lib' - # build a list of packages to install - packages = set() + # the directory where the instroot will be created + self.destdir = os.path.join(self.treedir, 'install') + if not os.path.isdir(self.destdir): + os.makedirs(self.destdir) - packages_files = [] - packages_files.append(os.path.join(pylorax.conf['confdir'], 'packages')) - packages_files.append(os.path.join(pylorax.conf['confdir'], arch, 'packages')) + # build a list of packages to install + self.packages = self._getPackageList() - for pfile in packages_files: - if os.path.isfile(pfile): - f = open(pfile, 'r') - for line in f.readlines(): - line = line.strip() + # install the packages to the instroot + self._installPackages() - if line.startswith('#') or line == '': - continue + # scrub instroot + self._scrubInstRoot() - if line.startswith('-'): - try: - packages.remove(line[1:]) - except KeyError: - pass - else: - packages.add(line) + def _getPackageList(self): + packages = set() + packages_files = [] + packages_files.append(os.path.join(pylorax.conf['confdir'], 'packages')) + packages_files.append(os.path.join(pylorax.conf['confdir'], self.arch, 'packages')) + + for pfile in packages_files: + if os.path.isfile(pfile): + f = open(pfile, 'r') + for line in f.readlines(): + line = line.strip() + + if line.startswith('#') or line == '': + continue + + if line.startswith('-'): + try: + packages.remove(line[1:]) + except KeyError: + pass + else: + packages.add(line) + + f.close() + + packages = list(packages) + packages.sort() + + return packages + + # Call yummain to install the list of packages to destdir + def _installPackages(self): + # build the list of arguments to pass to yum + arglist = ['-c', self.yumconf] + arglist.append("--installroot=%s" % (self.destdir,)) + arglist += ['install', '-y'] + self.packages + + # do some prep work on the destdir before calling yum + os.makedirs(os.path.join(self.destdir, 'usr', 'lib', 'debug')) + os.makedirs(os.path.join(self.destdir, 'usr', 'src', 'debug')) + os.makedirs(os.path.join(self.destdir, 'tmp')) + os.makedirs(os.path.join(self.destdir, 'var', 'log')) + os.makedirs(os.path.join(self.destdir, 'var', 'lib')) + os.symlink(os.path.join(os.path.sep, 'tmp'), os.path.join(self.destdir, 'var', 'lib', 'xkb')) + + # XXX: sort through yum errcodes and return False for actual bad things + # we care about + errcode = yummain.user_main(arglist, exit_code=False) + + # Scrub the instroot tree (remove files we don't want, modify settings, etc) + def _scrubInstRoot(self): + print + + # 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') + print "Installing %s..." % (os.path.join(os.path.sep, '.gconf', 'desktop', 'gnome', 'interface', '%gconf.xml'),) + shutil.copy(dogtailconf, dest) - packages = list(packages) - packages.sort() + # 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') + print "Installing %s..." % (os.path.join(os.path.sep, 'etc', 'selinux', 'config'),) + shutil.copy(src, dest) - # install the packages to the instroot - if not installPackages(yumconf=yumconf, destdir=destdir, packages=packages): - sys.stderr.write("ERROR: Could not install packages.\n") - sys.exit(1) - - if not scrubInstRoot(destdir=destdir, libdir=libdir, arch=arch): - sys.stderr.write("ERROR: Could not scrub instroot.\n") - sys.exit(1) - - return True - -# Call yummain to install the list of packages to destdir -def installPackages(yumconf=None, destdir=None, packages=None): - """installPackages(yumconf=yumconf, destdir=destdir, packages=packages) - - Call yummain to install the list of packages. All parameters are - required. yumconf is the yum configuration file created for this - run of lorax. destdir is the installroot that yum should install to. - packages is a list of package names that yum should install. - - yum will resolve dependencies, so it is not necessary to list every - package you want in the instroot. - - This function returns True on success, False on failre. - - """ - - if yumconf is None or destdir is None or packages is None or packages == []: - return False - - # build the list of arguments to pass to yum - arglist = ['-c', yumconf] - arglist.append("--installroot=%s" % (destdir,)) - arglist += ['install', '-y'] + packages - - # do some prep work on the destdir before calling yum - os.makedirs(os.path.join(destdir, 'usr', 'lib', 'debug')) - os.makedirs(os.path.join(destdir, 'usr', 'src', 'debug')) - os.makedirs(os.path.join(destdir, 'tmp')) - os.makedirs(os.path.join(destdir, 'var', 'log')) - os.makedirs(os.path.join(destdir, 'var', 'lib')) - 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 - # we care about - errcode = yummain.user_main(arglist, exit_code=False) - return True - -# Scrub the instroot tree (remove files we don't want, modify settings, etc) -def scrubInstRoot(destdir=None, libdir='lib', arch=None): - """scrubInstRoot(destdir=None, libdir='lib', arch=None) - - Clean up the newly created instroot and make the tree more suitable to - run the installer. - - destdir is the path to the instroot. libdir is the subdirectory in - /usr for libraries (either lib or lib64). arch is the architecture - the image is for (e.g., i386, x86_64, ppc, s390x, alpha, sparc). - - """ - - if destdir is None or not os.path.isdir(destdir) or arch is None: - return False - - print - - # 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') - print "Installing %s..." % (os.path.join(os.path.sep, '.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') + # 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): - dest = os.path.join(destdir, 'etc', 'selinux', 'config') - print "Installing %s..." % (os.path.join(os.path.sep, 'etc', 'selinux', 'config'),) + print "Installing %s..." % (os.path.join(os.path.sep, 'etc', 'libuser.conf'),) 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): - print "Installing %s..." % (os.path.join(os.path.sep, 'etc', 'libuser.conf'),) - 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 - # 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): + print "\nReading %s..." % (os.path.join(os.path.sep, 'etc', 'gtk-2.0', 'gtkrc'),) + f = open(gtkrc, 'r') + lines = f.readlines() + f.close() - if os.path.isfile(gtkrc): - print "\nReading %s..." % (os.path.join(os.path.sep, 'etc', 'gtk-2.0', '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() + print " gtk-theme-name: %s" % (gtk_theme_name,) - for line in lines: - line = line.strip() - if line.startswith('gtk-theme-name'): - gtk_theme_name = line[line.find('=') + 1:].replace('"', '').strip() - print " gtk-theme-name: %s" % (gtk_theme_name,) - - # 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('"', '') - print " gtk-engine: %s" % (gtk_engine,) - break - elif line.startswith('gtk-icon-theme-name'): - icon_theme = line[line.find('=') + 1:].replace('"', '').strip() - print " gtk-icon-theme-name: %s" % (icon_theme,) - gtk_icon_themes.append(icon_theme) - - # bring in all inherited themes - while True: - icon_theme_index = os.path.join(destdir, 'usr', 'share', 'icons', icon_theme, 'index.theme') - if os.path.isfile(icon_theme_index): - inherits = False - f = open(icon_theme_index, 'r') - icon_lines = f.readlines() + # 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 icon_line in icon_lines: - icon_line = icon_line.strip() - if icon_line.startswith('Inherits='): - inherits = True - icon_theme = icon_line[icon_line.find('=') + 1:].replace('"', '') - print " inherits gtk-icon-theme-name: %s" % (icon_theme,) - gtk_icon_themes.append(icon_theme) + 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('"', '') + print " gtk-engine: %s" % (gtk_engine,) break + elif line.startswith('gtk-icon-theme-name'): + icon_theme = line[line.find('=') + 1:].replace('"', '').strip() + print " gtk-icon-theme-name: %s" % (icon_theme,) + gtk_icon_themes.append(icon_theme) - if not inherits: + # bring in all inherited themes + while True: + icon_theme_index = os.path.join(destdir, 'usr', 'share', 'icons', icon_theme, 'index.theme') + if os.path.isfile(icon_theme_index): + inherits = False + 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='): + inherits = True + icon_theme = icon_line[icon_line.find('=') + 1:].replace('"', '') + print " inherits gtk-icon-theme-name: %s" % (icon_theme,) + gtk_icon_themes.append(icon_theme) + break + + if not inherits: + break + else: break - else: - break - 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_errors=True) + 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_errors=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): + 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) + + # clean out unused locales + langtable = os.path.join(destdir, 'usr', 'lib', 'anaconda', 'lang-table') + localepath = os.path.join(destdir, 'usr', 'share', 'locale') + if os.path.isfile(langtable): + locales = set() + all_locales = set() + + f = open(langtable, 'r') + lines = f.readlines() + f.close() + + print "Keeping locales used during installation..." + for line in lines: + line = line.strip() + + if line == '' or line.startswith('#'): 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) + fields = line.split('\t') - # clean out unused locales - langtable = os.path.join(destdir, 'usr', 'lib', 'anaconda', 'lang-table') - localepath = os.path.join(destdir, 'usr', 'share', 'locale') - if os.path.isfile(langtable): - locales = set() - all_locales = set() + if os.path.isdir(os.path.join(localepath, fields[1])): + locales.add(fields[1]) - f = open(langtable, 'r') - lines = f.readlines() - f.close() + locale = fields[3].split('.')[0] + if os.path.isdir(os.path.join(localepath, locale)): + locales.add(locale) - print "Keeping locales used during installation..." - for line in lines: - line = line.strip() + for locale in os.listdir(os.path.join(destdir, 'usr', 'share', 'locale')): + all_locales.add(locale) - if line == '' or line.startswith('#'): - continue + print "Removing unused locales..." + locales_to_remove = list(all_locales.difference(locales)) + for locale in locales_to_remove: + rmpath = os.path.join(destdir, 'usr', 'share', 'locale', locale) + shutil.rmtree(rmpath, ignore_errors=True) - fields = line.split('\t') + # fix up some links for man page related stuff + for file in ['nroff', 'groff', 'iconv', 'geqn', 'gtbl', 'gpic', 'grefer']: + src = os.path.join('mnt', 'sysimage', 'usr', 'bin', file) + dst = os.path.join(destdir, 'usr', 'bin', file) + if not os.path.isfile(dst): + os.symlink(src, dst) - if os.path.isdir(os.path.join(localepath, fields[1])): - locales.add(fields[1]) + # install anaconda stub programs as instroot programs + for subdir in ['lib', 'firmware']: + subdir = os.path.join(destdir, subdir) + if not os.path.isdir(subdir): + os.makedirs(subdir) - locale = fields[3].split('.')[0] - if os.path.isdir(os.path.join(localepath, locale)): - locales.add(locale) - - for locale in os.listdir(os.path.join(destdir, 'usr', 'share', 'locale')): - all_locales.add(locale) - - print "Removing unused locales..." - locales_to_remove = list(all_locales.difference(locales)) - for locale in locales_to_remove: - rmpath = os.path.join(destdir, 'usr', 'share', 'locale', locale) - shutil.rmtree(rmpath, ignore_errors=True) - - # fix up some links for man page related stuff - for file in ['nroff', 'groff', 'iconv', 'geqn', 'gtbl', 'gpic', 'grefer']: - src = os.path.join('mnt', 'sysimage', 'usr', 'bin', file) - dst = os.path.join(destdir, 'usr', 'bin', file) - if not os.path.isfile(dst): + for subdir in ['modules', 'firmware']: + src = os.path.join(os.path.sep, subdir) + dst = os.path.join(destdir, 'lib', subdir) + shutil.rmtree(dst, ignore_errors=True) os.symlink(src, dst) - # install anaconda stub programs as instroot programs - for subdir in ['lib', 'firmware']: - subdir = os.path.join(destdir, subdir) - if not os.path.isdir(subdir): - os.makedirs(subdir) + for prog in ['raidstart', 'raidstop', 'losetup', 'list-harddrives', 'loadkeys', 'mknod', 'sysklogd']: + stub = "%s-stub" % (prog,) + src = os.path.join(destdir, 'usr', 'lib', 'anaconda', stub) + dst = os.path.join(destdir, 'usr', 'bin', prog) + if os.path.isfile(src) and not os.path.isfile(dst): + shutil.copy2(src, dst) - for subdir in ['modules', 'firmware']: - src = os.path.join(os.path.sep, subdir) - dst = os.path.join(destdir, 'lib', subdir) - shutil.rmtree(dst, ignore_errors=True) - os.symlink(src, dst) + # copy in boot loader files + bootpath = os.path.join(destdir, 'usr', 'lib', 'anaconda-runtime', 'boot') + if not os.path.isdir(bootpath): + os.makedirs(bootpath) - for prog in ['raidstart', 'raidstop', 'losetup', 'list-harddrives', 'loadkeys', 'mknod', 'sysklogd']: - stub = "%s-stub" % (prog,) - src = os.path.join(destdir, 'usr', 'lib', 'anaconda', stub) - dst = os.path.join(destdir, 'usr', 'bin', prog) - if os.path.isfile(src) and not os.path.isfile(dst): + if arch == 'i386' or arch == 'x86_64': + for bootfile in os.listdir(os.path.join(destdir, 'boot')): + if bootfile.startswith('memtest'): + src = os.path.join(destdir, 'boot', bootfile) + dst = os.path.join(bootpath, bootfile) + shutil.copy2(src, dst) + elif arch.startswith('sparc'): + for bootfile in os.listdir(os.path.join(destdir, 'boot')): + if bootfile.endswith('.b'): + src = os.path.join(destdir, 'boot', bootfile) + dst = os.path.join(bootpath, bootfile) + shutil.copy2(src, dst) + elif arch.startswith('ppc'): + src = os.path.join(destdir, 'boot', 'efika.forth') + dst = os.path.join(bootpath, 'efika.forth') shutil.copy2(src, dst) + elif arch == 'alpha': + src = os.path.join(destdir, 'boot', 'bootlx') + dst = os.path.join(bootpath, 'bootlx') + shutil.copy2(src, dst) + elif arch == 'ia64': + src = os.path.join(destdir, 'boot', 'efi', 'EFI', 'redhat') + shutil.rmtree(bootpath, ignore_errors=True) + shutil.copytree(src, bootpath) - # copy in boot loader files - bootpath = os.path.join(destdir, 'usr', 'lib', 'anaconda-runtime', 'boot') - if not os.path.isdir(bootpath): - os.makedirs(bootpath) + # move the yum repos configuration directory + src = os.path.join(destdir, 'etc', 'yum.repos.d') + dst = os.path.join(destdir, 'etc', 'anaconda.repos.d') + if os.path.isdir(src): + shutil.rmtree(dst, ignore_errors=True) + shutil.move(src, dst) - if arch == 'i386' or arch == 'x86_64': - for bootfile in os.listdir(os.path.join(destdir, 'boot')): - if bootfile.startswith('memtest'): - src = os.path.join(destdir, 'boot', bootfile) - dst = os.path.join(bootpath, bootfile) - shutil.copy2(src, dst) - elif arch.startswith('sparc'): - for bootfile in os.listdir(os.path.join(destdir, 'boot')): - if bootfile.endswith('.b'): - src = os.path.join(destdir, 'boot', bootfile) - dst = os.path.join(bootpath, bootfile) - shutil.copy2(src, dst) - elif arch.startswith('ppc'): - src = os.path.join(destdir, 'boot', 'efika.forth') - dst = os.path.join(bootpath, 'efika.forth') - shutil.copy2(src, dst) - elif arch == 'alpha': - src = os.path.join(destdir, 'boot', 'bootlx') - dst = os.path.join(bootpath, 'bootlx') - shutil.copy2(src, dst) - elif arch == 'ia64': - src = os.path.join(destdir, 'boot', 'efi', 'EFI', 'redhat') - shutil.rmtree(bootpath, ignore_errors=True) - shutil.copytree(src, bootpath) + # remove things we do not want in the instroot + for subdir in ['boot', 'home', 'root', 'tmp']: + shutil.rmtree(os.path.join(destdir, subdir), ignore_errors=True) - # move the yum repos configuration directory - src = os.path.join(destdir, 'etc', 'yum.repos.d') - dst = os.path.join(destdir, 'etc', 'anaconda.repos.d') - if os.path.isdir(src): - shutil.rmtree(dst, ignore_errors=True) - shutil.move(src, dst) + for subdir in ['doc', 'info']: + shutil.rmtree(os.path.join(destdir, 'usr', 'share', subdir), ignore_errors=True) - # remove things we do not want in the instroot - for subdir in ['boot', 'home', 'root', 'tmp']: - shutil.rmtree(os.path.join(destdir, subdir), ignore_errors=True) - - for subdir in ['doc', 'info']: - shutil.rmtree(os.path.join(destdir, 'usr', 'share', subdir), ignore_errors=True) - - for libname in glob.glob(os.path.join(destdir, 'usr', libdir), 'libunicode-lite*'): - shutil.rmtree(libname, ignore_errors=True) - - return True + for libname in glob.glob(os.path.join(destdir, 'usr', libdir), 'libunicode-lite*'): + shutil.rmtree(libname, ignore_errors=True)