summaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic/engine.py
diff options
context:
space:
mode:
authorEd Bartosh <ed.bartosh@linux.intel.com>2015-09-02 13:58:02 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-09-03 12:43:25 +0100
commit7d4bb40905fab38fb3db1d0e17afbc803622f00c (patch)
treefea3791bf21dce5d7693ce0a695e49a5579b25b4 /scripts/lib/wic/engine.py
parent77561e719181d58289687373eebadce764f838a7 (diff)
downloadpoky-7d4bb40905fab38fb3db1d0e17afbc803622f00c.tar.gz
wic: get rid of scripts/lib/image
Moved content of scripts/lib/image/ to scripts/lib/wic as one directory with the same name as a tool is self-explanatory and less confusing than two. (From OE-Core rev: 5dc02d572794298b3362378cea3d7da654456c44) Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/wic/engine.py')
-rw-r--r--scripts/lib/wic/engine.py241
1 files changed, 241 insertions, 0 deletions
diff --git a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py
new file mode 100644
index 0000000000..a034841a7a
--- /dev/null
+++ b/scripts/lib/wic/engine.py
@@ -0,0 +1,241 @@
1# ex:ts=4:sw=4:sts=4:et
2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3#
4# Copyright (c) 2013, Intel Corporation.
5# All rights reserved.
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License version 2 as
9# published by the Free Software Foundation.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License along
17# with this program; if not, write to the Free Software Foundation, Inc.,
18# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19#
20# DESCRIPTION
21
22# This module implements the image creation engine used by 'wic' to
23# create images. The engine parses through the OpenEmbedded kickstart
24# (wks) file specified and generates images that can then be directly
25# written onto media.
26#
27# AUTHORS
28# Tom Zanussi <tom.zanussi (at] linux.intel.com>
29#
30
31import os
32import sys
33
34from wic import msger, creator
35from wic.utils import misc
36from wic.plugin import pluginmgr
37from wic.utils.oe import misc
38
39
40def verify_build_env():
41 """
42 Verify that the build environment is sane.
43
44 Returns True if it is, false otherwise
45 """
46 try:
47 builddir = os.environ["BUILDDIR"]
48 except KeyError:
49 print "BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)"
50 sys.exit(1)
51
52 return True
53
54
55CANNED_IMAGE_DIR = "lib/wic/canned-wks" # relative to scripts
56SCRIPTS_CANNED_IMAGE_DIR = "scripts/" + CANNED_IMAGE_DIR
57
58def build_canned_image_list(dl):
59 layers_path = misc.get_bitbake_var("BBLAYERS")
60 canned_wks_layer_dirs = []
61
62 if layers_path is not None:
63 for layer_path in layers_path.split():
64 path = os.path.join(layer_path, SCRIPTS_CANNED_IMAGE_DIR)
65 canned_wks_layer_dirs.append(path)
66
67 path = os.path.join(dl, CANNED_IMAGE_DIR)
68 canned_wks_layer_dirs.append(path)
69
70 return canned_wks_layer_dirs
71
72def find_canned_image(scripts_path, wks_file):
73 """
74 Find a .wks file with the given name in the canned files dir.
75
76 Return False if not found
77 """
78 layers_canned_wks_dir = build_canned_image_list(scripts_path)
79
80 for canned_wks_dir in layers_canned_wks_dir:
81 for root, dirs, files in os.walk(canned_wks_dir):
82 for file in files:
83 if file.endswith("~") or file.endswith("#"):
84 continue
85 if file.endswith(".wks") and wks_file + ".wks" == file:
86 fullpath = os.path.join(canned_wks_dir, file)
87 return fullpath
88 return None
89
90
91def list_canned_images(scripts_path):
92 """
93 List the .wks files in the canned image dir, minus the extension.
94 """
95 layers_canned_wks_dir = build_canned_image_list(scripts_path)
96
97 for canned_wks_dir in layers_canned_wks_dir:
98 for root, dirs, files in os.walk(canned_wks_dir):
99 for file in files:
100 if file.endswith("~") or file.endswith("#"):
101 continue
102 if file.endswith(".wks"):
103 fullpath = os.path.join(canned_wks_dir, file)
104 f = open(fullpath, "r")
105 lines = f.readlines()
106 for line in lines:
107 desc = ""
108 idx = line.find("short-description:")
109 if idx != -1:
110 desc = line[idx + len("short-description:"):].strip()
111 break
112 basename = os.path.splitext(file)[0]
113 print " %s\t\t%s" % (basename.ljust(30), desc)
114
115
116def list_canned_image_help(scripts_path, fullpath):
117 """
118 List the help and params in the specified canned image.
119 """
120 f = open(fullpath, "r")
121 lines = f.readlines()
122 found = False
123 for line in lines:
124 if not found:
125 idx = line.find("long-description:")
126 if idx != -1:
127 print
128 print line[idx + len("long-description:"):].strip()
129 found = True
130 continue
131 if not line.strip():
132 break
133 idx = line.find("#")
134 if idx != -1:
135 print line[idx + len("#:"):].rstrip()
136 else:
137 break
138
139
140def list_source_plugins():
141 """
142 List the available source plugins i.e. plugins available for --source.
143 """
144 plugins = pluginmgr.get_source_plugins()
145
146 for plugin in plugins:
147 print " %s" % plugin
148
149
150def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
151 native_sysroot, scripts_path, image_output_dir,
152 compressor, debug):
153 """Create image
154
155 wks_file - user-defined OE kickstart file
156 rootfs_dir - absolute path to the build's /rootfs dir
157 bootimg_dir - absolute path to the build's boot artifacts directory
158 kernel_dir - absolute path to the build's kernel directory
159 native_sysroot - absolute path to the build's native sysroots dir
160 scripts_path - absolute path to /scripts dir
161 image_output_dir - dirname to create for image
162 compressor - compressor utility to compress the image
163
164 Normally, the values for the build artifacts values are determined
165 by 'wic -e' from the output of the 'bitbake -e' command given an
166 image name e.g. 'core-image-minimal' and a given machine set in
167 local.conf. If that's the case, the variables get the following
168 values from the output of 'bitbake -e':
169
170 rootfs_dir: IMAGE_ROOTFS
171 kernel_dir: DEPLOY_DIR_IMAGE
172 native_sysroot: STAGING_DIR_NATIVE
173
174 In the above case, bootimg_dir remains unset and the
175 plugin-specific image creation code is responsible for finding the
176 bootimg artifacts.
177
178 In the case where the values are passed in explicitly i.e 'wic -e'
179 is not used but rather the individual 'wic' options are used to
180 explicitly specify these values.
181 """
182 try:
183 oe_builddir = os.environ["BUILDDIR"]
184 except KeyError:
185 print "BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)"
186 sys.exit(1)
187
188 if debug:
189 msger.set_loglevel('debug')
190
191 cr = creator.Creator()
192
193 cr.main(["direct", native_sysroot, kernel_dir, bootimg_dir, rootfs_dir,
194 wks_file, image_output_dir, oe_builddir, compressor or ""])
195
196 print "\nThe image(s) were created using OE kickstart file:\n %s" % wks_file
197
198
199def wic_list(args, scripts_path, properties_file):
200 """
201 Print the complete list of properties defined by the image, or the
202 possible values for a particular image property.
203 """
204 if len(args) < 1:
205 return False
206
207 if len(args) == 1:
208 if args[0] == "images":
209 list_canned_images(scripts_path)
210 return True
211 elif args[0] == "source-plugins":
212 list_source_plugins()
213 return True
214 elif args[0] == "properties":
215 return True
216 else:
217 return False
218
219 if len(args) == 2:
220 if args[0] == "properties":
221 wks_file = args[1]
222 print "print properties contained in wks file: %s" % wks_file
223 return True
224 elif args[0] == "property":
225 print "print property values for property: %s" % args[1]
226 return True
227 elif args[1] == "help":
228 wks_file = args[0]
229 fullpath = find_canned_image(scripts_path, wks_file)
230 if not fullpath:
231 print "No image named %s found, exiting. "\
232 "(Use 'wic list images' to list available images, or "\
233 "specify a fully-qualified OE kickstart (.wks) "\
234 "filename)\n" % wks_file
235 sys.exit(1)
236 list_canned_image_help(scripts_path, fullpath)
237 return True
238 else:
239 return False
240
241 return False