summaryrefslogtreecommitdiffstats
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:38:31 +0000
commit75318c7b0c0ce1f811fb020692abe572c5192743 (patch)
tree1b39809cb97ef7a36525a860b4dc3118c1ee9bcf /scripts
parent88dce2cf41304df1716472864a36f6be4ad3c502 (diff)
downloadpoky-75318c7b0c0ce1f811fb020692abe572c5192743.tar.gz
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. (From OE-Core rev: 4e9952514211ef4b9a3731ce915090385f335a31) 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 @@
1#!/usr/bin/env python -tt
2#
3# Copyright (c) 2007 Red Hat Inc.
4# Copyright (c) 2009, 2010, 2011 Intel, Inc.
5#
6# This program is free software; you can redistribute it and/or modify it
7# under the terms of the GNU General Public License as published by the Free
8# Software Foundation; version 2 of the License
9#
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13# for more details.
14#
15# You should have received a copy of the GNU General Public License along
16# with this program; if not, write to the Free Software Foundation, Inc., 59
17# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19import os
20import tempfile
21import shutil
22
23from wic import msger
24from wic.utils.errors import CreatorError
25from wic.utils import runner
26
27class BaseImageCreator():
28 """Base class for image creation.
29
30 BaseImageCreator is the simplest creator class available; it will
31 create a system image according to the supplied kickstart file.
32
33 e.g.
34
35 import wic.imgcreate as imgcreate
36 ks = imgcreate.read_kickstart("foo.ks")
37 imgcreate.ImageCreator(ks, "foo").create()
38 """
39
40 def __del__(self):
41 self.cleanup()
42
43 def __init__(self, createopts=None):
44 """Initialize an ImageCreator instance.
45
46 ks -- a pykickstart.KickstartParser instance; this instance will be
47 used to drive the install by e.g. providing the list of packages
48 to be installed, the system configuration and %post scripts
49
50 name -- a name for the image; used for e.g. image filenames or
51 filesystem labels
52 """
53
54 self.__builddir = None
55
56 self.ks = None
57 self.name = "target"
58 self.tmpdir = "/var/tmp/wic"
59 self.workdir = "/var/tmp/wic/build"
60
61 # setup tmpfs tmpdir when enabletmpfs is True
62 self.enabletmpfs = False
63
64 if createopts:
65 # Mapping table for variables that have different names.
66 optmap = {"outdir" : "destdir",
67 }
68
69 # update setting from createopts
70 for key in createopts:
71 if key in optmap:
72 option = optmap[key]
73 else:
74 option = key
75 setattr(self, option, createopts[key])
76
77 self.destdir = os.path.abspath(os.path.expanduser(self.destdir))
78
79 self._dep_checks = ["ls", "bash", "cp", "echo"]
80
81 # Output image file names
82 self.outimage = []
83
84 # No ks provided when called by convertor, so skip the dependency check
85 if self.ks:
86 # If we have btrfs partition we need to check necessary tools
87 for part in self.ks.partitions:
88 if part.fstype and part.fstype == "btrfs":
89 self._dep_checks.append("mkfs.btrfs")
90 break
91
92 # make sure the specified tmpdir and cachedir exist
93 if not os.path.exists(self.tmpdir):
94 os.makedirs(self.tmpdir)
95
96
97 #
98 # Hooks for subclasses
99 #
100 def _create(self):
101 """Create partitions for the disk image(s)
102
103 This is the hook where subclasses may create the partitions
104 that will be assembled into disk image(s).
105
106 There is no default implementation.
107 """
108 pass
109
110 def _cleanup(self):
111 """Undo anything performed in _create().
112
113 This is the hook where subclasses must undo anything which was
114 done in _create().
115
116 There is no default implementation.
117
118 """
119 pass
120
121 #
122 # Actual implementation
123 #
124 def __ensure_builddir(self):
125 if not self.__builddir is None:
126 return
127
128 try:
129 self.workdir = os.path.join(self.tmpdir, "build")
130 if not os.path.exists(self.workdir):
131 os.makedirs(self.workdir)
132 self.__builddir = tempfile.mkdtemp(dir=self.workdir,
133 prefix="imgcreate-")
134 except OSError as err:
135 raise CreatorError("Failed create build directory in %s: %s" %
136 (self.tmpdir, err))
137
138 def __setup_tmpdir(self):
139 if not self.enabletmpfs:
140 return
141
142 runner.show('mount -t tmpfs -o size=4G tmpfs %s' % self.workdir)
143
144 def __clean_tmpdir(self):
145 if not self.enabletmpfs:
146 return
147
148 runner.show('umount -l %s' % self.workdir)
149
150 def create(self):
151 """Create partitions for the disk image(s)
152
153 Create the partitions that will be assembled into disk
154 image(s).
155 """
156 self.__setup_tmpdir()
157 self.__ensure_builddir()
158
159 self._create()
160
161 def cleanup(self):
162 """Undo anything performed in create().
163
164 Note, make sure to call this method once finished with the creator
165 instance in order to ensure no stale files are left on the host e.g.:
166
167 creator = ImageCreator(ks, name)
168 try:
169 creator.create()
170 finally:
171 creator.cleanup()
172
173 """
174 if not self.__builddir:
175 return
176
177 self._cleanup()
178
179 shutil.rmtree(self.__builddir, ignore_errors=True)
180 self.__builddir = None
181
182 self.__clean_tmpdir()
183
184
185 def print_outimage_info(self):
186 msg = "The new image can be found here:\n"
187 self.outimage.sort()
188 for path in self.outimage:
189 msg += ' %s\n' % os.path.abspath(path)
190
191 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
32from wic.utils.oe.misc import get_bitbake_var 32from wic.utils.oe.misc import get_bitbake_var
33from wic.utils.partitionedfs import Image 33from wic.utils.partitionedfs import Image
34from wic.utils.errors import CreatorError, ImageError 34from wic.utils.errors import CreatorError, ImageError
35from wic.imager.baseimager import BaseImageCreator
36from wic.plugin import pluginmgr 35from wic.plugin import pluginmgr
37from wic.utils.oe.misc import exec_cmd, exec_native_cmd 36from wic.utils.oe.misc import exec_cmd, exec_native_cmd
38 37
@@ -61,7 +60,7 @@ class DiskImage():
61 60
62 self.created = True 61 self.created = True
63 62
64class DirectImageCreator(BaseImageCreator): 63class DirectImageCreator:
65 """ 64 """
66 Installs a system into a file containing a partitioned disk image. 65 Installs a system into a file containing a partitioned disk image.
67 66
@@ -72,15 +71,23 @@ class DirectImageCreator(BaseImageCreator):
72 media and used on actual hardware. 71 media and used on actual hardware.
73 """ 72 """
74 73
75 def __init__(self, oe_builddir, image_output_dir, rootfs_dir, bootimg_dir, 74 def __init__(self, oe_builddir, image_output_dir, rootfs_dir,
76 kernel_dir, native_sysroot, compressor, creatoropts=None, 75 bootimg_dir, kernel_dir, native_sysroot, compressor,
77 bmap=False): 76 creatoropts, bmap=False):
78 """ 77 """
79 Initialize a DirectImageCreator instance. 78 Initialize a DirectImageCreator instance.
80 79
81 This method takes the same arguments as ImageCreator.__init__() 80 This method takes the same arguments as ImageCreator.__init__()
82 """ 81 """
83 BaseImageCreator.__init__(self, creatoropts) 82
83 self.name = creatoropts['name']
84 self.ks = creatoropts['ks']
85
86 self.tmpdir = "/var/tmp/wic"
87 self.workdir = "/var/tmp/wic/build"
88
89 if not os.path.exists(self.tmpdir):
90 os.makedirs(self.tmpdir)
84 91
85 self.__image = None 92 self.__image = None
86 self.__disks = {} 93 self.__disks = {}