summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2014-12-19 11:41:54 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-12-23 10:18:15 +0000
commitb7d53f2ebb3219e205ab6b368f7f41b57a5cf89a (patch)
tree112dc8fb3398c36aacd41bc2baf7800d94066c91 /scripts
parent5638ca2b9483806d991d93071b259769a5f7ec48 (diff)
downloadpoky-b7d53f2ebb3219e205ab6b368f7f41b57a5cf89a.tar.gz
scripts: add scriptutils module
Add a utility module for scripts. This is intended to provide functions only really useful before bitbake has been found (or only of particular interest to scripts). At the moment this includes functions for setting up a logger and for loading plugins. (From OE-Core rev: a8f90528981127fbace3e901c6e3dfe8b45b98ab) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/lib/scriptutils.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/scripts/lib/scriptutils.py b/scripts/lib/scriptutils.py
new file mode 100644
index 0000000000..e7861268a5
--- /dev/null
+++ b/scripts/lib/scriptutils.py
@@ -0,0 +1,60 @@
1# Script utility functions
2#
3# Copyright (C) 2014 Intel Corporation
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 2 as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along
15# with this program; if not, write to the Free Software Foundation, Inc.,
16# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18import sys
19import os
20import logging
21import glob
22
23def logger_create(name):
24 logger = logging.getLogger(name)
25 loggerhandler = logging.StreamHandler()
26 loggerhandler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
27 logger.addHandler(loggerhandler)
28 logger.setLevel(logging.INFO)
29 return logger
30
31def logger_setup_color(logger, color='auto'):
32 from bb.msg import BBLogFormatter
33 console = logging.StreamHandler(sys.stdout)
34 formatter = BBLogFormatter("%(levelname)s: %(message)s")
35 console.setFormatter(formatter)
36 logger.handlers = [console]
37 if color == 'always' or (color=='auto' and console.stream.isatty()):
38 formatter.enable_color()
39
40
41def load_plugins(logger, plugins, pluginpath):
42 import imp
43
44 def load_plugin(name):
45 logger.debug('Loading plugin %s' % name)
46 fp, pathname, description = imp.find_module(name, [pluginpath])
47 try:
48 return imp.load_module(name, fp, pathname, description)
49 finally:
50 if fp:
51 fp.close()
52
53 logger.debug('Loading plugins from %s...' % pluginpath)
54 for fn in glob.glob(os.path.join(pluginpath, '*.py')):
55 name = os.path.splitext(os.path.basename(fn))[0]
56 if name != '__init__':
57 plugin = load_plugin(name)
58 if hasattr(plugin, 'plugin_init'):
59 plugin.plugin_init(plugins)
60 plugins.append(plugin)