diff options
Diffstat (limited to 'scripts/lib/mic/utils/oe/misc.py')
| -rw-r--r-- | scripts/lib/mic/utils/oe/misc.py | 108 |
1 files changed, 108 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..9edaa230e4 --- /dev/null +++ b/scripts/lib/mic/utils/oe/misc.py | |||
| @@ -0,0 +1,108 @@ | |||
| 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 | |||
| 28 | from mic import msger | ||
| 29 | from mic.utils import runner | ||
| 30 | |||
| 31 | def 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.debug("WARNING: %s returned '%s' instead of 0" % (args[0], rc)) | ||
| 55 | |||
| 56 | return (rc, out) | ||
| 57 | |||
| 58 | |||
| 59 | def 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 | |||
| 68 | def 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:PATH=%s/usr/sbin:PATH=%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 | return exec_cmd(native_cmd_and_args, True, catch) | ||
| 86 | |||
| 87 | |||
| 88 | def exec_native_cmd_quiet(cmd_and_args, native_sysroot): | ||
| 89 | """ | ||
| 90 | Execute native command, catching nothing in the output | ||
| 91 | |||
| 92 | Need to execute as_shell if the command uses wildcards | ||
| 93 | |||
| 94 | Always need to execute native commands as_shell | ||
| 95 | """ | ||
| 96 | return exec_native_cmd(cmd_and_args, native_sysroot, 0) | ||
| 97 | |||
| 98 | |||
| 99 | # kickstart doesn't support variable substution in commands, so this | ||
| 100 | # is our current simplistic scheme for supporting that | ||
| 101 | |||
| 102 | wks_vars = dict() | ||
| 103 | |||
| 104 | def get_wks_var(key): | ||
| 105 | return wks_vars[key] | ||
| 106 | |||
| 107 | def add_wks_var(key, val): | ||
| 108 | wks_vars[key] = val | ||
