Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mail.openembedded.org (Postfix) with ESMTP id F215D75678 for ; Thu, 11 Jun 2015 11:34:29 +0000 (UTC) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP; 11 Jun 2015 04:34:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,595,1427785200"; d="scan'208";a="709156489" Received: from marquiz.fi.intel.com ([10.237.72.155]) by orsmga001.jf.intel.com with ESMTP; 11 Jun 2015 04:34:30 -0700 From: Markus Lehtonen To: openembedded-core@lists.openembedded.org Date: Thu, 11 Jun 2015 14:34:16 +0300 Message-Id: <1434022456-26266-11-git-send-email-markus.lehtonen@linux.intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1434022456-26266-1-git-send-email-markus.lehtonen@linux.intel.com> References: <1434022456-26266-1-git-send-email-markus.lehtonen@linux.intel.com> Cc: Paul Eggleton Subject: [PATCH v2 10/10] devtool: use DevtoolError for error handling X-BeenThere: openembedded-core@lists.openembedded.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Patches and discussions about the oe-core layer List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Jun 2015 11:34:30 -0000 Use DevtoolError exception more widely for handling error cases. This exception is now caught in the main script and raising it can be used to exit with an error. This hopefully simplifies error handling. The change also makes exit codes more consistent, always returning '1' when an error occurs. Signed-off-by: Markus Lehtonen --- scripts/devtool | 8 ++- scripts/lib/devtool/__init__.py | 6 ++ scripts/lib/devtool/deploy.py | 31 ++++---- scripts/lib/devtool/standard.py | 154 ++++++++++++++++++---------------------- 4 files changed, 99 insertions(+), 100 deletions(-) diff --git a/scripts/devtool b/scripts/devtool index 307846a..7fd4da3 100755 --- a/scripts/devtool +++ b/scripts/devtool @@ -35,6 +35,7 @@ context = None scripts_path = os.path.dirname(os.path.realpath(__file__)) lib_path = scripts_path + '/lib' sys.path = sys.path + [lib_path] +from devtool import DevtoolError import scriptutils logger = scriptutils.logger_create('devtool') @@ -249,7 +250,12 @@ def main(): if args.subparser_name != 'create-workspace': read_workspace() - ret = args.func(args, config, basepath, workspace) + try: + ret = args.func(args, config, basepath, workspace) + except DevtoolError as err: + if str(err): + logger.error(str(err)) + ret = 1 return ret diff --git a/scripts/lib/devtool/__init__.py b/scripts/lib/devtool/__init__.py index 9ec1ef6..ea0b63e 100644 --- a/scripts/lib/devtool/__init__.py +++ b/scripts/lib/devtool/__init__.py @@ -25,6 +25,12 @@ import logging logger = logging.getLogger('devtool') + +class DevtoolError(Exception): + """Exception for handling devtool errors""" + pass + + def exec_build_env_command(init_path, builddir, cmd, watch=False, **options): """Run a program in bitbake build context""" import bb diff --git a/scripts/lib/devtool/deploy.py b/scripts/lib/devtool/deploy.py index 92a3cb4..ca74a8e 100644 --- a/scripts/lib/devtool/deploy.py +++ b/scripts/lib/devtool/deploy.py @@ -19,7 +19,7 @@ import os import subprocess import logging -from devtool import exec_build_env_command, setup_tinfoil +from devtool import exec_build_env_command, setup_tinfoil, DevtoolError logger = logging.getLogger('devtool') @@ -34,8 +34,8 @@ def deploy(args, config, basepath, workspace): import oe.recipeutils if not args.recipename in workspace: - logger.error("no recipe named %s in your workspace" % args.recipename) - return -1 + raise DevtoolError("no recipe named %s in your workspace" % + args.recipename) try: host, destdir = args.target.split(':') except ValueError: @@ -50,12 +50,13 @@ def deploy(args, config, basepath, workspace): try: rd = oe.recipeutils.parse_recipe_simple(tinfoil.cooker, args.recipename, tinfoil.config_data) except Exception as e: - logger.error('Exception parsing recipe %s: %s' % (args.recipename, e)) - return 2 + raise DevtoolError('Exception parsing recipe %s: %s' % + (args.recipename, e)) recipe_outdir = rd.getVar('D', True) if not os.path.exists(recipe_outdir) or not os.listdir(recipe_outdir): - logger.error('No files to deploy - have you built the %s recipe? If so, the install step has not installed any files.' % args.recipename) - return -1 + raise DevtoolError('No files to deploy - have you built the %s ' + 'recipe? If so, the install step has not installed ' + 'any files.' % args.recipename) if args.dry_run: print('Files to be deployed for %s on target %s:' % (args.recipename, args.target)) @@ -67,7 +68,7 @@ def deploy(args, config, basepath, workspace): if os.path.exists(deploy_file): if undeploy(args, config, basepath, workspace): # Error already shown - return -1 + return 1 extraoptions = '' if args.no_host_check: @@ -76,8 +77,8 @@ def deploy(args, config, basepath, workspace): extraoptions += ' -q' ret = subprocess.call('scp -r %s %s/* %s:%s' % (extraoptions, recipe_outdir, args.target, destdir), shell=True) if ret != 0: - logger.error('Deploy failed - rerun with -s to get a complete error message') - return ret + raise DevtoolError('Deploy failed - rerun with -s to get a complete ' + 'error message') logger.info('Successfully deployed %s' % recipe_outdir) @@ -99,8 +100,7 @@ def undeploy(args, config, basepath, workspace): """Entry point for the devtool 'undeploy' subcommand""" deploy_file = os.path.join(basepath, 'target_deploy', args.target, args.recipename + '.list') if not os.path.exists(deploy_file): - logger.error('%s has not been deployed' % args.recipename) - return -1 + raise DevtoolError('%s has not been deployed' % args.recipename) if args.dry_run: print('Previously deployed files to be un-deployed for %s on target %s:' % (args.recipename, args.target)) @@ -117,15 +117,16 @@ def undeploy(args, config, basepath, workspace): ret = subprocess.call("scp %s %s %s:/tmp" % (extraoptions, deploy_file, args.target), shell=True) if ret != 0: - logger.error('Failed to copy file list to %s - rerun with -s to get a complete error message' % args.target) - return -1 + raise DevtoolError('Failed to copy file list to %s - rerun with -s to ' + 'get a complete error message' % args.target) ret = subprocess.call("ssh %s %s 'xargs -n1 rm -f