diff options
-rw-r--r-- | bitbake/lib/toaster/bldcontrol/management/commands/loadconf.py | 85 |
1 files changed, 82 insertions, 3 deletions
diff --git a/bitbake/lib/toaster/bldcontrol/management/commands/loadconf.py b/bitbake/lib/toaster/bldcontrol/management/commands/loadconf.py index 59324acbc5..4f8c9c6307 100644 --- a/bitbake/lib/toaster/bldcontrol/management/commands/loadconf.py +++ b/bitbake/lib/toaster/bldcontrol/management/commands/loadconf.py | |||
@@ -9,6 +9,20 @@ from .checksettings import DN | |||
9 | import logging | 9 | import logging |
10 | logger = logging.getLogger("toaster") | 10 | logger = logging.getLogger("toaster") |
11 | 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 | ||
12 | 26 | ||
13 | class Command(BaseCommand): | 27 | class Command(BaseCommand): |
14 | help = "Loads a toasterconf.json file in the database" | 28 | help = "Loads a toasterconf.json file in the database" |
@@ -76,6 +90,74 @@ class Command(BaseCommand): | |||
76 | # find layers with the same name | 90 | # find layers with the same name |
77 | ReleaseDefaultLayer.objects.get_or_create( release = ro, layer_name = dli) | 91 | ReleaseDefaultLayer.objects.get_or_create( release = ro, layer_name = dli) |
78 | 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 | |||
79 | # set default release | 161 | # set default release |
80 | if ToasterSetting.objects.filter(name = "DEFAULT_RELEASE").count() > 0: | 162 | if ToasterSetting.objects.filter(name = "DEFAULT_RELEASE").count() > 0: |
81 | ToasterSetting.objects.filter(name = "DEFAULT_RELEASE").update(value = data['defaultrelease']) | 163 | ToasterSetting.objects.filter(name = "DEFAULT_RELEASE").update(value = data['defaultrelease']) |
@@ -95,6 +177,3 @@ class Command(BaseCommand): | |||
95 | raise CommandError("Need a path to the toasterconf.json file") | 177 | raise CommandError("Need a path to the toasterconf.json file") |
96 | filepath = args[0] | 178 | filepath = args[0] |
97 | self._import_layer_config(filepath) | 179 | self._import_layer_config(filepath) |
98 | |||
99 | |||
100 | |||