summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorEd Bartosh <ed.bartosh@linux.intel.com>2017-02-14 22:21:38 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-03-04 23:18:17 +0000
commitf5ae79da406190bf27194d7cecf15926bbb6ef20 (patch)
tree8f745825923833393a896c3a084e42cd3f184528 /scripts
parent3d47a212a627af50c78099eaf7308a6d38aaf1b3 (diff)
downloadpoky-f5ae79da406190bf27194d7cecf15926bbb6ef20.tar.gz
wic: raise WicError in core modules
Replaced sys.exit with raising WicError in the core wic modules. (From OE-Core rev: 1b11437fb25ece5b3eede52344b071e875fa738f) 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/engine.py21
-rw-r--r--scripts/lib/wic/partition.py46
-rw-r--r--scripts/lib/wic/utils/misc.py6
-rw-r--r--scripts/lib/wic/utils/runner.py6
4 files changed, 36 insertions, 43 deletions
diff --git a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py
index 2ccd5107f3..38a68ed340 100644
--- a/scripts/lib/wic/engine.py
+++ b/scripts/lib/wic/engine.py
@@ -30,8 +30,8 @@
30 30
31import logging 31import logging
32import os 32import os
33import sys
34 33
34from wic.errors import WicError
35from wic.plugin import pluginmgr 35from wic.plugin import pluginmgr
36from wic.utils.misc import get_bitbake_var 36from wic.utils.misc import get_bitbake_var
37 37
@@ -44,8 +44,7 @@ def verify_build_env():
44 Returns True if it is, false otherwise 44 Returns True if it is, false otherwise
45 """ 45 """
46 if not os.environ.get("BUILDDIR"): 46 if not os.environ.get("BUILDDIR"):
47 logger.error("BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)") 47 raise WicError("BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)")
48 sys.exit(1)
49 48
50 return True 49 return True
51 50
@@ -180,8 +179,7 @@ def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
180 try: 179 try:
181 oe_builddir = os.environ["BUILDDIR"] 180 oe_builddir = os.environ["BUILDDIR"]
182 except KeyError: 181 except KeyError:
183 logger.error("BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)") 182 raise WicError("BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)")
184 sys.exit(1)
185 183
186 if not os.path.exists(options.outdir): 184 if not os.path.exists(options.outdir):
187 os.makedirs(options.outdir) 185 os.makedirs(options.outdir)
@@ -189,8 +187,7 @@ def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
189 pname = 'direct' 187 pname = 'direct'
190 plugin_class = pluginmgr.get_plugins('imager').get(pname) 188 plugin_class = pluginmgr.get_plugins('imager').get(pname)
191 if not plugin_class: 189 if not plugin_class:
192 logger.error('Unknown plugin: %s', pname) 190 raise WicError('Unknown plugin: %s' % pname)
193 sys.exit(1)
194 191
195 plugin = plugin_class(wks_file, rootfs_dir, bootimg_dir, kernel_dir, 192 plugin = plugin_class(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
196 native_sysroot, oe_builddir, options) 193 native_sysroot, oe_builddir, options)
@@ -217,11 +214,11 @@ def wic_list(args, scripts_path):
217 wks_file = args[0] 214 wks_file = args[0]
218 fullpath = find_canned_image(scripts_path, wks_file) 215 fullpath = find_canned_image(scripts_path, wks_file)
219 if not fullpath: 216 if not fullpath:
220 logger.error("No image named %s found, exiting. " 217 raise WicError("No image named %s found, exiting. "
221 "(Use 'wic list images' to list available images, or " 218 "(Use 'wic list images' to list available images, "
222 "specify a fully-qualified OE kickstart (.wks) " 219 "or specify a fully-qualified OE kickstart (.wks) "
223 "filename)\n", wks_file) 220 "filename)" % wks_file)
224 sys.exit(1) 221
225 list_canned_image_help(scripts_path, fullpath) 222 list_canned_image_help(scripts_path, fullpath)
226 return True 223 return True
227 224
diff --git a/scripts/lib/wic/partition.py b/scripts/lib/wic/partition.py
index a68dc6fd6d..e100377933 100644
--- a/scripts/lib/wic/partition.py
+++ b/scripts/lib/wic/partition.py
@@ -26,9 +26,9 @@
26 26
27import logging 27import logging
28import os 28import os
29import sys
30import tempfile 29import tempfile
31 30
31from wic.errors import WicError
32from wic.utils.misc import exec_cmd, exec_native_cmd, get_bitbake_var 32from wic.utils.misc import exec_cmd, exec_native_cmd, get_bitbake_var
33from wic.plugin import pluginmgr 33from wic.plugin import pluginmgr
34 34
@@ -99,9 +99,9 @@ class Partition():
99 if self.fixed_size: 99 if self.fixed_size:
100 rootfs_size = self.fixed_size 100 rootfs_size = self.fixed_size
101 if actual_rootfs_size > rootfs_size: 101 if actual_rootfs_size > rootfs_size:
102 logger.error("Actual rootfs size (%d kB) is larger than allowed size %d kB", 102 raise WicError("Actual rootfs size (%d kB) is larger than "
103 actual_rootfs_size, rootfs_size) 103 "allowed size %d kB" %
104 sys.exit(1) 104 (actual_rootfs_size, rootfs_size))
105 else: 105 else:
106 extra_blocks = self.get_extra_block_count(actual_rootfs_size) 106 extra_blocks = self.get_extra_block_count(actual_rootfs_size)
107 if extra_blocks < self.extra_space: 107 if extra_blocks < self.extra_space:
@@ -132,10 +132,10 @@ class Partition():
132 """ 132 """
133 if not self.source: 133 if not self.source:
134 if not self.size and not self.fixed_size: 134 if not self.size and not self.fixed_size:
135 logger.error("The %s partition has a size of zero. Please " 135 raise WicError("The %s partition has a size of zero. Please "
136 "specify a non-zero --size/--fixed-size for that " 136 "specify a non-zero --size/--fixed-size for that "
137 "partition.", self.mountpoint) 137 "partition." % self.mountpoint)
138 sys.exit(1) 138
139 if self.fstype and self.fstype == "swap": 139 if self.fstype and self.fstype == "swap":
140 self.prepare_swap_partition(cr_workdir, oe_builddir, 140 self.prepare_swap_partition(cr_workdir, oe_builddir,
141 native_sysroot) 141 native_sysroot)
@@ -157,12 +157,11 @@ class Partition():
157 plugins = pluginmgr.get_source_plugins() 157 plugins = pluginmgr.get_source_plugins()
158 158
159 if self.source not in plugins: 159 if self.source not in plugins:
160 logger.error("The '%s' --source specified for %s doesn't exist.\n\t" 160 raise WicError("The '%s' --source specified for %s doesn't exist.\n\t"
161 "See 'wic list source-plugins' for a list of available" 161 "See 'wic list source-plugins' for a list of available"
162 " --sources.\n\tSee 'wic help source-plugins' for " 162 " --sources.\n\tSee 'wic help source-plugins' for "
163 "details on adding a new source plugin.", 163 "details on adding a new source plugin." %
164 self.source, self.mountpoint) 164 (self.source, self.mountpoint))
165 sys.exit(1)
166 165
167 srcparams_dict = {} 166 srcparams_dict = {}
168 if self.sourceparams: 167 if self.sourceparams:
@@ -192,16 +191,14 @@ class Partition():
192 # further processing required Partition.size to be an integer, make 191 # further processing required Partition.size to be an integer, make
193 # sure that it is one 192 # sure that it is one
194 if not isinstance(self.size, int): 193 if not isinstance(self.size, int):
195 logger.error("Partition %s internal size is not an integer. " 194 raise WicError("Partition %s internal size is not an integer. "
196 "This a bug in source plugin %s and needs to be fixed.", 195 "This a bug in source plugin %s and needs to be fixed." %
197 self.mountpoint, self.source) 196 (self.mountpoint, self.source))
198 sys.exit(1)
199 197
200 if self.fixed_size and self.size > self.fixed_size: 198 if self.fixed_size and self.size > self.fixed_size:
201 logger.error("File system image of partition %s is larger (%d kB) " 199 raise WicError("File system image of partition %s is "
202 "than its allowed size %d kB", 200 "larger (%d kB) than its allowed size %d kB" %
203 self.mountpoint, self.size, self.fixed_size) 201 (self.mountpoint, self.size, self.fixed_size))
204 sys.exit(1)
205 202
206 def prepare_rootfs_from_fs_image(self, cr_workdir, oe_builddir, 203 def prepare_rootfs_from_fs_image(self, cr_workdir, oe_builddir,
207 rootfs_dir): 204 rootfs_dir):
@@ -241,9 +238,8 @@ class Partition():
241 os.remove(rootfs) 238 os.remove(rootfs)
242 239
243 if not self.fstype: 240 if not self.fstype:
244 logger.error("File system for partition %s not specified in kickstart, " 241 raise WicError("File system for partition %s not specified in "
245 "use --fstype option", self.mountpoint) 242 "kickstart, use --fstype option" % self.mountpoint)
246 sys.exit(1)
247 243
248 # Get rootfs size from bitbake variable if it's not set in .ks file 244 # Get rootfs size from bitbake variable if it's not set in .ks file
249 if not self.size: 245 if not self.size:
diff --git a/scripts/lib/wic/utils/misc.py b/scripts/lib/wic/utils/misc.py
index b7b835afbb..94fdab2669 100644
--- a/scripts/lib/wic/utils/misc.py
+++ b/scripts/lib/wic/utils/misc.py
@@ -33,6 +33,7 @@ import re
33from collections import defaultdict 33from collections import defaultdict
34from distutils import spawn 34from distutils import spawn
35 35
36from wic.errors import WicError
36from wic.utils import runner 37from wic.utils import runner
37 38
38logger = logging.getLogger('wic') 39logger = logging.getLogger('wic')
@@ -74,9 +75,8 @@ def _exec_cmd(cmd_and_args, as_shell=False, catch=3):
74 ret, out = runner.runtool(args, catch) 75 ret, out = runner.runtool(args, catch)
75 out = out.strip() 76 out = out.strip()
76 if ret != 0: 77 if ret != 0:
77 logger.error("_exec_cmd: %s returned '%s' instead of 0\noutput: %s" % \ 78 raise WicError("_exec_cmd: %s returned '%s' instead of 0\noutput: %s" % \
78 (cmd_and_args, ret, out)) 79 (cmd_and_args, ret, out))
79 sys.exit(1)
80 80
81 logger.debug("_exec_cmd: output for %s (rc = %d): %s", 81 logger.debug("_exec_cmd: output for %s (rc = %d): %s",
82 cmd_and_args, ret, out) 82 cmd_and_args, ret, out)
diff --git a/scripts/lib/wic/utils/runner.py b/scripts/lib/wic/utils/runner.py
index d27dcc7afd..5ede1929a3 100644
--- a/scripts/lib/wic/utils/runner.py
+++ b/scripts/lib/wic/utils/runner.py
@@ -18,7 +18,8 @@
18import logging 18import logging
19import os 19import os
20import subprocess 20import subprocess
21import sys 21
22from wic.errors import WicError
22 23
23logger = logging.getLogger('wic') 24logger = logging.getLogger('wic')
24 25
@@ -72,8 +73,7 @@ def runtool(cmdln_or_args, catch=1):
72 except OSError as err: 73 except OSError as err:
73 if err.errno == 2: 74 if err.errno == 2:
74 # [Errno 2] No such file or directory 75 # [Errno 2] No such file or directory
75 logger.error('Cannot run command: %s, lost dependency?', cmd) 76 raise WicError('Cannot run command: %s, lost dependency?' % cmd)
76 sys.exit(1)
77 else: 77 else:
78 raise # relay 78 raise # relay
79 finally: 79 finally: