summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Bartosh <ed.bartosh@linux.intel.com>2017-02-14 18:54:32 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-03-04 23:18:16 +0000
commitfe2d6022409248063403eed2f2de97f438dc7f03 (patch)
treeacf85ab9205c2ac8e73c20bf7d823c0a452b87a2
parent58ff06f1e7a19bef5199cc938c910af1f599373a (diff)
downloadpoky-fe2d6022409248063403eed2f2de97f438dc7f03.tar.gz
wic: use wic logger in core modules
Replaced msger with wic logger in the core wic modules. (From OE-Core rev: cdd6675951b74075c9b9159f7465a88f83775bac) Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--scripts/lib/wic/engine.py19
-rw-r--r--scripts/lib/wic/help.py8
-rw-r--r--scripts/lib/wic/ksparser.py7
-rw-r--r--scripts/lib/wic/partition.py72
-rw-r--r--scripts/lib/wic/plugin.py19
-rw-r--r--scripts/lib/wic/pluginbase.py12
-rw-r--r--scripts/lib/wic/utils/misc.py32
-rw-r--r--scripts/lib/wic/utils/runner.py12
8 files changed, 104 insertions, 77 deletions
diff --git a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py
index 1aa8f6534e..b64714c686 100644
--- a/scripts/lib/wic/engine.py
+++ b/scripts/lib/wic/engine.py
@@ -28,6 +28,7 @@
28# Tom Zanussi <tom.zanussi (at] linux.intel.com> 28# Tom Zanussi <tom.zanussi (at] linux.intel.com>
29# 29#
30 30
31import logging
31import os 32import os
32import sys 33import sys
33 34
@@ -35,6 +36,7 @@ from wic import msger
35from wic.plugin import pluginmgr 36from wic.plugin import pluginmgr
36from wic.utils.misc import get_bitbake_var 37from wic.utils.misc import get_bitbake_var
37 38
39logger = logging.getLogger('wic')
38 40
39def verify_build_env(): 41def verify_build_env():
40 """ 42 """
@@ -43,7 +45,7 @@ def verify_build_env():
43 Returns True if it is, false otherwise 45 Returns True if it is, false otherwise
44 """ 46 """
45 if not os.environ.get("BUILDDIR"): 47 if not os.environ.get("BUILDDIR"):
46 print("BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)") 48 logger.error("BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)")
47 sys.exit(1) 49 sys.exit(1)
48 50
49 return True 51 return True
@@ -179,7 +181,7 @@ def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
179 try: 181 try:
180 oe_builddir = os.environ["BUILDDIR"] 182 oe_builddir = os.environ["BUILDDIR"]
181 except KeyError: 183 except KeyError:
182 print("BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)") 184 logger.error("BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)")
183 sys.exit(1) 185 sys.exit(1)
184 186
185 if options.debug: 187 if options.debug:
@@ -191,14 +193,15 @@ def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
191 pname = 'direct' 193 pname = 'direct'
192 plugin_class = pluginmgr.get_plugins('imager').get(pname) 194 plugin_class = pluginmgr.get_plugins('imager').get(pname)
193 if not plugin_class: 195 if not plugin_class:
194 msger.error('Unknown plugin: %s' % pname) 196 logger.error('Unknown plugin: %s', pname)
197 sys.exit(1)
195 198
196 plugin = plugin_class(wks_file, rootfs_dir, bootimg_dir, kernel_dir, 199 plugin = plugin_class(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
197 native_sysroot, oe_builddir, options) 200 native_sysroot, oe_builddir, options)
198 201
199 plugin.do_create() 202 plugin.do_create()
200 203
201 print("\nThe image(s) were created using OE kickstart file:\n %s" % wks_file) 204 logger.info("The image(s) were created using OE kickstart file:\n %s", wks_file)
202 205
203 206
204def wic_list(args, scripts_path): 207def wic_list(args, scripts_path):
@@ -218,10 +221,10 @@ def wic_list(args, scripts_path):
218 wks_file = args[0] 221 wks_file = args[0]
219 fullpath = find_canned_image(scripts_path, wks_file) 222 fullpath = find_canned_image(scripts_path, wks_file)
220 if not fullpath: 223 if not fullpath:
221 print("No image named %s found, exiting. "\ 224 logger.error("No image named %s found, exiting. "
222 "(Use 'wic list images' to list available images, or "\ 225 "(Use 'wic list images' to list available images, or "
223 "specify a fully-qualified OE kickstart (.wks) "\ 226 "specify a fully-qualified OE kickstart (.wks) "
224 "filename)\n" % wks_file) 227 "filename)\n", wks_file)
225 sys.exit(1) 228 sys.exit(1)
226 list_canned_image_help(scripts_path, fullpath) 229 list_canned_image_help(scripts_path, fullpath)
227 return True 230 return True
diff --git a/scripts/lib/wic/help.py b/scripts/lib/wic/help.py
index 63bbc23a83..47e3d1666b 100644
--- a/scripts/lib/wic/help.py
+++ b/scripts/lib/wic/help.py
@@ -30,8 +30,10 @@ import logging
30 30
31from wic.plugin import pluginmgr, PLUGIN_TYPES 31from wic.plugin import pluginmgr, PLUGIN_TYPES
32 32
33logger = logging.getLogger('wic')
34
33def subcommand_error(args): 35def subcommand_error(args):
34 logging.info("invalid subcommand %s", args[0]) 36 logger.info("invalid subcommand %s", args[0])
35 37
36 38
37def display_help(subcommand, subcommands): 39def display_help(subcommand, subcommands):
@@ -81,13 +83,13 @@ def invoke_subcommand(args, parser, main_command_usage, subcommands):
81 Should use argparse, but has to work in 2.6. 83 Should use argparse, but has to work in 2.6.
82 """ 84 """
83 if not args: 85 if not args:
84 logging.error("No subcommand specified, exiting") 86 logger.error("No subcommand specified, exiting")
85 parser.print_help() 87 parser.print_help()
86 return 1 88 return 1
87 elif args[0] == "help": 89 elif args[0] == "help":
88 wic_help(args, main_command_usage, subcommands) 90 wic_help(args, main_command_usage, subcommands)
89 elif args[0] not in subcommands: 91 elif args[0] not in subcommands:
90 logging.error("Unsupported subcommand %s, exiting\n", args[0]) 92 logger.error("Unsupported subcommand %s, exiting\n", args[0])
91 parser.print_help() 93 parser.print_help()
92 return 1 94 return 1
93 else: 95 else:
diff --git a/scripts/lib/wic/ksparser.py b/scripts/lib/wic/ksparser.py
index 968b8e1312..a0393008eb 100644
--- a/scripts/lib/wic/ksparser.py
+++ b/scripts/lib/wic/ksparser.py
@@ -27,12 +27,15 @@
27 27
28import os 28import os
29import shlex 29import shlex
30import logging
31
30from argparse import ArgumentParser, ArgumentError, ArgumentTypeError 32from argparse import ArgumentParser, ArgumentError, ArgumentTypeError
31 33
32from wic import msger
33from wic.engine import find_canned 34from wic.engine import find_canned
34from wic.partition import Partition 35from wic.partition import Partition
35 36
37logger = logging.getLogger('wic')
38
36class KickStartError(Exception): 39class KickStartError(Exception):
37 """Custom exception.""" 40 """Custom exception."""
38 pass 41 pass
@@ -168,7 +171,7 @@ class KickStart():
168 171
169 self._parse(parser, confpath) 172 self._parse(parser, confpath)
170 if not self.bootloader: 173 if not self.bootloader:
171 msger.warning('bootloader config not specified, using defaults') 174 logger.warning('bootloader config not specified, using defaults\n')
172 self.bootloader = bootloader.parse_args([]) 175 self.bootloader = bootloader.parse_args([])
173 176
174 def _parse(self, parser, confpath): 177 def _parse(self, parser, confpath):
diff --git a/scripts/lib/wic/partition.py b/scripts/lib/wic/partition.py
index 1221f691dc..a68dc6fd6d 100644
--- a/scripts/lib/wic/partition.py
+++ b/scripts/lib/wic/partition.py
@@ -24,13 +24,16 @@
24# Tom Zanussi <tom.zanussi (at] linux.intel.com> 24# Tom Zanussi <tom.zanussi (at] linux.intel.com>
25# Ed Bartosh <ed.bartosh> (at] linux.intel.com> 25# Ed Bartosh <ed.bartosh> (at] linux.intel.com>
26 26
27import logging
27import os 28import os
29import sys
28import tempfile 30import tempfile
29 31
30from wic import msger
31from 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
32from wic.plugin import pluginmgr 33from wic.plugin import pluginmgr
33 34
35logger = logging.getLogger('wic')
36
34class Partition(): 37class Partition():
35 38
36 def __init__(self, args, lineno): 39 def __init__(self, args, lineno):
@@ -69,16 +72,16 @@ class Partition():
69 number of (1k) blocks we need to add to get to --size, 0 if 72 number of (1k) blocks we need to add to get to --size, 0 if
70 we're already there or beyond. 73 we're already there or beyond.
71 """ 74 """
72 msger.debug("Requested partition size for %s: %d" % \ 75 logger.debug("Requested partition size for %s: %d",
73 (self.mountpoint, self.size)) 76 self.mountpoint, self.size)
74 77
75 if not self.size: 78 if not self.size:
76 return 0 79 return 0
77 80
78 requested_blocks = self.size 81 requested_blocks = self.size
79 82
80 msger.debug("Requested blocks %d, current_blocks %d" % \ 83 logger.debug("Requested blocks %d, current_blocks %d",
81 (requested_blocks, current_blocks)) 84 requested_blocks, current_blocks)
82 85
83 if requested_blocks > current_blocks: 86 if requested_blocks > current_blocks:
84 return requested_blocks - current_blocks 87 return requested_blocks - current_blocks
@@ -96,8 +99,9 @@ class Partition():
96 if self.fixed_size: 99 if self.fixed_size:
97 rootfs_size = self.fixed_size 100 rootfs_size = self.fixed_size
98 if actual_rootfs_size > rootfs_size: 101 if actual_rootfs_size > rootfs_size:
99 msger.error("Actual rootfs size (%d kB) is larger than allowed size %d kB" \ 102 logger.error("Actual rootfs size (%d kB) is larger than allowed size %d kB",
100 %(actual_rootfs_size, rootfs_size)) 103 actual_rootfs_size, rootfs_size)
104 sys.exit(1)
101 else: 105 else:
102 extra_blocks = self.get_extra_block_count(actual_rootfs_size) 106 extra_blocks = self.get_extra_block_count(actual_rootfs_size)
103 if extra_blocks < self.extra_space: 107 if extra_blocks < self.extra_space:
@@ -106,8 +110,8 @@ class Partition():
106 rootfs_size = actual_rootfs_size + extra_blocks 110 rootfs_size = actual_rootfs_size + extra_blocks
107 rootfs_size *= self.overhead_factor 111 rootfs_size *= self.overhead_factor
108 112
109 msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \ 113 logger.debug("Added %d extra blocks to %s to get to %d total blocks",
110 (extra_blocks, self.mountpoint, rootfs_size)) 114 extra_blocks, self.mountpoint, rootfs_size)
111 115
112 return rootfs_size 116 return rootfs_size
113 117
@@ -128,9 +132,10 @@ class Partition():
128 """ 132 """
129 if not self.source: 133 if not self.source:
130 if not self.size and not self.fixed_size: 134 if not self.size and not self.fixed_size:
131 msger.error("The %s partition has a size of zero. Please " 135 logger.error("The %s partition has a size of zero. Please "
132 "specify a non-zero --size/--fixed-size for that partition." % \ 136 "specify a non-zero --size/--fixed-size for that "
133 self.mountpoint) 137 "partition.", self.mountpoint)
138 sys.exit(1)
134 if self.fstype and self.fstype == "swap": 139 if self.fstype and self.fstype == "swap":
135 self.prepare_swap_partition(cr_workdir, oe_builddir, 140 self.prepare_swap_partition(cr_workdir, oe_builddir,
136 native_sysroot) 141 native_sysroot)
@@ -152,11 +157,12 @@ class Partition():
152 plugins = pluginmgr.get_source_plugins() 157 plugins = pluginmgr.get_source_plugins()
153 158
154 if self.source not in plugins: 159 if self.source not in plugins:
155 msger.error("The '%s' --source specified for %s doesn't exist.\n\t" 160 logger.error("The '%s' --source specified for %s doesn't exist.\n\t"
156 "See 'wic list source-plugins' for a list of available" 161 "See 'wic list source-plugins' for a list of available"
157 " --sources.\n\tSee 'wic help source-plugins' for " 162 " --sources.\n\tSee 'wic help source-plugins' for "
158 "details on adding a new source plugin." % \ 163 "details on adding a new source plugin.",
159 (self.source, self.mountpoint)) 164 self.source, self.mountpoint)
165 sys.exit(1)
160 166
161 srcparams_dict = {} 167 srcparams_dict = {}
162 if self.sourceparams: 168 if self.sourceparams:
@@ -186,15 +192,16 @@ class Partition():
186 # further processing required Partition.size to be an integer, make 192 # further processing required Partition.size to be an integer, make
187 # sure that it is one 193 # sure that it is one
188 if not isinstance(self.size, int): 194 if not isinstance(self.size, int):
189 msger.error("Partition %s internal size is not an integer. " \ 195 logger.error("Partition %s internal size is not an integer. "
190 "This a bug in source plugin %s and needs to be fixed." \ 196 "This a bug in source plugin %s and needs to be fixed.",
191 % (self.mountpoint, self.source)) 197 self.mountpoint, self.source)
198 sys.exit(1)
192 199
193 if self.fixed_size and self.size > self.fixed_size: 200 if self.fixed_size and self.size > self.fixed_size:
194 msger.error("File system image of partition %s is larger (%d kB) than its"\ 201 logger.error("File system image of partition %s is larger (%d kB) "
195 "allowed size %d kB" % (self.mountpoint, 202 "than its allowed size %d kB",
196 self.size, self.fixed_size)) 203 self.mountpoint, self.size, self.fixed_size)
197 204 sys.exit(1)
198 205
199 def prepare_rootfs_from_fs_image(self, cr_workdir, oe_builddir, 206 def prepare_rootfs_from_fs_image(self, cr_workdir, oe_builddir,
200 rootfs_dir): 207 rootfs_dir):
@@ -234,8 +241,9 @@ class Partition():
234 os.remove(rootfs) 241 os.remove(rootfs)
235 242
236 if not self.fstype: 243 if not self.fstype:
237 msger.error("File system for partition %s not specified in kickstart, " \ 244 logger.error("File system for partition %s not specified in kickstart, "
238 "use --fstype option" % (self.mountpoint)) 245 "use --fstype option", self.mountpoint)
246 sys.exit(1)
239 247
240 # Get rootfs size from bitbake variable if it's not set in .ks file 248 # Get rootfs size from bitbake variable if it's not set in .ks file
241 if not self.size: 249 if not self.size:
@@ -245,10 +253,10 @@ class Partition():
245 # IMAGE_OVERHEAD_FACTOR and IMAGE_ROOTFS_EXTRA_SPACE 253 # IMAGE_OVERHEAD_FACTOR and IMAGE_ROOTFS_EXTRA_SPACE
246 rsize_bb = get_bitbake_var('ROOTFS_SIZE') 254 rsize_bb = get_bitbake_var('ROOTFS_SIZE')
247 if rsize_bb: 255 if rsize_bb:
248 msger.warning('overhead-factor was specified, but size was not,' 256 logger.warning('overhead-factor was specified, but size was not,'
249 ' so bitbake variables will be used for the size.' 257 ' so bitbake variables will be used for the size.'
250 ' In this case both IMAGE_OVERHEAD_FACTOR and ' 258 ' In this case both IMAGE_OVERHEAD_FACTOR and '
251 '--overhead-factor will be applied') 259 '--overhead-factor will be applied')
252 self.size = int(round(float(rsize_bb))) 260 self.size = int(round(float(rsize_bb)))
253 261
254 for prefix in ("ext", "btrfs", "vfat", "squashfs"): 262 for prefix in ("ext", "btrfs", "vfat", "squashfs"):
@@ -404,8 +412,8 @@ class Partition():
404 """ 412 """
405 Prepare an empty squashfs partition. 413 Prepare an empty squashfs partition.
406 """ 414 """
407 msger.warning("Creating of an empty squashfs %s partition was attempted. " \ 415 logger.warning("Creating of an empty squashfs %s partition was attempted. "
408 "Proceeding as requested." % self.mountpoint) 416 "Proceeding as requested.", self.mountpoint)
409 417
410 path = "%s/fs_%s.%s" % (cr_workdir, self.label, self.fstype) 418 path = "%s/fs_%s.%s" % (cr_workdir, self.label, self.fstype)
411 if os.path.isfile(path): 419 if os.path.isfile(path):
diff --git a/scripts/lib/wic/plugin.py b/scripts/lib/wic/plugin.py
index f04a0343d9..70d337789f 100644
--- a/scripts/lib/wic/plugin.py
+++ b/scripts/lib/wic/plugin.py
@@ -17,8 +17,8 @@
17 17
18import os 18import os
19import sys 19import sys
20import logging
20 21
21from wic import msger
22from wic import pluginbase 22from wic import pluginbase
23from wic.utils import errors 23from wic.utils import errors
24from wic.utils.misc import get_bitbake_var 24from wic.utils.misc import get_bitbake_var
@@ -30,6 +30,8 @@ PLUGIN_TYPES = ["imager", "source"]
30PLUGIN_DIR = "/lib/wic/plugins" # relative to scripts 30PLUGIN_DIR = "/lib/wic/plugins" # relative to scripts
31SCRIPTS_PLUGIN_DIR = "scripts" + PLUGIN_DIR 31SCRIPTS_PLUGIN_DIR = "scripts" + PLUGIN_DIR
32 32
33logger = logging.getLogger('wic')
34
33class PluginMgr(): 35class PluginMgr():
34 plugin_dirs = {} 36 plugin_dirs = {}
35 37
@@ -91,17 +93,16 @@ class PluginMgr():
91 if mod and mod != '__init__': 93 if mod and mod != '__init__':
92 if mod in sys.modules: 94 if mod in sys.modules:
93 #self.plugin_dirs[pdir] = True 95 #self.plugin_dirs[pdir] = True
94 msger.warning("Module %s already exists, skip" % mod) 96 logger.warning("Module %s already exists, skip", mod)
95 else: 97 else:
96 try: 98 try:
97 pymod = __import__(mod) 99 pymod = __import__(mod)
98 self.plugin_dirs[pdir] = True 100 self.plugin_dirs[pdir] = True
99 msger.debug("Plugin module %s:%s imported"\ 101 logger.debug("Plugin module %s:%s imported",
100 % (mod, pymod.__file__)) 102 mod, pymod.__file__)
101 except ImportError as err: 103 except ImportError as err:
102 msg = 'Failed to load plugin %s/%s: %s' \ 104 logger.warning('Failed to load plugin %s/%s: %s',
103 % (os.path.basename(pdir), mod, err) 105 os.path.basename(pdir), mod, err)
104 msger.warning(msg)
105 106
106 del sys.path[0] 107 del sys.path[0]
107 108
@@ -140,8 +141,8 @@ class PluginMgr():
140 if _source_name == source_name: 141 if _source_name == source_name:
141 for _method_name in methods: 142 for _method_name in methods:
142 if not hasattr(klass, _method_name): 143 if not hasattr(klass, _method_name):
143 msger.warning("Unimplemented %s source interface for: %s"\ 144 logger.warning("Unimplemented %s source interface for: %s",
144 % (_method_name, _source_name)) 145 _method_name, _source_name)
145 return None 146 return None
146 func = getattr(klass, _method_name) 147 func = getattr(klass, _method_name)
147 methods[_method_name] = func 148 methods[_method_name] = func
diff --git a/scripts/lib/wic/pluginbase.py b/scripts/lib/wic/pluginbase.py
index 2f747a91de..aea9c02319 100644
--- a/scripts/lib/wic/pluginbase.py
+++ b/scripts/lib/wic/pluginbase.py
@@ -17,9 +17,11 @@
17 17
18__all__ = ['ImagerPlugin', 'SourcePlugin', 'get_plugins'] 18__all__ = ['ImagerPlugin', 'SourcePlugin', 'get_plugins']
19 19
20import logging
21
20from collections import defaultdict 22from collections import defaultdict
21 23
22from wic import msger 24logger = logging.getLogger('wic')
23 25
24class PluginMeta(type): 26class PluginMeta(type):
25 plugins = defaultdict(dict) 27 plugins = defaultdict(dict)
@@ -49,7 +51,7 @@ class SourcePlugin(PluginMeta("Plugin", (), {})):
49 disk image. This provides a hook to allow finalization of a 51 disk image. This provides a hook to allow finalization of a
50 disk image e.g. to write an MBR to it. 52 disk image e.g. to write an MBR to it.
51 """ 53 """
52 msger.debug("SourcePlugin: do_install_disk: disk: %s" % disk_name) 54 logger.debug("SourcePlugin: do_install_disk: disk: %s", disk_name)
53 55
54 @classmethod 56 @classmethod
55 def do_stage_partition(cls, part, source_params, creator, cr_workdir, 57 def do_stage_partition(cls, part, source_params, creator, cr_workdir,
@@ -66,7 +68,7 @@ class SourcePlugin(PluginMeta("Plugin", (), {})):
66 Not that get_bitbake_var() allows you to acces non-standard 68 Not that get_bitbake_var() allows you to acces non-standard
67 variables that you might want to use for this. 69 variables that you might want to use for this.
68 """ 70 """
69 msger.debug("SourcePlugin: do_stage_partition: part: %s" % part) 71 logger.debug("SourcePlugin: do_stage_partition: part: %s", part)
70 72
71 @classmethod 73 @classmethod
72 def do_configure_partition(cls, part, source_params, creator, cr_workdir, 74 def do_configure_partition(cls, part, source_params, creator, cr_workdir,
@@ -77,7 +79,7 @@ class SourcePlugin(PluginMeta("Plugin", (), {})):
77 custom configuration files for a partition, for example 79 custom configuration files for a partition, for example
78 syslinux or grub config files. 80 syslinux or grub config files.
79 """ 81 """
80 msger.debug("SourcePlugin: do_configure_partition: part: %s" % part) 82 logger.debug("SourcePlugin: do_configure_partition: part: %s", part)
81 83
82 @classmethod 84 @classmethod
83 def do_prepare_partition(cls, part, source_params, creator, cr_workdir, 85 def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
@@ -87,7 +89,7 @@ class SourcePlugin(PluginMeta("Plugin", (), {})):
87 Called to do the actual content population for a partition i.e. it 89 Called to do the actual content population for a partition i.e. it
88 'prepares' the partition to be incorporated into the image. 90 'prepares' the partition to be incorporated into the image.
89 """ 91 """
90 msger.debug("SourcePlugin: do_prepare_partition: part: %s" % part) 92 logger.debug("SourcePlugin: do_prepare_partition: part: %s", part)
91 93
92def get_plugins(typen): 94def get_plugins(typen):
93 return PluginMeta.plugins.get(typen) 95 return PluginMeta.plugins.get(typen)
diff --git a/scripts/lib/wic/utils/misc.py b/scripts/lib/wic/utils/misc.py
index edb9c5b484..b7b835afbb 100644
--- a/scripts/lib/wic/utils/misc.py
+++ b/scripts/lib/wic/utils/misc.py
@@ -26,14 +26,17 @@
26# 26#
27"""Miscellaneous functions.""" 27"""Miscellaneous functions."""
28 28
29import logging
29import os 30import os
30import re 31import re
32
31from collections import defaultdict 33from collections import defaultdict
32from distutils import spawn 34from distutils import spawn
33 35
34from wic import msger
35from wic.utils import runner 36from wic.utils import runner
36 37
38logger = logging.getLogger('wic')
39
37# executable -> recipe pairs for exec_native_cmd 40# executable -> recipe pairs for exec_native_cmd
38NATIVE_RECIPES = {"bmaptool": "bmap-tools", 41NATIVE_RECIPES = {"bmaptool": "bmap-tools",
39 "grub-mkimage": "grub-efi", 42 "grub-mkimage": "grub-efi",
@@ -61,9 +64,9 @@ def _exec_cmd(cmd_and_args, as_shell=False, catch=3):
61 64
62 Need to execute as_shell if the command uses wildcards 65 Need to execute as_shell if the command uses wildcards
63 """ 66 """
64 msger.debug("_exec_cmd: %s" % cmd_and_args) 67 logger.debug("_exec_cmd: %s", cmd_and_args)
65 args = cmd_and_args.split() 68 args = cmd_and_args.split()
66 msger.debug(args) 69 logger.debug(args)
67 70
68 if as_shell: 71 if as_shell:
69 ret, out = runner.runtool(cmd_and_args, catch) 72 ret, out = runner.runtool(cmd_and_args, catch)
@@ -71,11 +74,12 @@ def _exec_cmd(cmd_and_args, as_shell=False, catch=3):
71 ret, out = runner.runtool(args, catch) 74 ret, out = runner.runtool(args, catch)
72 out = out.strip() 75 out = out.strip()
73 if ret != 0: 76 if ret != 0:
74 msger.error("_exec_cmd: %s returned '%s' instead of 0\noutput: %s" % \ 77 logger.error("_exec_cmd: %s returned '%s' instead of 0\noutput: %s" % \
75 (cmd_and_args, ret, out)) 78 (cmd_and_args, ret, out))
79 sys.exit(1)
76 80
77 msger.debug("_exec_cmd: output for %s (rc = %d): %s" % \ 81 logger.debug("_exec_cmd: output for %s (rc = %d): %s",
78 (cmd_and_args, ret, out)) 82 cmd_and_args, ret, out)
79 83
80 return ret, out 84 return ret, out
81 85
@@ -97,7 +101,7 @@ def exec_native_cmd(cmd_and_args, native_sysroot, catch=3, pseudo=""):
97 """ 101 """
98 # The reason -1 is used is because there may be "export" commands. 102 # The reason -1 is used is because there may be "export" commands.
99 args = cmd_and_args.split(';')[-1].split() 103 args = cmd_and_args.split(';')[-1].split()
100 msger.debug(args) 104 logger.debug(args)
101 105
102 if pseudo: 106 if pseudo:
103 cmd_and_args = pseudo + cmd_and_args 107 cmd_and_args = pseudo + cmd_and_args
@@ -106,7 +110,7 @@ def exec_native_cmd(cmd_and_args, native_sysroot, catch=3, pseudo=""):
106 (native_sysroot, native_sysroot, native_sysroot) 110 (native_sysroot, native_sysroot, native_sysroot)
107 native_cmd_and_args = "export PATH=%s:$PATH;%s" % \ 111 native_cmd_and_args = "export PATH=%s:$PATH;%s" % \
108 (native_paths, cmd_and_args) 112 (native_paths, cmd_and_args)
109 msger.debug("exec_native_cmd: %s" % cmd_and_args) 113 logger.debug("exec_native_cmd: %s", cmd_and_args)
110 114
111 # If the command isn't in the native sysroot say we failed. 115 # If the command isn't in the native sysroot say we failed.
112 if spawn.find_executable(args[0], native_paths): 116 if spawn.find_executable(args[0], native_paths):
@@ -127,7 +131,7 @@ def exec_native_cmd(cmd_and_args, native_sysroot, catch=3, pseudo=""):
127 else: 131 else:
128 msg += "Wic failed to find a recipe to build native %s. Please "\ 132 msg += "Wic failed to find a recipe to build native %s. Please "\
129 "file a bug against wic.\n" % prog 133 "file a bug against wic.\n" % prog
130 msger.error(msg) 134 logger.error(msg)
131 135
132 return ret, out 136 return ret, out
133 137
@@ -184,14 +188,14 @@ class BitbakeVars(defaultdict):
184 if image: 188 if image:
185 cmd += " %s" % image 189 cmd += " %s" % image
186 190
187 log_level = msger.get_loglevel() 191 log_level = logger.getEffectiveLevel()
188 msger.set_loglevel('normal') 192 logger.setLevel(logging.INFO)
189 ret, lines = _exec_cmd(cmd) 193 ret, lines = _exec_cmd(cmd)
190 msger.set_loglevel(log_level) 194 logger.setLevel(log_level)
191 195
192 if ret: 196 if ret:
193 print("Couldn't get '%s' output." % cmd) 197 logger.error("Couldn't get '%s' output.", cmd)
194 print("Bitbake failed with error:\n%s\n" % lines) 198 logger.error("Bitbake failed with error:\n%s\n", lines)
195 return 199 return
196 200
197 # Parse bitbake -e output 201 # Parse bitbake -e output
diff --git a/scripts/lib/wic/utils/runner.py b/scripts/lib/wic/utils/runner.py
index db536ba588..d27dcc7afd 100644
--- a/scripts/lib/wic/utils/runner.py
+++ b/scripts/lib/wic/utils/runner.py
@@ -15,10 +15,12 @@
15# with this program; if not, write to the Free Software Foundation, Inc., 59 15# with this program; if not, write to the Free Software Foundation, Inc., 59
16# Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 17
18import logging
18import os 19import os
19import subprocess 20import subprocess
21import sys
20 22
21from wic import msger 23logger = logging.getLogger('wic')
22 24
23def runtool(cmdln_or_args, catch=1): 25def runtool(cmdln_or_args, catch=1):
24 """ wrapper for most of the subprocess calls 26 """ wrapper for most of the subprocess calls
@@ -70,7 +72,8 @@ def runtool(cmdln_or_args, catch=1):
70 except OSError as err: 72 except OSError as err:
71 if err.errno == 2: 73 if err.errno == 2:
72 # [Errno 2] No such file or directory 74 # [Errno 2] No such file or directory
73 msger.error('Cannot run command: %s, lost dependency?' % cmd) 75 logger.error('Cannot run command: %s, lost dependency?', cmd)
76 sys.exit(1)
74 else: 77 else:
75 raise # relay 78 raise # relay
76 finally: 79 finally:
@@ -80,7 +83,7 @@ def runtool(cmdln_or_args, catch=1):
80 return (process.returncode, out) 83 return (process.returncode, out)
81 84
82def show(cmdln_or_args): 85def show(cmdln_or_args):
83 # show all the message using msger.verbose 86 """Show all messages using logger.debug."""
84 87
85 rcode, out = runtool(cmdln_or_args, catch=3) 88 rcode, out = runtool(cmdln_or_args, catch=3)
86 89
@@ -99,7 +102,8 @@ def show(cmdln_or_args):
99 msg += '\n | %s' % line 102 msg += '\n | %s' % line
100 msg += '\n +----------------' 103 msg += '\n +----------------'
101 104
102 msger.verbose(msg) 105 logger.debug(msg)
106
103 return rcode 107 return rcode
104 108
105def outs(cmdln_or_args, catch=1): 109def outs(cmdln_or_args, catch=1):