diff options
Diffstat (limited to 'scripts/devtool')
| -rwxr-xr-x | scripts/devtool | 72 |
1 files changed, 53 insertions, 19 deletions
diff --git a/scripts/devtool b/scripts/devtool index 06e91b7591..c9ad9ddb95 100755 --- a/scripts/devtool +++ b/scripts/devtool @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # OpenEmbedded Development tool # @@ -22,7 +22,7 @@ import os import argparse import glob import re -import ConfigParser +import configparser import subprocess import logging @@ -51,12 +51,12 @@ class ConfigHandler(object): def __init__(self, filename): self.config_file = filename - self.config_obj = ConfigParser.SafeConfigParser() + self.config_obj = configparser.SafeConfigParser() def get(self, section, option, default=None): try: ret = self.config_obj.get(section, option) - except (ConfigParser.NoOptionError, ConfigParser.NoSectionError): + except (configparser.NoOptionError, configparser.NoSectionError): if default != None: ret = default else: @@ -86,6 +86,11 @@ class ConfigHandler(object): with open(self.config_file, 'w') as f: self.config_obj.write(f) + def set(self, section, option, value): + if not self.config_obj.has_section(section): + self.config_obj.add_section(section) + self.config_obj.set(section, option, value) + class Context: def __init__(self, **kwargs): self.__dict__.update(kwargs) @@ -125,6 +130,25 @@ def read_workspace(): 'recipefile': recipefile} logger.debug('Found recipe %s' % workspace[pn]) +def create_unlockedsigs(): + """ This function will make unlocked-sigs.inc match the recipes in the + workspace. This runs on every run of devtool, but it lets us ensure + the unlocked items are in sync with the workspace. """ + + confdir = os.path.join(basepath, 'conf') + unlockedsigs = os.path.join(confdir, 'unlocked-sigs.inc') + bb.utils.mkdirhier(confdir) + with open(os.path.join(confdir, 'unlocked-sigs.inc'), 'w') as f: + f.write("# DO NOT MODIFY! YOUR CHANGES WILL BE LOST.\n" + + "# This layer was created by the OpenEmbedded devtool" + + " utility in order to\n" + + "# contain recipes that are unlocked.\n") + + f.write('SIGGEN_UNLOCKED_RECIPES += "\\\n') + for pn in workspace: + f.write(' ' + pn) + f.write('"') + def create_workspace(args, config, basepath, workspace): if args.layerpath: workspacedir = os.path.abspath(args.layerpath) @@ -155,13 +179,16 @@ def _create_workspace(workspacedir, config, basepath): # Add a README file with open(os.path.join(workspacedir, 'README'), 'w') as f: f.write('This layer was created by the OpenEmbedded devtool utility in order to\n') - f.write('contain recipes and bbappends. In most instances you should use the\n') + f.write('contain recipes and bbappends that are currently being worked on. The idea\n') + f.write('is that the contents is temporary - once you have finished working on a\n') + f.write('recipe you use the appropriate method to move the files you have been\n') + f.write('working on to a proper layer. In most instances you should use the\n') f.write('devtool utility to manage files within it rather than modifying files\n') f.write('directly (although recipes added with "devtool add" will often need\n') f.write('direct modification.)\n') - f.write('\nIf you no longer need to use devtool you can remove the path to this\n') - f.write('workspace layer from your conf/bblayers.conf file (and then delete the\n') - f.write('layer, if you wish).\n') + f.write('\nIf you no longer need to use devtool or the workspace layer\'s contents\n') + f.write('you can remove the path to this workspace layer from your conf/bblayers.conf\n') + f.write('file (and then delete the layer, if you wish).\n') f.write('\nNote that by default, if devtool fetches and unpacks source code, it\n') f.write('will place it in a subdirectory of a "sources" subdirectory of the\n') f.write('layer. If you prefer it to be elsewhere you can specify the source\n') @@ -188,6 +215,9 @@ def main(): global config global context + if sys.getfilesystemencoding() != "utf-8": + sys.exit("Please use a locale setting which supports utf-8.\nPython can't change the filesystem locale after loading so we need a utf-8 when python starts or things won't work.") + context = Context(fixed_setup=False) # Default basepath @@ -261,19 +291,22 @@ def main(): scriptutils.logger_setup_color(logger, global_args.color) if global_args.bbpath is None: - tinfoil = setup_tinfoil(config_only=True, basepath=basepath) - global_args.bbpath = tinfoil.config_data.getVar('BBPATH', True) - else: - tinfoil = None - - for path in [scripts_path] + global_args.bbpath.split(':'): + try: + tinfoil = setup_tinfoil(config_only=True, basepath=basepath) + try: + global_args.bbpath = tinfoil.config_data.getVar('BBPATH') + finally: + tinfoil.shutdown() + except bb.BBHandledException: + return 2 + + # Search BBPATH first to allow layers to override plugins in scripts_path + for path in global_args.bbpath.split(':') + [scripts_path]: pluginpath = os.path.join(path, 'lib', 'devtool') scriptutils.load_plugins(logger, plugins, pluginpath) - if tinfoil: - tinfoil.shutdown() - subparsers = parser.add_subparsers(dest="subparser_name", title='subcommands', metavar='<subcommand>') + subparsers.required = True subparsers.add_subparser_group('sdk', 'SDK maintenance', -2) subparsers.add_subparser_group('advanced', 'Advanced', -1) @@ -299,13 +332,14 @@ def main(): if not getattr(args, 'no_workspace', False): read_workspace() + create_unlockedsigs() try: ret = args.func(args, config, basepath, workspace) except DevtoolError as err: if str(err): logger.error(str(err)) - ret = 1 + ret = err.exitcode except argparse_oe.ArgumentUsageError as ae: parser.error_subcommand(ae.message, ae.subcommand) @@ -318,5 +352,5 @@ if __name__ == "__main__": except Exception: ret = 1 import traceback - traceback.print_exc(5) + traceback.print_exc() sys.exit(ret) |
