diff options
Diffstat (limited to 'scripts/lib/devtool/__init__.py')
| -rw-r--r-- | scripts/lib/devtool/__init__.py | 78 | 
1 files changed, 78 insertions, 0 deletions
diff --git a/scripts/lib/devtool/__init__.py b/scripts/lib/devtool/__init__.py new file mode 100644 index 0000000000..3f8158e24a --- /dev/null +++ b/scripts/lib/devtool/__init__.py  | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | #!/usr/bin/env python | ||
| 2 | |||
| 3 | # Development tool - utility functions for plugins | ||
| 4 | # | ||
| 5 | # Copyright (C) 2014 Intel Corporation | ||
| 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 | |||
| 21 | import os | ||
| 22 | import sys | ||
| 23 | import subprocess | ||
| 24 | import logging | ||
| 25 | |||
| 26 | logger = logging.getLogger('devtool') | ||
| 27 | |||
| 28 | def exec_build_env_command(init_path, builddir, cmd, watch=False, **options): | ||
| 29 | import bb | ||
| 30 | if not 'cwd' in options: | ||
| 31 | options["cwd"] = builddir | ||
| 32 | if init_path: | ||
| 33 | logger.debug('Executing command: "%s" using init path %s' % (cmd, init_path)) | ||
| 34 | init_prefix = '. %s %s > /dev/null && ' % (init_path, builddir) | ||
| 35 | else: | ||
| 36 | logger.debug('Executing command "%s"' % cmd) | ||
| 37 | init_prefix = '' | ||
| 38 | if watch: | ||
| 39 | if sys.stdout.isatty(): | ||
| 40 | # Fool bitbake into thinking it's outputting to a terminal (because it is, indirectly) | ||
| 41 | cmd = 'script -q -c "%s" /dev/null' % cmd | ||
| 42 | return exec_watch('%s%s' % (init_prefix, cmd), **options) | ||
| 43 | else: | ||
| 44 | return bb.process.run('%s%s' % (init_prefix, cmd), **options) | ||
| 45 | |||
| 46 | def exec_watch(cmd, **options): | ||
| 47 | if isinstance(cmd, basestring) and not "shell" in options: | ||
| 48 | options["shell"] = True | ||
| 49 | |||
| 50 | process = subprocess.Popen( | ||
| 51 | cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **options | ||
| 52 | ) | ||
| 53 | |||
| 54 | buf = '' | ||
| 55 | while True: | ||
| 56 | out = process.stdout.read(1) | ||
| 57 | if out: | ||
| 58 | sys.stdout.write(out) | ||
| 59 | sys.stdout.flush() | ||
| 60 | buf += out | ||
| 61 | elif out == '' and process.poll() != None: | ||
| 62 | break | ||
| 63 | return buf | ||
| 64 | |||
| 65 | def setup_tinfoil(): | ||
| 66 | import scriptpath | ||
| 67 | bitbakepath = scriptpath.add_bitbake_lib_path() | ||
| 68 | if not bitbakepath: | ||
| 69 | logger.error("Unable to find bitbake by searching parent directory of this script or PATH") | ||
| 70 | sys.exit(1) | ||
| 71 | |||
| 72 | import bb.tinfoil | ||
| 73 | import logging | ||
| 74 | tinfoil = bb.tinfoil.Tinfoil() | ||
| 75 | tinfoil.prepare(False) | ||
| 76 | tinfoil.logger.setLevel(logging.WARNING) | ||
| 77 | return tinfoil | ||
| 78 | |||
