summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorEd Bartosh <ed.bartosh@linux.intel.com>2017-01-24 15:43:50 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-01-31 14:12:46 +0000
commit4e9952514211ef4b9a3731ce915090385f335a31 (patch)
tree51ee8cb2cfcf6a0ddf53a1ec32a8fabd347d9a9c /scripts
parentad116c4d02ccf36e22fbf3e45e45bc508849a833 (diff)
downloadopenembedded-core-4e9952514211ef4b9a3731ce915090385f335a31.tar.gz
openembedded-core-4e9952514211ef4b9a3731ce915090385f335a31.tar.bz2
openembedded-core-4e9952514211ef4b9a3731ce915090385f335a31.zip
wic: get rid of baseimager inheritance
Simplified DirectImageCreator code by removing inheritance from BaseImageCreator. This inheritance doesn't make much sense as DirectImageCreator is the only class that was inherited from BaseImageCreator. Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/lib/wic/imager/baseimager.py191
-rw-r--r--scripts/lib/wic/imager/direct.py19
2 files changed, 13 insertions, 197 deletions
diff --git a/scripts/lib/wic/imager/baseimager.py b/scripts/lib/wic/imager/baseimager.py
deleted file mode 100644
index 1a52dd8b4d..0000000000
--- a/scripts/lib/wic/imager/baseimager.py
+++ /dev/null
@@ -1,191 +0,0 @@
-#!/usr/bin/env 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.
-
-import os
-import tempfile
-import shutil
-
-from wic import msger
-from wic.utils.errors import CreatorError
-from wic.utils import runner
-
-class BaseImageCreator():
- """Base class for image creation.
-
- BaseImageCreator is the simplest creator class available; it will
- create a system image according to the supplied kickstart file.
-
- e.g.
-
- import wic.imgcreate as imgcreate
- ks = imgcreate.read_kickstart("foo.ks")
- imgcreate.ImageCreator(ks, "foo").create()
- """
-
- def __del__(self):
- self.cleanup()
-
- def __init__(self, createopts=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.__builddir = None
-
- self.ks = None
- self.name = "target"
- self.tmpdir = "/var/tmp/wic"
- self.workdir = "/var/tmp/wic/build"
-
- # setup tmpfs tmpdir when enabletmpfs is True
- self.enabletmpfs = False
-
- if createopts:
- # Mapping table for variables that have different names.
- optmap = {"outdir" : "destdir",
- }
-
- # update setting from createopts
- for key in createopts:
- 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))
-
- self._dep_checks = ["ls", "bash", "cp", "echo"]
-
- # Output image file names
- self.outimage = []
-
- # 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.partitions:
- if part.fstype and part.fstype == "btrfs":
- self._dep_checks.append("mkfs.btrfs")
- break
-
- # make sure the specified tmpdir and cachedir exist
- if not os.path.exists(self.tmpdir):
- os.makedirs(self.tmpdir)
-
-
- #
- # Hooks for subclasses
- #
- def _create(self):
- """Create partitions for the disk image(s)
-
- This is the hook where subclasses may create the partitions
- that will be assembled into disk image(s).
-
- There is no default implementation.
- """
- pass
-
- def _cleanup(self):
- """Undo anything performed in _create().
-
- This is the hook where subclasses must undo anything which was
- done in _create().
-
- There is no default implementation.
-
- """
- pass
-
- #
- # Actual implementation
- #
- def __ensure_builddir(self):
- if not self.__builddir is None:
- return
-
- try:
- self.workdir = os.path.join(self.tmpdir, "build")
- if not os.path.exists(self.workdir):
- os.makedirs(self.workdir)
- self.__builddir = tempfile.mkdtemp(dir=self.workdir,
- prefix="imgcreate-")
- except OSError as err:
- raise CreatorError("Failed create build directory in %s: %s" %
- (self.tmpdir, err))
-
- def __setup_tmpdir(self):
- if not self.enabletmpfs:
- return
-
- runner.show('mount -t tmpfs -o size=4G tmpfs %s' % self.workdir)
-
- def __clean_tmpdir(self):
- if not self.enabletmpfs:
- return
-
- runner.show('umount -l %s' % self.workdir)
-
- def create(self):
- """Create partitions for the disk image(s)
-
- Create the partitions that will be assembled into disk
- image(s).
- """
- self.__setup_tmpdir()
- self.__ensure_builddir()
-
- self._create()
-
- def cleanup(self):
- """Undo anything performed in create().
-
- Note, make sure to call this method once finished with the creator
- instance in order to ensure no stale files are left on the host e.g.:
-
- creator = ImageCreator(ks, name)
- try:
- creator.create()
- finally:
- creator.cleanup()
-
- """
- if not self.__builddir:
- return
-
- self._cleanup()
-
- shutil.rmtree(self.__builddir, ignore_errors=True)
- self.__builddir = None
-
- self.__clean_tmpdir()
-
-
- def print_outimage_info(self):
- msg = "The new image can be found here:\n"
- self.outimage.sort()
- for path in self.outimage:
- msg += ' %s\n' % os.path.abspath(path)
-
- msger.info(msg)
diff --git a/scripts/lib/wic/imager/direct.py b/scripts/lib/wic/imager/direct.py
index 52828c10cd..825c9d7f6e 100644
--- a/scripts/lib/wic/imager/direct.py
+++ b/scripts/lib/wic/imager/direct.py
@@ -32,7 +32,6 @@ from wic import msger
from wic.utils.oe.misc import get_bitbake_var
from wic.utils.partitionedfs import Image
from wic.utils.errors import CreatorError, ImageError
-from wic.imager.baseimager import BaseImageCreator
from wic.plugin import pluginmgr
from wic.utils.oe.misc import exec_cmd, exec_native_cmd
@@ -61,7 +60,7 @@ class DiskImage():
self.created = True
-class DirectImageCreator(BaseImageCreator):
+class DirectImageCreator:
"""
Installs a system into a file containing a partitioned disk image.
@@ -72,15 +71,23 @@ class DirectImageCreator(BaseImageCreator):
media and used on actual hardware.
"""
- def __init__(self, oe_builddir, image_output_dir, rootfs_dir, bootimg_dir,
- kernel_dir, native_sysroot, compressor, creatoropts=None,
- bmap=False):
+ def __init__(self, oe_builddir, image_output_dir, rootfs_dir,
+ bootimg_dir, kernel_dir, native_sysroot, compressor,
+ creatoropts, bmap=False):
"""
Initialize a DirectImageCreator instance.
This method takes the same arguments as ImageCreator.__init__()
"""
- BaseImageCreator.__init__(self, creatoropts)
+
+ self.name = creatoropts['name']
+ self.ks = creatoropts['ks']
+
+ self.tmpdir = "/var/tmp/wic"
+ self.workdir = "/var/tmp/wic/build"
+
+ if not os.path.exists(self.tmpdir):
+ os.makedirs(self.tmpdir)
self.__image = None
self.__disks = {}