#!/usr/bin/python -tt
#
# Copyright (c) 2007 Red Hat Inc.
# Copyright (c) 2009, 2010, 2011 Intel, Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; version 2 of the License
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from __future__ import with_statement
import os, sys
import stat
import tempfile
import shutil
import subprocess
import re
import tarfile
import glob
from mic import kickstart
from mic import msger
from mic.utils.errors import CreatorError, Abort
from mic.utils import misc, runner, fs_related as fs
class BaseImageCreator(object):
"""Installs a system to a chroot directory.
ImageCreator is the simplest creator class available; it will install and
configure a system image according to the supplied kickstart file.
e.g.
import mic.imgcreate as imgcreate
ks = imgcreate.read_kickstart("foo.ks")
imgcreate.ImageCreator(ks, "foo").create()
"""
def __del__(self):
self.cleanup()
def __init__(self, createopts = None, pkgmgr = None):
"""Initialize an ImageCreator instance.
ks -- a pykickstart.KickstartParser instance; this instance will be
used to drive the install by e.g. providing the list of packages
to be installed, the system configuration and %post scripts
name -- a name for the image; used for e.g. image filenames or
filesystem labels
"""
self.pkgmgr = pkgmgr
self.__builddir = None
self.__bindmounts = []
self.ks = None
self.name = "target"
self.tmpdir = "/var/tmp/wic"
self.cachedir = "/var/tmp/wic/cache"
self.workdir = "/var/tmp/wic/build"
self.destdir = "."
self.installerfw_prefix = "INSTALLERFW_"
self.target_arch = "noarch"
self._local_pkgs_path = None
self.pack_to = None
self.repourl = {}
# If the kernel is save to the destdir when copy_kernel cmd is called.
self._need_copy_kernel = False
# setup tmpfs tmpdir when enabletmpfs is True
self.enabletmpfs = False
if createopts:
# Mapping table for variables that have different names.
optmap = {"pkgmgr" : "pkgmgr_name",
"outdir" : "destdir",
"arch" : "target_arch",
"local_pkgs_path" : "_local_pkgs_path",
"copy_kernel" : "_need_copy_kernel",
}
# update setting from createopts
for key in createopts.keys():
if key in optmap:
option = optmap[key]
else:
option = key
setattr(self, option, createopts[key])
self.destdir = os.path.abspath(os.path.expanduser(self.destdir))
if 'release' in createopts and createopts['release']:
self.name = createopts['release'] + '_' + self.name
if self.pack_to:
if '@NAME@' in self.pack_to:
self.pack_to = self.pack_to.replace('@NAME@', self.name)
(tar, ext) = os.path.splitext(self.pack_to)
if ext in (".gz", ".bz2") and tar.endswith(".tar"):
ext = ".tar" + ext
if ext not in misc.pack_formats:
self.pack_to += ".tar"
self._dep_checks = ["ls", "bash", "cp", "echo", "modprobe"]
# Output image file names
self.outimage = []
# A flag to generate checksum
self._genchecksum = False
self._alt_initrd_name = None
self._recording_pkgs = []
# available size in root fs, init to 0
self._root_fs_avail = 0
# Name of the disk image file that is created.
self._img_name = None
self.image_format = None
# Save qemu emulator file name in order to clean up it finally
self.qemu_emulator = None
# No ks provided when called by convertor, so skip the dependency check
if self.ks:
# If we have btrfs partition we need to check necessary tools
for part in self.ks.handler.partition.partitions:
if part.fstype and part.fstype == "btrfs":
self._dep_checks.append("mkfs.btrfs")
break
if self.target_arch and self.target_arch.startswith("arm"):
for dep in self._dep_checks:
if dep == "extlinux":
self._dep_checks.remove(dep)
if not os.path.exists("/usr/bin/qemu-arm") or \
not misc.is_statically_linked("/usr/bin/qemu-arm"):
self._dep_checks.append("qemu-arm-static")
if os.path.exists("/proc/sys/vm/vdso_enabled"):
vdso_fh = open("/proc/sys/vm/vdso_enabled","r")
vdso_value = vdso_fh.read().strip()
vdso_fh.close()
if (int)(vdso_value) == 1:
msger.warning("vdso is enabled on your host, which might "
|