summaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic/utils
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 /scripts/lib/wic/utils
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>
Diffstat (limited to 'scripts/lib/wic/utils')
-rw-r--r--scripts/lib/wic/utils/misc.py32
-rw-r--r--scripts/lib/wic/utils/runner.py12
2 files changed, 26 insertions, 18 deletions
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):