diff options
| -rwxr-xr-x | bitbake/bin/toaster | 15 | ||||
| -rw-r--r-- | bitbake/lib/toaster/bldcontrol/management/commands/checksettings.py | 33 | ||||
| -rw-r--r-- | bitbake/lib/toaster/bldcontrol/management/commands/loadconf.py | 179 |
3 files changed, 0 insertions, 227 deletions
diff --git a/bitbake/bin/toaster b/bitbake/bin/toaster index 80d07ab0c8..e35bfce58c 100755 --- a/bitbake/bin/toaster +++ b/bitbake/bin/toaster | |||
| @@ -101,7 +101,6 @@ stop_system() | |||
| 101 | fi | 101 | fi |
| 102 | webserverKillAll | 102 | webserverKillAll |
| 103 | # unset exported variables | 103 | # unset exported variables |
| 104 | unset TOASTER_CONF | ||
| 105 | unset TOASTER_DIR | 104 | unset TOASTER_DIR |
| 106 | unset BITBAKE_UI | 105 | unset BITBAKE_UI |
| 107 | unset BBBASEDIR | 106 | unset BBBASEDIR |
| @@ -154,23 +153,9 @@ if [ -n "$TEMPLATECONF" ]; then | |||
| 154 | if [ -d "$OEROOT/$TEMPLATECONF" ]; then | 153 | if [ -d "$OEROOT/$TEMPLATECONF" ]; then |
| 155 | TEMPLATECONF="$OEROOT/$TEMPLATECONF" | 154 | TEMPLATECONF="$OEROOT/$TEMPLATECONF" |
| 156 | fi | 155 | fi |
| 157 | if [ ! -d "$TEMPLATECONF" ]; then | ||
| 158 | echo >&2 "Error: '$TEMPLATECONF' must be a directory containing toasterconf.json" | ||
| 159 | return 1 | ||
| 160 | fi | ||
| 161 | fi | 156 | fi |
| 162 | fi | 157 | fi |
| 163 | 158 | ||
| 164 | if [ "$TOASTER_CONF" = "" ]; then | ||
| 165 | TOASTER_CONF="$TEMPLATECONF/toasterconf.json" | ||
| 166 | export TOASTER_CONF=$(python3 -c "import os; print(os.path.realpath('$TOASTER_CONF'))") | ||
| 167 | fi | ||
| 168 | |||
| 169 | if [ ! -f $TOASTER_CONF ]; then | ||
| 170 | echo "$TOASTER_CONF configuration file not found. Set TOASTER_CONF to specify file or fix .templateconf" | ||
| 171 | return 1 | ||
| 172 | fi | ||
| 173 | |||
| 174 | # this defines the dir toaster will use for | 159 | # this defines the dir toaster will use for |
| 175 | # 1) clones of layers (in _toaster_clones ) | 160 | # 1) clones of layers (in _toaster_clones ) |
| 176 | # 2) the build dir (in build) | 161 | # 2) the build dir (in build) |
diff --git a/bitbake/lib/toaster/bldcontrol/management/commands/checksettings.py b/bitbake/lib/toaster/bldcontrol/management/commands/checksettings.py index fcee8b09ef..0dc55f63af 100644 --- a/bitbake/lib/toaster/bldcontrol/management/commands/checksettings.py +++ b/bitbake/lib/toaster/bldcontrol/management/commands/checksettings.py | |||
| @@ -26,39 +26,6 @@ class Command(NoArgsCommand): | |||
| 26 | super(Command, self).__init__(*args, **kwargs) | 26 | super(Command, self).__init__(*args, **kwargs) |
| 27 | self.guesspath = DN(DN(DN(DN(DN(DN(DN(__file__))))))) | 27 | self.guesspath = DN(DN(DN(DN(DN(DN(DN(__file__))))))) |
| 28 | 28 | ||
| 29 | def _find_first_path_for_file(self, startdirectory, filename, level=0): | ||
| 30 | if level < 0: | ||
| 31 | return None | ||
| 32 | dirs = [] | ||
| 33 | for i in os.listdir(startdirectory): | ||
| 34 | j = os.path.join(startdirectory, i) | ||
| 35 | if os.path.isfile(j): | ||
| 36 | if i == filename: | ||
| 37 | return startdirectory | ||
| 38 | elif os.path.isdir(j): | ||
| 39 | dirs.append(j) | ||
| 40 | for j in dirs: | ||
| 41 | ret = self._find_first_path_for_file(j, filename, level - 1) | ||
| 42 | if ret is not None: | ||
| 43 | return ret | ||
| 44 | return None | ||
| 45 | |||
| 46 | def _recursive_list_directories(self, startdirectory, level=0): | ||
| 47 | if level < 0: | ||
| 48 | return [] | ||
| 49 | dirs = [] | ||
| 50 | try: | ||
| 51 | for i in os.listdir(startdirectory): | ||
| 52 | j = os.path.join(startdirectory, i) | ||
| 53 | if os.path.isdir(j): | ||
| 54 | dirs.append(j) | ||
| 55 | except OSError: | ||
| 56 | pass | ||
| 57 | for j in dirs: | ||
| 58 | dirs = dirs + self._recursive_list_directories(j, level - 1) | ||
| 59 | return dirs | ||
| 60 | |||
| 61 | |||
| 62 | def _verify_build_environment(self): | 29 | def _verify_build_environment(self): |
| 63 | # provide a local build env. This will be extended later to include non local | 30 | # provide a local build env. This will be extended later to include non local |
| 64 | if BuildEnvironment.objects.count() == 0: | 31 | if BuildEnvironment.objects.count() == 0: |
diff --git a/bitbake/lib/toaster/bldcontrol/management/commands/loadconf.py b/bitbake/lib/toaster/bldcontrol/management/commands/loadconf.py deleted file mode 100644 index 4f8c9c6307..0000000000 --- a/bitbake/lib/toaster/bldcontrol/management/commands/loadconf.py +++ /dev/null | |||
| @@ -1,179 +0,0 @@ | |||
| 1 | from django.core.management.base import BaseCommand, CommandError | ||
| 2 | from orm.models import LayerSource, ToasterSetting, Layer, Layer_Version | ||
| 3 | from orm.models import BitbakeVersion, Release, ReleaseDefaultLayer | ||
| 4 | from django.db import IntegrityError | ||
| 5 | import os | ||
| 6 | |||
| 7 | from .checksettings import DN | ||
| 8 | |||
| 9 | import logging | ||
| 10 | logger = logging.getLogger("toaster") | ||
| 11 | |||
| 12 | # Temporary old code to support old toasterconf.json | ||
| 13 | def _reduce_canon_path(path): | ||
| 14 | components = [] | ||
| 15 | for c in path.split("/"): | ||
| 16 | if c == "..": | ||
| 17 | del components[-1] | ||
| 18 | elif c == ".": | ||
| 19 | pass | ||
| 20 | else: | ||
| 21 | components.append(c) | ||
| 22 | if len(components) < 2: | ||
| 23 | components.append('') | ||
| 24 | return "/".join(components) | ||
| 25 | # End temp code | ||
| 26 | |||
| 27 | class Command(BaseCommand): | ||
| 28 | help = "Loads a toasterconf.json file in the database" | ||
| 29 | args = "filepath" | ||
| 30 | |||
| 31 | |||
| 32 | |||
| 33 | def _import_layer_config(self, filepath): | ||
| 34 | if not os.path.exists(filepath) or not os.path.isfile(filepath): | ||
| 35 | raise Exception("Failed to find toaster config file %s ." % filepath) | ||
| 36 | |||
| 37 | import json | ||
| 38 | data = json.loads(open(filepath, "r").read()) | ||
| 39 | |||
| 40 | # verify config file validity before updating settings | ||
| 41 | for i in ['bitbake', 'releases', 'defaultrelease', 'config']: | ||
| 42 | assert i in data | ||
| 43 | |||
| 44 | def _read_git_url_from_local_repository(address): | ||
| 45 | url = None | ||
| 46 | # we detect the remote name at runtime | ||
| 47 | import subprocess | ||
| 48 | (remote, remote_name) = address.split(":", 1) | ||
| 49 | cmd = subprocess.Popen("git remote -v", shell=True, cwd = os.path.dirname(filepath), stdout=subprocess.PIPE, stderr = subprocess.PIPE) | ||
| 50 | (out,err) = cmd.communicate() | ||
| 51 | if cmd.returncode != 0: | ||
| 52 | logging.warning("Error while importing layer vcs_url: git error: %s" % err) | ||
| 53 | for line in out.decode('utf-8').split("\n"): | ||
| 54 | try: | ||
| 55 | (name, path) = line.split("\t", 1) | ||
| 56 | if name == remote_name: | ||
| 57 | url = path.split(" ")[0] | ||
| 58 | break | ||
| 59 | except ValueError: | ||
| 60 | pass | ||
| 61 | if url == None: | ||
| 62 | logging.warning("Error while looking for remote \"%s\" in \"%s\"" % (remote_name, out)) | ||
| 63 | return url | ||
| 64 | |||
| 65 | |||
| 66 | # import bitbake data | ||
| 67 | for bvi in data['bitbake']: | ||
| 68 | bvo, created = BitbakeVersion.objects.get_or_create(name=bvi['name']) | ||
| 69 | if bvi['giturl'].startswith("remote:"): | ||
| 70 | bvo.giturl = _read_git_url_from_local_repository(bvi['giturl']) | ||
| 71 | if bvo.giturl is None: | ||
| 72 | 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']) | ||
| 73 | |||
| 74 | if bvo.giturl is None: | ||
| 75 | bvo.giturl = bvi['giturl'] | ||
| 76 | bvo.branch = bvi['branch'] | ||
| 77 | bvo.dirpath = bvi['dirpath'] | ||
| 78 | bvo.save() | ||
| 79 | |||
| 80 | for ri in data['releases']: | ||
| 81 | bvo = BitbakeVersion.objects.get(name = ri['bitbake']) | ||
| 82 | assert bvo is not None | ||
| 83 | |||
| 84 | ro, created = Release.objects.get_or_create(name = ri['name'], bitbake_version = bvo, branch_name = ri['branch']) | ||
| 85 | ro.description = ri['description'] | ||
| 86 | ro.helptext = ri['helptext'] | ||
| 87 | ro.save() | ||
| 88 | |||
| 89 | for dli in ri['defaultlayers']: | ||
| 90 | # find layers with the same name | ||
| 91 | ReleaseDefaultLayer.objects.get_or_create( release = ro, layer_name = dli) | ||
| 92 | |||
| 93 | # NOTE Temporary old code to handle old toasterconf.json. All this to | ||
| 94 | # be removed after rewrite of config loading mechanism | ||
| 95 | for lsi in data['layersources']: | ||
| 96 | assert 'sourcetype' in lsi | ||
| 97 | assert 'apiurl' in lsi | ||
| 98 | assert 'name' in lsi | ||
| 99 | assert 'branches' in lsi | ||
| 100 | |||
| 101 | if "local" in lsi['sourcetype']: | ||
| 102 | ls = LayerSource.TYPE_LOCAL | ||
| 103 | else: | ||
| 104 | ls = LayerSource.TYPE_LAYERINDEX | ||
| 105 | |||
| 106 | layer_releases = [] | ||
| 107 | for branchname in lsi['branches']: | ||
| 108 | try: | ||
| 109 | release = Release.objects.get(branch_name=branchname) | ||
| 110 | layer_releases.append(release) | ||
| 111 | except Release.DoesNotExist: | ||
| 112 | logger.error("Layer set for %s but no release matches this" | ||
| 113 | "in the config" % branchname) | ||
| 114 | |||
| 115 | apiurl = _reduce_canon_path( | ||
| 116 | os.path.join(DN(os.path.abspath(filepath)), lsi['apiurl'])) | ||
| 117 | |||
| 118 | if 'layers' in lsi: | ||
| 119 | for layerinfo in lsi['layers']: | ||
| 120 | lo, created = Layer.objects.get_or_create( | ||
| 121 | name=layerinfo['name'], | ||
| 122 | vcs_url=layerinfo['vcs_url'], | ||
| 123 | ) | ||
| 124 | if layerinfo['local_path'].startswith("/"): | ||
| 125 | lo.local_path = layerinfo['local_path'] | ||
| 126 | else: | ||
| 127 | lo.local_path = _reduce_canon_path( | ||
| 128 | os.path.join(apiurl, layerinfo['local_path'])) | ||
| 129 | |||
| 130 | if layerinfo['vcs_url'].startswith("remote:"): | ||
| 131 | lo.vcs_url = _read_git_url_from_local_repository( | ||
| 132 | layerinfo['vcs_url']) | ||
| 133 | if lo.vcs_url is None: | ||
| 134 | logger.error("The toaster config file references" | ||
| 135 | " the local git repo, but Toaster " | ||
| 136 | "cannot detect it.\nYour local " | ||
| 137 | "configuration for layer %s is " | ||
| 138 | "invalid. Make sure that the " | ||
| 139 | "toasterconf.json file is correct." | ||
| 140 | % layerinfo['name']) | ||
| 141 | |||
| 142 | if lo.vcs_url is None: | ||
| 143 | lo.vcs_url = layerinfo['vcs_url'] | ||
| 144 | |||
| 145 | if 'layer_index_url' in layerinfo: | ||
| 146 | lo.layer_index_url = layerinfo['layer_index_url'] | ||
| 147 | lo.save() | ||
| 148 | |||
| 149 | for release in layer_releases: | ||
| 150 | lvo, created = Layer_Version.objects.get_or_create( | ||
| 151 | layer_source=ls, | ||
| 152 | release=release, | ||
| 153 | commit=release.branch_name, | ||
| 154 | branch=release.branch_name, | ||
| 155 | layer=lo) | ||
| 156 | lvo.dirpath = layerinfo['dirpath'] | ||
| 157 | lvo.save() | ||
| 158 | # END temporary code | ||
| 159 | |||
| 160 | |||
| 161 | # set default release | ||
| 162 | if ToasterSetting.objects.filter(name = "DEFAULT_RELEASE").count() > 0: | ||
| 163 | ToasterSetting.objects.filter(name = "DEFAULT_RELEASE").update(value = data['defaultrelease']) | ||
| 164 | else: | ||
| 165 | ToasterSetting.objects.create(name = "DEFAULT_RELEASE", value = data['defaultrelease']) | ||
| 166 | |||
| 167 | # set default config variables | ||
| 168 | for configname in data['config']: | ||
| 169 | if ToasterSetting.objects.filter(name = "DEFCONF_" + configname).count() > 0: | ||
| 170 | ToasterSetting.objects.filter(name = "DEFCONF_" + configname).update(value = data['config'][configname]) | ||
| 171 | else: | ||
| 172 | ToasterSetting.objects.create(name = "DEFCONF_" + configname, value = data['config'][configname]) | ||
| 173 | |||
| 174 | |||
| 175 | def handle(self, *args, **options): | ||
| 176 | if len(args) == 0: | ||
| 177 | raise CommandError("Need a path to the toasterconf.json file") | ||
| 178 | filepath = args[0] | ||
| 179 | self._import_layer_config(filepath) | ||
