summaryrefslogtreecommitdiffstats
path: root/scripts/lib/mic/utils/oe/misc.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/mic/utils/oe/misc.py')
-rw-r--r--scripts/lib/mic/utils/oe/misc.py144
1 files changed, 144 insertions, 0 deletions
diff --git a/scripts/lib/mic/utils/oe/misc.py b/scripts/lib/mic/utils/oe/misc.py
new file mode 100644
index 0000000000..7ad3aa9685
--- /dev/null
+++ b/scripts/lib/mic/utils/oe/misc.py
@@ -0,0 +1,144 @@
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# This module provides a place to collect various mic-related utils
22# for the OpenEmbedded Image Tools.
23#
24# AUTHORS
25# Tom Zanussi <tom.zanussi (at] linux.intel.com>
26#
27
28from mic import msger
29from mic.utils import runner
30
31def exec_cmd(cmd_and_args, as_shell = False, catch = 3):
32 """
33 Execute command, catching stderr, stdout
34
35 Need to execute as_shell if the command uses wildcards
36 """
37 msger.debug("exec_cmd: %s" % cmd_and_args)
38 args = cmd_and_args.split()
39 msger.debug(args)
40
41 if (as_shell):
42 rc, out = runner.runtool(cmd_and_args, catch)
43 else:
44 rc, out = runner.runtool(args, catch)
45 out = out.strip()
46 msger.debug("exec_cmd: output for %s (rc = %d): %s" % \
47 (cmd_and_args, rc, out))
48
49 if rc != 0:
50 # We don't throw exception when return code is not 0, because
51 # parted always fails to reload part table with loop devices. This
52 # prevents us from distinguishing real errors based on return
53 # code.
54 msger.warning("WARNING: %s returned '%s' instead of 0" % (cmd_and_args, rc))
55
56 return (rc, out)
57
58
59def exec_cmd_quiet(cmd_and_args, as_shell = False):
60 """
61 Execute command, catching nothing in the output
62
63 Need to execute as_shell if the command uses wildcards
64 """
65 return exec_cmd(cmd_and_args, as_shell, 0)
66
67
68def exec_native_cmd(cmd_and_args, native_sysroot, catch = 3):
69 """
70 Execute native command, catching stderr, stdout
71
72 Need to execute as_shell if the command uses wildcards
73
74 Always need to execute native commands as_shell
75 """
76 native_paths = \
77 "export PATH=%s/sbin:%s/usr/sbin:%s/usr/bin:$PATH" % \
78 (native_sysroot, native_sysroot, native_sysroot)
79 native_cmd_and_args = "%s;%s" % (native_paths, cmd_and_args)
80 msger.debug("exec_native_cmd: %s" % cmd_and_args)
81
82 args = cmd_and_args.split()
83 msger.debug(args)
84
85 rc, out = exec_cmd(native_cmd_and_args, True, catch)
86
87 if rc == 127: # shell command-not-found
88 msger.error("A native (host) program required to build the image "
89 "was not found (see details above). Please make sure "
90 "it's installed and try again.")
91
92 return (rc, out)
93
94
95def exec_native_cmd_quiet(cmd_and_args, native_sysroot):
96 """
97 Execute native command, catching nothing in the output
98
99 Need to execute as_shell if the command uses wildcards
100
101 Always need to execute native commands as_shell
102 """
103 return exec_native_cmd(cmd_and_args, native_sysroot, 0)
104
105
106# kickstart doesn't support variable substution in commands, so this
107# is our current simplistic scheme for supporting that
108
109wks_vars = dict()
110
111def get_wks_var(key):
112 return wks_vars[key]
113
114def add_wks_var(key, val):
115 wks_vars[key] = val
116
117BOOTDD_EXTRA_SPACE = 16384
118IMAGE_EXTRA_SPACE = 10240
119
120__bitbake_env_lines = ""
121
122def set_bitbake_env_lines(bitbake_env_lines):
123 global __bitbake_env_lines
124 __bitbake_env_lines = bitbake_env_lines
125
126def get_bitbake_env_lines():
127 return __bitbake_env_lines
128
129def get_line_val(line, key):
130 """
131 Extract the value from the VAR="val" string
132 """
133 if line.startswith(key + "="):
134 stripped_line = line.split('=')[1]
135 stripped_line = stripped_line.replace('\"', '')
136 return stripped_line
137 return None
138
139def get_bitbake_var(key):
140 for line in __bitbake_env_lines.split('\n'):
141 if (get_line_val(line, key)):
142 val = get_line_val(line, key)
143 return val
144 return None