From 3d14cc033a855bf5b20e799438548b6d8f29d9b8 Mon Sep 17 00:00:00 2001 From: Alexandru DAMIAN Date: Tue, 18 Aug 2015 17:28:55 +0100 Subject: toaster: replace raising Exceptions in loadconf This patch replaces throwing Exceptions in toaster loadconf command with proper explicit error messages. This allows the user to properly understand and debug what went wrong when loading a config file. Additionally we change a bit the logic around auto-detecting relative giturl handling so the user gets proper error messages when trying to load an invalid toasterconf.json file. [YOCTO #7945] Signed-off-by: Alexandru DAMIAN Signed-off-by: Michael Wood Signed-off-by: Richard Purdie --- .../bldcontrol/management/commands/loadconf.py | 37 ++++++++++++++-------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/lib/toaster/bldcontrol/management/commands/loadconf.py b/lib/toaster/bldcontrol/management/commands/loadconf.py index 9163e9bf1..5022b5940 100644 --- a/lib/toaster/bldcontrol/management/commands/loadconf.py +++ b/lib/toaster/bldcontrol/management/commands/loadconf.py @@ -1,10 +1,14 @@ from django.core.management.base import BaseCommand, CommandError from orm.models import LayerSource, ToasterSetting, Branch, Layer, Layer_Version from orm.models import BitbakeVersion, Release, ReleaseDefaultLayer, ReleaseLayerSourcePriority +from django.db import IntegrityError import os from checksettings import DN +import logging +logger = logging.getLogger("toaster") + def _reduce_canon_path(path): components = [] for c in path.split("/"): @@ -34,7 +38,7 @@ class Command(BaseCommand): if not os.path.exists(filepath) or not os.path.isfile(filepath): raise Exception("Failed to find toaster config file %s ." % filepath) - import json, pprint + import json data = json.loads(open(filepath, "r").read()) # verify config file validity before updating settings @@ -49,7 +53,7 @@ class Command(BaseCommand): cmd = subprocess.Popen("git remote -v", shell=True, cwd = os.path.dirname(filepath), stdout=subprocess.PIPE, stderr = subprocess.PIPE) (out,err) = cmd.communicate() if cmd.returncode != 0: - raise Exception("Error while importing layer vcs_url: git error: %s" % err) + logging.warning("Error while importing layer vcs_url: git error: %s" % err) for line in out.split("\n"): try: (name, path) = line.split("\t", 1) @@ -59,16 +63,20 @@ class Command(BaseCommand): except ValueError: pass if url == None: - raise Exception("Error while looking for remote \"%s\" in \"%s\"" % (remote_name, out)) + logging.warning("Error while looking for remote \"%s\" in \"%s\"" % (remote_name, out)) return url # import bitbake data for bvi in data['bitbake']: bvo, created = BitbakeVersion.objects.get_or_create(name=bvi['name']) - bvo.giturl = bvi['giturl'] if bvi['giturl'].startswith("remote:"): bvo.giturl = _read_git_url_from_local_repository(bvi['giturl']) + if bvo.giturl is None: + logger.error("The toaster config file references the local git repo, but Toaster cannot detect it.\nYour local configuration for bitbake version %s is invalid. Make sure that the toasterconf.json file is correct." % bvi['name']) + + if bvo.giturl is None: + bvo.giturl = bvi['giturl'] bvo.branch = bvi['branch'] bvo.dirpath = bvi['dirpath'] bvo.save() @@ -89,13 +97,12 @@ class Command(BaseCommand): assert ((_get_id_for_sourcetype(lsi['sourcetype']) == LayerSource.TYPE_LAYERINDEX) or apiurl.startswith("/")), (lsi['sourcetype'],apiurl) try: - ls = LayerSource.objects.get(sourcetype = _get_id_for_sourcetype(lsi['sourcetype']), apiurl = apiurl) - except LayerSource.DoesNotExist: - ls = LayerSource.objects.create( - name = lsi['name'], - sourcetype = _get_id_for_sourcetype(lsi['sourcetype']), - apiurl = apiurl - ) + ls, created = LayerSource.objects.get_or_create(sourcetype = _get_id_for_sourcetype(lsi['sourcetype']), apiurl = apiurl) + ls.name = lsi['name'] + ls.save() + except IntegrityError as e: + logger.warning("IntegrityError %s \nWhile setting name %s for layer source %s " % (e, lsi['name'], ls)) + layerbranches = [] for branchname in lsi['branches']: @@ -111,12 +118,14 @@ class Command(BaseCommand): lo.local_path = _reduce_canon_path(os.path.join(ls.apiurl, layerinfo['local_path'])) if not os.path.exists(lo.local_path): - raise Exception("Local layer path %s must exists." % lo.local_path) + logger.error("Local layer path %s must exists. Are you trying to import a layer that does not exist ? Check your local toasterconf.json" % lo.local_path) - lo.vcs_url = layerinfo['vcs_url'] if layerinfo['vcs_url'].startswith("remote:"): lo.vcs_url = _read_git_url_from_local_repository(layerinfo['vcs_url']) - else: + if lo.vcs_url is None: + logger.error("The toaster config file references the local git repo, but Toaster cannot detect it.\nYour local configuration for layer %s is invalid. Make sure that the toasterconf.json file is correct." % layerinfo['name']) + + if lo.vcs_url is None: lo.vcs_url = layerinfo['vcs_url'] if 'layer_index_url' in layerinfo: -- cgit 1.2.3-korg