summaryrefslogtreecommitdiffstats
path: root/bitbake/lib
diff options
context:
space:
mode:
authorAlexandru DAMIAN <alexandru.damian@intel.com>2015-08-18 17:28:55 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-08-19 18:05:54 +0100
commit242603e9b43be44bc735c6aaf9e721e08224667e (patch)
treea06c3f3ec23e7531cde8db98a08edc1d5d2d1fa9 /bitbake/lib
parentc159b3c1175d554f1cc60a41e1287d9ca4b3962f (diff)
downloadpoky-242603e9b43be44bc735c6aaf9e721e08224667e.tar.gz
bitbake: 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] (Bitbake rev: 3d14cc033a855bf5b20e799438548b6d8f29d9b8) Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com> Signed-off-by: Michael Wood <michael.g.wood@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
-rw-r--r--bitbake/lib/toaster/bldcontrol/management/commands/loadconf.py37
1 files changed, 23 insertions, 14 deletions
diff --git a/bitbake/lib/toaster/bldcontrol/management/commands/loadconf.py b/bitbake/lib/toaster/bldcontrol/management/commands/loadconf.py
index 9163e9bf11..5022b59400 100644
--- a/bitbake/lib/toaster/bldcontrol/management/commands/loadconf.py
+++ b/bitbake/lib/toaster/bldcontrol/management/commands/loadconf.py
@@ -1,10 +1,14 @@
1from django.core.management.base import BaseCommand, CommandError 1from django.core.management.base import BaseCommand, CommandError
2from orm.models import LayerSource, ToasterSetting, Branch, Layer, Layer_Version 2from orm.models import LayerSource, ToasterSetting, Branch, Layer, Layer_Version
3from orm.models import BitbakeVersion, Release, ReleaseDefaultLayer, ReleaseLayerSourcePriority 3from orm.models import BitbakeVersion, Release, ReleaseDefaultLayer, ReleaseLayerSourcePriority
4from django.db import IntegrityError
4import os 5import os
5 6
6from checksettings import DN 7from checksettings import DN
7 8
9import logging
10logger = logging.getLogger("toaster")
11
8def _reduce_canon_path(path): 12def _reduce_canon_path(path):
9 components = [] 13 components = []
10 for c in path.split("/"): 14 for c in path.split("/"):
@@ -34,7 +38,7 @@ class Command(BaseCommand):
34 if not os.path.exists(filepath) or not os.path.isfile(filepath): 38 if not os.path.exists(filepath) or not os.path.isfile(filepath):
35 raise Exception("Failed to find toaster config file %s ." % filepath) 39 raise Exception("Failed to find toaster config file %s ." % filepath)
36 40
37 import json, pprint 41 import json
38 data = json.loads(open(filepath, "r").read()) 42 data = json.loads(open(filepath, "r").read())
39 43
40 # verify config file validity before updating settings 44 # verify config file validity before updating settings
@@ -49,7 +53,7 @@ class Command(BaseCommand):
49 cmd = subprocess.Popen("git remote -v", shell=True, cwd = os.path.dirname(filepath), stdout=subprocess.PIPE, stderr = subprocess.PIPE) 53 cmd = subprocess.Popen("git remote -v", shell=True, cwd = os.path.dirname(filepath), stdout=subprocess.PIPE, stderr = subprocess.PIPE)
50 (out,err) = cmd.communicate() 54 (out,err) = cmd.communicate()
51 if cmd.returncode != 0: 55 if cmd.returncode != 0:
52 raise Exception("Error while importing layer vcs_url: git error: %s" % err) 56 logging.warning("Error while importing layer vcs_url: git error: %s" % err)
53 for line in out.split("\n"): 57 for line in out.split("\n"):
54 try: 58 try:
55 (name, path) = line.split("\t", 1) 59 (name, path) = line.split("\t", 1)
@@ -59,16 +63,20 @@ class Command(BaseCommand):
59 except ValueError: 63 except ValueError:
60 pass 64 pass
61 if url == None: 65 if url == None:
62 raise Exception("Error while looking for remote \"%s\" in \"%s\"" % (remote_name, out)) 66 logging.warning("Error while looking for remote \"%s\" in \"%s\"" % (remote_name, out))
63 return url 67 return url
64 68
65 69
66 # import bitbake data 70 # import bitbake data
67 for bvi in data['bitbake']: 71 for bvi in data['bitbake']:
68 bvo, created = BitbakeVersion.objects.get_or_create(name=bvi['name']) 72 bvo, created = BitbakeVersion.objects.get_or_create(name=bvi['name'])
69 bvo.giturl = bvi['giturl']
70 if bvi['giturl'].startswith("remote:"): 73 if bvi['giturl'].startswith("remote:"):
71 bvo.giturl = _read_git_url_from_local_repository(bvi['giturl']) 74 bvo.giturl = _read_git_url_from_local_repository(bvi['giturl'])
75 if bvo.giturl is None:
76 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'])
77
78 if bvo.giturl is None:
79 bvo.giturl = bvi['giturl']
72 bvo.branch = bvi['branch'] 80 bvo.branch = bvi['branch']
73 bvo.dirpath = bvi['dirpath'] 81 bvo.dirpath = bvi['dirpath']
74 bvo.save() 82 bvo.save()
@@ -89,13 +97,12 @@ class Command(BaseCommand):
89 assert ((_get_id_for_sourcetype(lsi['sourcetype']) == LayerSource.TYPE_LAYERINDEX) or apiurl.startswith("/")), (lsi['sourcetype'],apiurl) 97 assert ((_get_id_for_sourcetype(lsi['sourcetype']) == LayerSource.TYPE_LAYERINDEX) or apiurl.startswith("/")), (lsi['sourcetype'],apiurl)
90 98
91 try: 99 try:
92 ls = LayerSource.objects.get(sourcetype = _get_id_for_sourcetype(lsi['sourcetype']), apiurl = apiurl) 100 ls, created = LayerSource.objects.get_or_create(sourcetype = _get_id_for_sourcetype(lsi['sourcetype']), apiurl = apiurl)
93 except LayerSource.DoesNotExist: 101 ls.name = lsi['name']
94 ls = LayerSource.objects.create( 102 ls.save()
95 name = lsi['name'], 103 except IntegrityError as e:
96 sourcetype = _get_id_for_sourcetype(lsi['sourcetype']), 104 logger.warning("IntegrityError %s \nWhile setting name %s for layer source %s " % (e, lsi['name'], ls))
97 apiurl = apiurl 105
98 )
99 106
100 layerbranches = [] 107 layerbranches = []
101 for branchname in lsi['branches']: 108 for branchname in lsi['branches']:
@@ -111,12 +118,14 @@ class Command(BaseCommand):
111 lo.local_path = _reduce_canon_path(os.path.join(ls.apiurl, layerinfo['local_path'])) 118 lo.local_path = _reduce_canon_path(os.path.join(ls.apiurl, layerinfo['local_path']))
112 119
113 if not os.path.exists(lo.local_path): 120 if not os.path.exists(lo.local_path):
114 raise Exception("Local layer path %s must exists." % lo.local_path) 121 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)
115 122
116 lo.vcs_url = layerinfo['vcs_url']
117 if layerinfo['vcs_url'].startswith("remote:"): 123 if layerinfo['vcs_url'].startswith("remote:"):
118 lo.vcs_url = _read_git_url_from_local_repository(layerinfo['vcs_url']) 124 lo.vcs_url = _read_git_url_from_local_repository(layerinfo['vcs_url'])
119 else: 125 if lo.vcs_url is None:
126 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'])
127
128 if lo.vcs_url is None:
120 lo.vcs_url = layerinfo['vcs_url'] 129 lo.vcs_url = layerinfo['vcs_url']
121 130
122 if 'layer_index_url' in layerinfo: 131 if 'layer_index_url' in layerinfo: