Add a standard module for accessing the layerindex
cover Add a standard module for accessing the layerindex
In order to simply existing components, and add support to create some new functionaly -- we need a common apporach for access the layerindex.
The class supports loading multilib layerindexes, but right now that functionality is not being used by either bitbake-layers or the toaster.
There are a few 'TODO' items that remain in the code. These are related to either un-implemented, but planned functionality or to display stuff in bitbake-layers. I'm hoping that part of this review can discuss the TODO items.
Mark Hatle (5):
bblayers/layerindex.py: Fix addition of layers
layerindexlib: Initial layer index processing module implementation bblayers/layerindex.py: Switch to use the new layerindexlib class
bitbake-layers: disable parsing for layerindex commands toaster/orm/management/commands/lsupdates.py: Use new layerindexlib
module
bin/bitbake-selftest | 6 +- lib/bblayers/layerindex.py | 302 +++---- lib/layerindexlib/README | 28 + lib/layerindexlib/__init__.py | 974 +++++++++++++++++++++ lib/layerindexlib/common.py | 161 ++++ lib/layerindexlib/cooker.py | 338 +++++++ lib/layerindexlib/restapi.py | 375 ++++++++ lib/layerindexlib/tests/__init__.py | 0 lib/layerindexlib/tests/common.py | 37 + lib/layerindexlib/tests/cooker.py | 125 +++ lib/layerindexlib/tests/layerindex.py | 233 +++++ lib/layerindexlib/tests/restapi.py | 170 ++++ lib/layerindexlib/tests/testdata/README | 11 + .../tests/testdata/build/conf/bblayers.conf | 15 + .../tests/testdata/layer1/conf/layer.conf | 17 + .../tests/testdata/layer2/conf/layer.conf | 20 + .../tests/testdata/layer3/conf/layer.conf | 19 + .../tests/testdata/layer4/conf/layer.conf | 22 + lib/toaster/orm/management/commands/lsupdates.py | 215 ++--- 19 files changed, 2751 insertions(+), 317 deletions(-) create mode 100644 lib/layerindexlib/README create mode 100644 lib/layerindexlib/__init__.py create mode 100644 lib/layerindexlib/common.py create mode 100644 lib/layerindexlib/cooker.py create mode 100644 lib/layerindexlib/restapi.py create mode 100644 lib/layerindexlib/tests/__init__.py create mode 100644 lib/layerindexlib/tests/common.py create mode 100644 lib/layerindexlib/tests/cooker.py create mode 100644 lib/layerindexlib/tests/layerindex.py create mode 100644 lib/layerindexlib/tests/restapi.py create mode 100644 lib/layerindexlib/tests/testdata/README create mode 100644 lib/layerindexlib/tests/testdata/build/conf/bblayers.conf create mode 100644 lib/layerindexlib/tests/testdata/layer1/conf/layer.conf create mode 100644 lib/layerindexlib/tests/testdata/layer2/conf/layer.conf create mode 100644 lib/layerindexlib/tests/testdata/layer3/conf/layer.conf create mode 100644 lib/layerindexlib/tests/testdata/layer4/conf/layer.conf
Signature · 1 line
1.8.3.1
PATCH 1/5 bblayers/layerindex.py: Fix addition of layers
When a layer is added it needs to be in a list, otherwise the system will error such as:
Specified layer directory / doesn't contain a conf/layer.conf file
Additionally, instead of calling the add layer function over and over, it is better to add all of the new content in one command. Otherwise the order is important as the system now checks if the layer can be added. For instance, trying to add meta-python:
Layer Required by Git repository Subdirectory
===================================================================================================================
meta-python - git://git.openembedded.org/meta-openembedded meta-python meta-oe meta-python git://git.openembedded.org/meta-openembedded meta-oe openembedded-core meta-python git://git.openembedded.org/openembedded-core meta
Adding layer "meta-python" (.../oe-core/meta-openembedded/meta-python) to conf/bblayers.conf
ERROR: Layer 'meta-python' depends on layer 'openembedded-layer', but this layer is not enabled in your configuration
The system would try to add meta-python before the dependent meta-oe. Adding them both at the same time resolves this issue.
--- lib/bblayers/layerindex.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
lib/bblayers/layerindex.py +9 -6
@@ -239,19 +239,22 @@ class LayerIndexPlugin(ActionPlugin): return 1 addlayers.append((subdir, name, layerdir)) if not args.show_only: + localargs = argparse.Namespace() + localargs.layerdir = [] + localargs.force = args.force for subdir, name, layerdir in set(addlayers): if os.path.exists(layerdir): if subdir: - logger.plain("Adding layer \"%s\" to conf/bblayers.conf" % subdir) + logger.plain("Adding layer \"%s\" (%s) to conf/bblayers.conf" % (subdir, layerdir)) else: - logger.plain("Adding layer \"%s\" to conf/bblayers.conf" % name) - localargs = argparse.Namespace() - localargs.layerdir = layerdir - localargs.force = args.force - self.do_add_layer(localargs) + logger.plain("Adding layer \"%s\" (%s) to conf/bblayers.conf" % (name, layerdir)) + localargs.layerdir.append(layerdir) else: break + if localargs.layerdir: + self.do_add_layer(localargs) + def do_layerindex_show_depends(self, args): """Find layer dependencies from layer index. """
Signature · 1 line
1.8.3.1
PATCH 3/5 bblayers/layerindex.py: Switch to use the new layerindexlib class
In reply to Mark HatleDisplay changes:
The output will now include references to the layers that the user already has on their system. It does this by querying the cooker derived index.
The code that enables this behavior is labeled as 'TODO' currently. As part of the work we need to make a final determination if this is the desired output.
Also changed the default branch to no longer define itself as 'master'.
When the user does NOT set a branch, the default is now the 'LAYERSERIES_CORENAMES', and if that doesn't exist 'master'. This is subtly different in behavior, but more consistent with user expectations.
--- lib/bblayers/layerindex.py | 283 +++++++++++++++++---------------------------- 1 file changed, 104 insertions(+), 179 deletions(-)
lib/bblayers/layerindex.py +104 -179
@@ -1,10 +1,9 @@ +import layerindexlib + import argparse -import http.client -import json import logging import os import subprocess -import urllib.parse from bblayers.action import ActionPlugin
@@ -21,110 +20,6 @@ class LayerIndexPlugin(ActionPlugin): This class inherits ActionPlugin to get do_add_layer. """ - def get_json_data(self, apiurl): - proxy_settings = os.environ.get("http_proxy", None) - conn = None - _parsedurl = urllib.parse.urlparse(apiurl) - path = _parsedurl.path - query = _parsedurl.query - - def parse_url(url): - parsedurl = urllib.parse.urlparse(url) - if parsedurl.netloc[0] == '[': - host, port = parsedurl.netloc[1:].split(']', 1) - if ':' in port: - port = port.rsplit(':', 1)[1] - else: - port = None - else: - if parsedurl.netloc.count(':') == 1: - (host, port) = parsedurl.netloc.split(":") - else: - host = parsedurl.netloc - port = None - return (host, 80 if port is None else int(port)) - - if proxy_settings is None: - host, port = parse_url(apiurl) - conn = http.client.HTTPConnection(host, port) - conn.request("GET", path + "?" + query) - else: - host, port = parse_url(proxy_settings) - conn = http.client.HTTPConnection(host, port) - conn.request("GET", apiurl) - - r = conn.getresponse() - if r.status != 200: - raise Exception("Failed to read " + path + ": %d %s" % (r.status, r.reason)) - return json.loads(r.read().decode()) - - def get_layer_deps(self, layername, layeritems, layerbranches, layerdependencies, branchnum, selfname=False): - def layeritems_info_id(items_name, layeritems): - litems_id = None - for li in layeritems: - if li['name'] == items_name: - litems_id = li['id'] - break - return litems_id - - def layerbranches_info(items_id, layerbranches): - lbranch = {} - for lb in layerbranches: - if lb['layer'] == items_id and lb['branch'] == branchnum: - lbranch['id'] = lb['id'] - lbranch['vcs_subdir'] = lb['vcs_subdir'] - break - return lbranch - - def layerdependencies_info(lb_id, layerdependencies): - ld_deps = [] - for ld in layerdependencies: - if ld['layerbranch'] == lb_id and not ld['dependency'] in ld_deps: - ld_deps.append(ld['dependency']) - if not ld_deps: - logger.error("The dependency of layerDependencies is not found.") - return ld_deps - - def layeritems_info_name_subdir(items_id, layeritems): - litems = {} - for li in layeritems: - if li['id'] == items_id: - litems['vcs_url'] = li['vcs_url'] - litems['name'] = li['name'] - break - return litems - - if selfname: - selfid = layeritems_info_id(layername, layeritems) - lbinfo = layerbranches_info(selfid, layerbranches) - if lbinfo: - selfsubdir = lbinfo['vcs_subdir'] - else: - logger.error("%s is not found in the specified branch" % layername) - return - selfurl = layeritems_info_name_subdir(selfid, layeritems)['vcs_url'] - if selfurl: - return selfurl, selfsubdir - else: - logger.error("Cannot get layer %s git repo and subdir" % layername) - return - ldict = {} - itemsid = layeritems_info_id(layername, layeritems) - if not itemsid: - return layername, None - lbid = layerbranches_info(itemsid, layerbranches) - if lbid: - lbid = layerbranches_info(itemsid, layerbranches)['id'] - else: - logger.error("%s is not found in the specified branch" % layername) - return None, None - for dependency in layerdependencies_info(lbid, layerdependencies): - lname = layeritems_info_name_subdir(dependency, layeritems)['name'] - lurl = layeritems_info_name_subdir(dependency, layeritems)['vcs_url'] - lsubdir = layerbranches_info(dependency, layerbranches)['vcs_subdir'] - ldict[lname] = lurl, lsubdir - return None, ldict - def get_fetch_layer(self, fetchdir, url, subdir, fetch_layer): layername = self.get_layer_name(url) if os.path.splitext(layername)[1] == '.git':
@@ -136,95 +31,115 @@ class LayerIndexPlugin(ActionPlugin): result = subprocess.call('git clone %s %s' % (url, repodir), shell = True) if result: logger.error("Failed to download %s" % url) - return None, None + return None, None, None else: - return layername, layerdir + return subdir, layername, layerdir else: logger.plain("Repository %s needs to be fetched" % url) - return layername, layerdir + return subdir, layername, layerdir elif os.path.exists(layerdir): - return layername, layerdir + return subdir, layername, layerdir else: logger.error("%s is not in %s" % (url, subdir)) - return None, None + return None, None, None def do_layerindex_fetch(self, args): """Fetches a layer from a layer index along with its dependent layers, and adds them to conf/bblayers.conf. """ + + def _construct_url(baseurl, branch): + if baseurl[-1] != '/': + baseurl += '/' + baseurl += "api/" + baseurl += ";type=restapi" + + if branch: + baseurl += ";branch=%s" % branch + + return baseurl + + # General URL to use to access the layer index apiurl = self.tinfoil.config_data.getVar('BBLAYERS_LAYERINDEX_URL') if not apiurl: logger.error("Cannot get BBLAYERS_LAYERINDEX_URL") return 1 - else: - if apiurl[-1] != '/': - apiurl += '/' - apiurl += "api/" - apilinks = self.get_json_data(apiurl) - branches = self.get_json_data(apilinks['branches']) - - branchnum = 0 - for branch in branches: - if branch['name'] == args.branch: - branchnum = branch['id'] - break - if branchnum == 0: - validbranches = ', '.join([branch['name'] for branch in branches]) - logger.error('Invalid layer branch name "%s". Valid branches: %s' % (args.branch, validbranches)) + + remoteIndex = layerindexlib.LayerIndex(self.tinfoil.config_data) + + # Set the default... + branch = self.tinfoil.config_data.getVar('LAYERSERIES_CORENAMES') or 'master' + if args.branch: + branch = args.branch + + logger.debug(1, 'Trying branch %s' % branch) + try: + remoteIndex.load_layerindex(_construct_url(apiurl, branch)) + except Exception: + if branch == args.branch: + logger.error('Branch %s is not available' % branch) + return 1 + logger.debug(1, 'Falling back to branch master') + remoteIndex.load_layerindex(_construct_url(apiurl, 'master'), reload=True) + + if remoteIndex.is_empty(): return 1 - ignore_layers = [] - for collection in self.tinfoil.config_data.getVar('BBFILE_COLLECTIONS').split(): - lname = self.tinfoil.config_data.getVar('BBLAYERS_LAYERINDEX_NAME_%s' % collection) - if lname: - ignore_layers.append(lname) + # TODO: Determine display behavior... + # If we want the display to include already downloaded + # keep the following line, otherwise comment out. + cookerIndex = layerindexlib.LayerIndex(self.tinfoil.config_data) + cookerIndex.load_layerindex('file://local;type=cooker', load='layerDependencies') + + lIndex = cookerIndex + remoteIndex + ignore_layers = [] if args.ignore: ignore_layers.extend(args.ignore.split(',')) - layeritems = self.get_json_data(apilinks['layerItems']) - layerbranches = self.get_json_data(apilinks['layerBranches']) - layerdependencies = self.get_json_data(apilinks['layerDependencies']) - invaluenames = [] - repourls = {} - printlayers = [] - - def query_dependencies(layers, layeritems, layerbranches, layerdependencies, branchnum): - depslayer = [] - for layername in layers: - invaluename, layerdict = self.get_layer_deps(layername, layeritems, layerbranches, layerdependencies, branchnum) - if layerdict: - repourls[layername] = self.get_layer_deps(layername, layeritems, layerbranches, layerdependencies, branchnum, selfname=True) - for layer in layerdict: - if not layer in ignore_layers: - depslayer.append(layer) - printlayers.append((layername, layer, layerdict[layer][0], layerdict[layer][1])) - if not layer in ignore_layers and not layer in repourls: - repourls[layer] = (layerdict[layer][0], layerdict[layer][1]) - if invaluename and not invaluename in invaluenames: - invaluenames.append(invaluename) - return depslayer - - depslayers = query_dependencies(args.layername, layeritems, layerbranches, layerdependencies, branchnum) - while depslayers: - depslayer = query_dependencies(depslayers, layeritems, layerbranches, layerdependencies, branchnum) - depslayers = depslayer - if invaluenames: - for invaluename in invaluenames: + layernames = ' '.join(args.layername) + (dependencies, invalidnames) = lIndex.get_dependencies(names=layernames, ignores=ignore_layers) + + if invalidnames: + for invaluename in invalidnames: logger.error('Layer "%s" not found in layer index' % invaluename) return 1 - logger.plain("%s %s %s %s" % ("Layer".ljust(19), "Required by".ljust(19), "Git repository".ljust(54), "Subdirectory")) - logger.plain('=' * 115) - for layername in args.layername: - layerurl = repourls[layername] - logger.plain("%s %s %s %s" % (layername.ljust(20), '-'.ljust(20), layerurl[0].ljust(55), layerurl[1])) - printedlayers = [] - for layer, dependency, gitrepo, subdirectory in printlayers: - if dependency in printedlayers: - continue - logger.plain("%s %s %s %s" % (dependency.ljust(20), layer.ljust(20), gitrepo.ljust(55), subdirectory)) - printedlayers.append(dependency) - - if repourls: + + logger.plain("%s %s %s" % ("Layer".ljust(49), "Git repository (branch)".ljust(54), "Subdirectory")) + logger.plain('=' * 125) + + for deplayerbranch in dependencies: + layerBranch = dependencies[deplayerbranch][0] + + # TODO: Determine display behavior + # This is the local content, uncomment to hide local + # layers from the display. + #if layerBranch.index['CONFIG']['TYPE'] == 'cooker': + # continue + + layerDeps = dependencies[deplayerbranch][1:] + + requiredby = [] + recommendedby = [] + for dep in layerDeps: + if dep.is_required(): + requiredby.append(dep.get_layer().get_name()) + else: + recommendedby.append(dep.get_layer().get_name()) + + logger.plain('%s %s %s' % (("%s:%s:%s" % + (layerBranch.index['CONFIG']['DESCRIPTION'], + layerBranch.get_branch().get_name(), + layerBranch.get_layer().get_name())).ljust(50), + ("%s (%s)" % (layerBranch.get_layer().get_vcs_url(), + layerBranch.get_actual_branch())).ljust(55), + layerBranch.get_vcs_subdir() + )) + if requiredby: + logger.plain(' required by: %s' % ' '.join(requiredby)) + if recommendedby: + logger.plain(' recommended by: %s' % ' '.join(recommendedby)) + + if dependencies: fetchdir = self.tinfoil.config_data.getVar('BBLAYERS_FETCH_DIR') if not fetchdir: logger.error("Cannot get BBLAYERS_FETCH_DIR")
@@ -232,8 +147,18 @@ class LayerIndexPlugin(ActionPlugin): if not os.path.exists(fetchdir): os.makedirs(fetchdir) addlayers = [] - for repourl, subdir in repourls.values(): - name, layerdir = self.get_fetch_layer(fetchdir, repourl, subdir, not args.show_only) + + for deplayerbranch in dependencies: + layerBranch = dependencies[deplayerbranch][0] + + if layerBranch.index['CONFIG']['TYPE'] == 'cooker': + # Anything loaded via cooker is already local, skip it + continue + + subdir, name, layerdir = self.get_fetch_layer(fetchdir, + layerBranch.get_layer().get_vcs_url(), + layerBranch.get_vcs_subdir(), + not args.show_only) if not name: # Error already shown return 1
@@ -242,7 +167,7 @@ class LayerIndexPlugin(ActionPlugin): localargs = argparse.Namespace() localargs.layerdir = [] localargs.force = args.force - for subdir, name, layerdir in set(addlayers): + for subdir, name, layerdir in addlayers: if os.path.exists(layerdir): if subdir: logger.plain("Adding layer \"%s\" (%s) to conf/bblayers.conf" % (subdir, layerdir))
@@ -265,10 +190,10 @@ class LayerIndexPlugin(ActionPlugin): def register_commands(self, sp): parser_layerindex_fetch = self.add_command(sp, 'layerindex-fetch', self.do_layerindex_fetch) parser_layerindex_fetch.add_argument('-n', '--show-only', help='show dependencies and do nothing else', action='store_true') - parser_layerindex_fetch.add_argument('-b', '--branch', help='branch name to fetch (default %(default)s)', default='master') + parser_layerindex_fetch.add_argument('-b', '--branch', help='branch name to fetch') parser_layerindex_fetch.add_argument('-i', '--ignore', help='assume the specified layers do not need to be fetched/added (separate multiple layers with commas, no spaces)', metavar='LAYER') parser_layerindex_fetch.add_argument('layername', nargs='+', help='layer to fetch') parser_layerindex_show_depends = self.add_command(sp, 'layerindex-show-depends', self.do_layerindex_show_depends) - parser_layerindex_show_depends.add_argument('-b', '--branch', help='branch name to fetch (default %(default)s)', default='master') + parser_layerindex_show_depends.add_argument('-b', '--branch', help='branch name to fetch') parser_layerindex_show_depends.add_argument('layername', nargs='+', help='layer to query')
Signature · 1 line
1.8.3.1
PATCH 4/5 bitbake-layers: disable parsing for layerindex commands
In reply to Mark HatleThese don't need to access recipe information, so let's not waste the user's time parsing all recipes.
--- lib/bblayers/layerindex.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
lib/bblayers/layerindex.py +2 -2
@@ -188,12 +188,12 @@ class LayerIndexPlugin(ActionPlugin): self.do_layerindex_fetch(args) def register_commands(self, sp): - parser_layerindex_fetch = self.add_command(sp, 'layerindex-fetch', self.do_layerindex_fetch) + parser_layerindex_fetch = self.add_command(sp, 'layerindex-fetch', self.do_layerindex_fetch, parserecipes=False) parser_layerindex_fetch.add_argument('-n', '--show-only', help='show dependencies and do nothing else', action='store_true') parser_layerindex_fetch.add_argument('-b', '--branch', help='branch name to fetch') parser_layerindex_fetch.add_argument('-i', '--ignore', help='assume the specified layers do not need to be fetched/added (separate multiple layers with commas, no spaces)', metavar='LAYER') parser_layerindex_fetch.add_argument('layername', nargs='+', help='layer to fetch') - parser_layerindex_show_depends = self.add_command(sp, 'layerindex-show-depends', self.do_layerindex_show_depends) + parser_layerindex_show_depends = self.add_command(sp, 'layerindex-show-depends', self.do_layerindex_show_depends, parserecipes=False) parser_layerindex_show_depends.add_argument('-b', '--branch', help='branch name to fetch') parser_layerindex_show_depends.add_argument('layername', nargs='+', help='layer to query')
Signature · 1 line
1.8.3.1
PATCH 2/5 layerindexlib: Initial layer index processing module implementation
In reply to Mark HatleThe layer index module is expected to be used by various parts of the system in order to access a layerindex-web (such as layers.openembedded.org) and perform basic processing on the information, such as dependency scanning.
Along with the layerindex implementation are associated tests. The tests properly honor BB_SKIP_NETTESTS='yes' to prevent test failures.
Tests Implemented:
- Branch, LayerItem, LayerBranch, LayerDependency, Recipe, Machine and Distro objects
- LayerIndex setup using the layers.openembedded.org restapi
- LayerIndex storing and retrieving from a file
- LayerIndex verify dependency resolution ordering
- LayerIndex setup using simulated cooker data
--- bin/bitbake-selftest | 6 +- lib/layerindexlib/README | 28 + lib/layerindexlib/__init__.py | 974 +++++++++++++++++++++ lib/layerindexlib/common.py | 161 ++++ lib/layerindexlib/cooker.py | 338 +++++++ lib/layerindexlib/restapi.py | 375 ++++++++ lib/layerindexlib/tests/__init__.py | 0 lib/layerindexlib/tests/common.py | 37 + lib/layerindexlib/tests/cooker.py | 125 +++ lib/layerindexlib/tests/layerindex.py | 233 +++++ lib/layerindexlib/tests/restapi.py | 170 ++++ lib/layerindexlib/tests/testdata/README | 11 + .../tests/testdata/build/conf/bblayers.conf | 15 + .../tests/testdata/layer1/conf/layer.conf | 17 + .../tests/testdata/layer2/conf/layer.conf | 20 + .../tests/testdata/layer3/conf/layer.conf | 19 + .../tests/testdata/layer4/conf/layer.conf | 22 + 17 files changed, 2550 insertions(+), 1 deletion(-) create mode 100644 lib/layerindexlib/README create mode 100644 lib/layerindexlib/__init__.py create mode 100644 lib/layerindexlib/common.py create mode 100644 lib/layerindexlib/cooker.py create mode 100644 lib/layerindexlib/restapi.py create mode 100644 lib/layerindexlib/tests/__init__.py create mode 100644 lib/layerindexlib/tests/common.py create mode 100644 lib/layerindexlib/tests/cooker.py create mode 100644 lib/layerindexlib/tests/layerindex.py create mode 100644 lib/layerindexlib/tests/restapi.py create mode 100644 lib/layerindexlib/tests/testdata/README create mode 100644 lib/layerindexlib/tests/testdata/build/conf/bblayers.conf create mode 100644 lib/layerindexlib/tests/testdata/layer1/conf/layer.conf create mode 100644 lib/layerindexlib/tests/testdata/layer2/conf/layer.conf create mode 100644 lib/layerindexlib/tests/testdata/layer3/conf/layer.conf create mode 100644 lib/layerindexlib/tests/testdata/layer4/conf/layer.conf
bin/bitbake-selftest +5 -1
@@ -22,6 +22,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)), 'lib import unittest try: import bb + import layerindexlib except RuntimeError as exc: sys.exit(str(exc))
@@ -31,7 +32,10 @@ tests = ["bb.tests.codeparser", "bb.tests.event", "bb.tests.fetch", "bb.tests.parse", - "bb.tests.utils"] + "bb.tests.utils", + "layerindexlib.tests.layerindex", + "layerindexlib.tests.restapi", + "layerindexlib.tests.cooker"] for t in tests: t = '.'.join(t.split('.')[:3])
lib/layerindexlib/README new file +28 -0
@@ -0,0 +1,28 @@ +The layerindexlib module is designed to permit programs to work directly +with layer index information. (See layers.openembedded.org...) + +The layerindexlib module includes a plugin interface that is used to extend +the basic functionality. There are two primary plugins available: restapi +and cooker. + +The restapi plugin works with a web based REST Api compatible with the +layerindex-web project, as well as the ability to store and retried a +the information for one or more files on the disk. + +The cooker plugin works by reading the information from the current build +project and processing it as if it were a layer index. + + +TODO: + +__init__.py: +Implement local on-disk caching (using the rest api store/load) +Implement layer index style query operations on a combined index + +common.py: +Stop network access if BB_NO_NETWORK or allowed hosts is restricted + +cooker.py: +Cooker - Implement recipe parsing + +
lib/layerindexlib/__init__.py new file +974 -0
974 lines not on this page · raw message
lib/layerindexlib/common.py new file +161 -0
161 lines not on this page · raw message
lib/layerindexlib/cooker.py new file +338 -0
338 lines not on this page · raw message
lib/layerindexlib/restapi.py new file +375 -0
375 lines not on this page · raw message
lib/layerindexlib/tests/__init__.py new file +0 -0
lib/layerindexlib/tests/common.py new file +37 -0
@@ -0,0 +1,37 @@ +# Copyright (C) 2017-2018 Wind River Systems, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import unittest +import tempfile +import os +import bb + +import logging + +class LayersTest(unittest.TestCase): + + def setUp(self): + self.origdir = os.getcwd() + self.d = bb.data.init() + self.tempdir = tempfile.mkdtemp() + self.logger = logging.getLogger("BitBake") + + def tearDown(self): + os.chdir(self.origdir) + if os.environ.get("BB_TMPDIR_NOCLEAN") == "yes": + print("Not cleaning up %s. Please remove manually." % self.tempdir) + else: + bb.utils.prunedir(self.tempdir) +
lib/layerindexlib/tests/cooker.py new file +125 -0
125 lines not on this page · raw message
lib/layerindexlib/tests/layerindex.py new file +233 -0
233 lines not on this page · raw message
lib/layerindexlib/tests/restapi.py new file +170 -0
170 lines not on this page · raw message
lib/layerindexlib/tests/testdata/README new file +11 -0
@@ -0,0 +1,11 @@ +This test data is used to verify the 'cooker' module of the layerindex. + +The module consists of a faux project bblayers.conf with four layers defined. + +layer1 - openembedded-core +layer2 - networking-layer +layer3 - meta-python +layer4 - openembedded-layer (meta-oe) + +Since we do not have a fully populated cooker, we use this to test the +basic index generation, and not any deep recipe based contents.
lib/layerindexlib/tests/testdata/build/conf/bblayers.conf new file +15 -0
@@ -0,0 +1,15 @@ +LAYERSERIES_CORENAMES = "sumo" + +# LAYER_CONF_VERSION is increased each time build/conf/bblayers.conf +# changes incompatibly +LCONF_VERSION = "7" + +BBPATH = "${TOPDIR}" +BBFILES ?= "" + +BBLAYERS ?= " \ + ${TOPDIR}/layer1 \ + ${TOPDIR}/layer2 \ + ${TOPDIR}/layer3 \ + ${TOPDIR}/layer4 \ + "
lib/layerindexlib/tests/testdata/layer1/conf/layer.conf new file +17 -0
@@ -0,0 +1,17 @@ +# We have a conf and classes directory, add to BBPATH +BBPATH .= ":${LAYERDIR}" +# We have recipes-* directories, add to BBFILES +BBFILES += "${LAYERDIR}/recipes-*/*/*.bb" + +BBFILE_COLLECTIONS += "core" +BBFILE_PATTERN_core = "^${LAYERDIR}/" +BBFILE_PRIORITY_core = "5" + +LAYERSERIES_CORENAMES = "sumo" + +# This should only be incremented on significant changes that will +# cause compatibility issues with other layers +LAYERVERSION_core = "11" +LAYERSERIES_COMPAT_core = "sumo" + +BBLAYERS_LAYERINDEX_NAME_core = "openembedded-core"
lib/layerindexlib/tests/testdata/layer2/conf/layer.conf new file +20 -0
@@ -0,0 +1,20 @@ +# We have a conf and classes directory, add to BBPATH +BBPATH .= ":${LAYERDIR}" + +# We have a packages directory, add to BBFILES +BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \ + ${LAYERDIR}/recipes-*/*/*.bbappend" + +BBFILE_COLLECTIONS += "networking-layer" +BBFILE_PATTERN_networking-layer := "^${LAYERDIR}/" +BBFILE_PRIORITY_networking-layer = "5" + +# This should only be incremented on significant changes that will +# cause compatibility issues with other layers +LAYERVERSION_networking-layer = "1" + +LAYERDEPENDS_networking-layer = "core" +LAYERDEPENDS_networking-layer += "openembedded-layer" +LAYERDEPENDS_networking-layer += "meta-python" + +LAYERSERIES_COMPAT_networking-layer = "sumo"
lib/layerindexlib/tests/testdata/layer3/conf/layer.conf new file +19 -0
@@ -0,0 +1,19 @@ +# We might have a conf and classes directory, append to BBPATH +BBPATH .= ":${LAYERDIR}" + +# We have recipes directories, add to BBFILES +BBFILES += "${LAYERDIR}/recipes*/*/*.bb ${LAYERDIR}/recipes*/*/*.bbappend" + +BBFILE_COLLECTIONS += "meta-python" +BBFILE_PATTERN_meta-python := "^${LAYERDIR}/" +BBFILE_PRIORITY_meta-python = "7" + +# This should only be incremented on significant changes that will +# cause compatibility issues with other layers +LAYERVERSION_meta-python = "1" + +LAYERDEPENDS_meta-python = "core openembedded-layer" + +LAYERSERIES_COMPAT_meta-python = "sumo" + +LICENSE_PATH += "${LAYERDIR}/licenses"
lib/layerindexlib/tests/testdata/layer4/conf/layer.conf new file +22 -0
@@ -0,0 +1,22 @@ +# We have a conf and classes directory, append to BBPATH +BBPATH .= ":${LAYERDIR}" + +# We have a recipes directory, add to BBFILES +BBFILES += "${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/recipes-*/*/*.bbappend" + +BBFILE_COLLECTIONS += "openembedded-layer" +BBFILE_PATTERN_openembedded-layer := "^${LAYERDIR}/" + +# Define the priority for recipes (.bb files) from this layer, +# choosing carefully how this layer interacts with all of the +# other layers. + +BBFILE_PRIORITY_openembedded-layer = "6" + +# This should only be incremented on significant changes that will +# cause compatibility issues with other layers +LAYERVERSION_openembedded-layer = "1" + +LAYERDEPENDS_openembedded-layer = "core" + +LAYERSERIES_COMPAT_openembedded-layer = "sumo"
Signature · 1 line
1.8.3.1
PATCH 5/5 toaster/orm/management/commands/lsupdates.py: Use new layerindexlib module
In reply to Mark HatleChange lsupdates.py to use the new layerindexlib module to load the data from the public layer index. It still does all of the manual parsing. This is intended to be a stop gap until the toaster can use the module itself to manage the data.
Everything else is functionally equivalent to the prior version.
--- lib/toaster/orm/management/commands/lsupdates.py | 215 +++++++++-------------- 1 file changed, 86 insertions(+), 129 deletions(-)
lib/toaster/orm/management/commands/lsupdates.py +86 -129
@@ -29,7 +29,6 @@ from orm.models import ToasterSetting import os import sys -import json import logging import threading import time
@@ -37,6 +36,10 @@ logger = logging.getLogger("toaster") DEFAULT_LAYERINDEX_SERVER = "http://layers.openembedded.org/layerindex/api/" +# load Bitbake components +path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) +sys.path.insert(0, path) + class Spinner(threading.Thread): """ A simple progress spinner to indicate download/parsing is happening"""
@@ -86,45 +89,6 @@ class Command(BaseCommand): self.apiurl = ToasterSetting.objects.get(name = 'CUSTOM_LAYERINDEX_SERVER').value assert self.apiurl is not None - try: - from urllib.request import urlopen, URLError - from urllib.parse import urlparse - except ImportError: - from urllib2 import urlopen, URLError - from urlparse import urlparse - - proxy_settings = os.environ.get("http_proxy", None) - - def _get_json_response(apiurl=None): - if None == apiurl: - apiurl=self.apiurl - http_progress = Spinner() - http_progress.start() - - _parsedurl = urlparse(apiurl) - path = _parsedurl.path - - # logger.debug("Fetching %s", apiurl) - try: - res = urlopen(apiurl) - except URLError as e: - raise Exception("Failed to read %s: %s" % (path, e.reason)) - - parsed = json.loads(res.read().decode('utf-8')) - - http_progress.stop() - return parsed - - # verify we can get the basic api - try: - apilinks = _get_json_response() - except Exception as e: - import traceback - if proxy_settings is not None: - logger.info("EE: Using proxy %s" % proxy_settings) - logger.warning("EE: could not connect to %s, skipping update:" - "%s\n%s" % (self.apiurl, e, traceback.format_exc())) - return # update branches; only those that we already have names listed in the # Releases table
@@ -133,112 +97,117 @@ class Command(BaseCommand): if len(whitelist_branch_names) == 0: raise Exception("Failed to make list of branches to fetch") + self.apiurl += ";branch=%s" % ','.join(whitelist_branch_names) + + http_progress = Spinner() + logger.info("Fetching metadata releases for %s", " ".join(whitelist_branch_names)) - branches_info = _get_json_response(apilinks['branches'] + - "?filter=name:%s" - % "OR".join(whitelist_branch_names)) + + import layerindexlib + + layerindex = layerindexlib.LayerIndex(None) + + http_progress.start() + layerindex.load_layerindex(self.apiurl) + http_progress.stop() + + # We know we're only processing one entry, so we reference it here + # (this is cheating...) + lindex = layerindex.lindex[0] # Map the layer index branches to toaster releases li_branch_id_to_toaster_release = {} - total = len(branches_info) - for i, branch in enumerate(branches_info): - li_branch_id_to_toaster_release[branch['id']] = \ - Release.objects.get(name=branch['name']) + logger.info("Processing branches") + + total = len(lindex['branches']) + for i, branchId in enumerate(lindex['branches']): + li_branch_id_to_toaster_release[branchId] = \ + Release.objects.get(name=lindex['branches'][branchId].get_name()) self.mini_progress("Releases", i, total) # keep a track of the layerindex (li) id mappings so that # layer_versions can be created for these layers later on li_layer_id_to_toaster_layer_id = {} - logger.info("Fetching layers") - - layers_info = _get_json_response(apilinks['layerItems']) + logger.info("Processing layers") - total = len(layers_info) - for i, li in enumerate(layers_info): + total = len(lindex['layerItems']) + for i, liId in enumerate(lindex['layerItems']): try: - l, created = Layer.objects.get_or_create(name=li['name']) - l.up_date = li['updated'] - l.summary = li['summary'] - l.description = li['description'] + l, created = Layer.objects.get_or_create(name=lindex['layerItems'][liId].get_name()) + l.up_date = lindex['layerItems'][liId].get_updated() + l.summary = lindex['layerItems'][liId].get_summary() + l.description = lindex['layerItems'][liId].get_description() if created: # predefined layers in the fixtures (for example poky.xml) # always preempt the Layer Index for these values - l.vcs_url = li['vcs_url'] - l.vcs_web_url = li['vcs_web_url'] - l.vcs_web_tree_base_url = li['vcs_web_tree_base_url'] - l.vcs_web_file_base_url = li['vcs_web_file_base_url'] + l.vcs_url = lindex['layerItems'][liId].get_vcs_url() + l.vcs_web_url = lindex['layerItems'][liId].get_vcs_web_url() + l.vcs_web_tree_base_url = lindex['layerItems'][liId].get_vcs_web_tree_base_url() + l.vcs_web_file_base_url = lindex['layerItems'][liId].get_vcs_web_file_base_url() l.save() except Layer.MultipleObjectsReturned: logger.info("Skipped %s as we found multiple layers and " "don't know which to update" % li['name']) - li_layer_id_to_toaster_layer_id[li['id']] = l.pk + li_layer_id_to_toaster_layer_id[liId] = l.pk self.mini_progress("layers", i, total) # update layer_versions - logger.info("Fetching layer versions") - layerbranches_info = _get_json_response( - apilinks['layerBranches'] + "?filter=branch__name:%s" % - "OR".join(whitelist_branch_names)) + logger.info("Processing layer branches") # Map Layer index layer_branch object id to # layer_version toaster object id li_layer_branch_id_to_toaster_lv_id = {} - total = len(layerbranches_info) - for i, lbi in enumerate(layerbranches_info): + total = len(lindex['layerBranches']) + for i, lbiId in enumerate(lindex['layerBranches']): # release as defined by toaster map to layerindex branch - release = li_branch_id_to_toaster_release[lbi['branch']] + release = li_branch_id_to_toaster_release[lindex['layerBranches'][lbiId].get_branch_id()] try: lv, created = Layer_Version.objects.get_or_create( layer=Layer.objects.get( - pk=li_layer_id_to_toaster_layer_id[lbi['layer']]), + pk=li_layer_id_to_toaster_layer_id[lindex['layerBranches'][lbiId].get_layer_id()]), release=release ) except KeyError: logger.warning( "No such layerindex layer referenced by layerbranch %d" % - lbi['layer']) + lindex['layerBranches'][lbiId].get_layer_id()) continue if created: - lv.release = li_branch_id_to_toaster_release[lbi['branch']] - lv.up_date = lbi['updated'] - lv.commit = lbi['actual_branch'] - lv.dirpath = lbi['vcs_subdir'] + lv.release = li_branch_id_to_toaster_release[lindex['layerBranches'][lbiId].get_branch_id()] + lv.up_date = lindex['layerBranches'][lbiId].get_updated() + lv.commit = lindex['layerBranches'][lbiId].get_actual_branch() + lv.dirpath = lindex['layerBranches'][lbiId].get_vcs_subdir() lv.save() - li_layer_branch_id_to_toaster_lv_id[lbi['id']] =\ + li_layer_branch_id_to_toaster_lv_id[lindex['layerBranches'][lbiId].get_id()] =\ lv.pk self.mini_progress("layer versions", i, total) - logger.info("Fetching layer version dependencies") - # update layer dependencies - layerdependencies_info = _get_json_response( - apilinks['layerDependencies'] + - "?filter=layerbranch__branch__name:%s" % - "OR".join(whitelist_branch_names)) + logger.info("Processing layer dependencies") dependlist = {} - for ldi in layerdependencies_info: + for ldiId in lindex['layerDependencies']: try: lv = Layer_Version.objects.get( - pk=li_layer_branch_id_to_toaster_lv_id[ldi['layerbranch']]) + pk=li_layer_branch_id_to_toaster_lv_id[lindex['layerDependencies'][ldiId].get_layerbranch_id()]) except Layer_Version.DoesNotExist as e: continue if lv not in dependlist: dependlist[lv] = [] try: - layer_id = li_layer_id_to_toaster_layer_id[ldi['dependency']] + layer_id = li_layer_id_to_toaster_layer_id[lindex['layerDependencies'][ldiId].get_dependency_id()] dependlist[lv].append( Layer_Version.objects.get(layer__pk=layer_id,
@@ -247,7 +216,7 @@ class Command(BaseCommand): except Layer_Version.DoesNotExist: logger.warning("Cannot find layer version (ls:%s)," "up_id:%s lv:%s" % - (self, ldi['dependency'], lv)) + (self, lindex['layerDependencies'][ldiId].get_dependency_id(), lv)) total = len(dependlist) for i, lv in enumerate(dependlist):
@@ -258,73 +227,61 @@ class Command(BaseCommand): self.mini_progress("Layer version dependencies", i, total) # update Distros - logger.info("Fetching distro information") - distros_info = _get_json_response( - apilinks['distros'] + "?filter=layerbranch__branch__name:%s" % - "OR".join(whitelist_branch_names)) + logger.info("Processing distro information") - total = len(distros_info) - for i, di in enumerate(distros_info): + total = len(lindex['distros']) + for i, diId in enumerate(lindex['distros']): distro, created = Distro.objects.get_or_create( - name=di['name'], + name=lindex['distros'][diId].get_name(), layer_version=Layer_Version.objects.get( - pk=li_layer_branch_id_to_toaster_lv_id[di['layerbranch']])) - distro.up_date = di['updated'] - distro.name = di['name'] - distro.description = di['description'] + pk=li_layer_branch_id_to_toaster_lv_id[lindex['distros'][diId].get_layerbranch_id()])) + distro.up_date = lindex['distros'][diId].get_updated() + distro.name = lindex['distros'][diId].get_name() + distro.description = lindex['distros'][diId].get_description() distro.save() self.mini_progress("distros", i, total) # update machines - logger.info("Fetching machine information") - machines_info = _get_json_response( - apilinks['machines'] + "?filter=layerbranch__branch__name:%s" % - "OR".join(whitelist_branch_names)) + logger.info("Processing machine information") - total = len(machines_info) - for i, mi in enumerate(machines_info): + total = len(lindex['machines']) + for i, miId in enumerate(lindex['machines']): mo, created = Machine.objects.get_or_create( - name=mi['name'], + name=lindex['machines'][miId].get_name(), layer_version=Layer_Version.objects.get( - pk=li_layer_branch_id_to_toaster_lv_id[mi['layerbranch']])) - mo.up_date = mi['updated'] - mo.name = mi['name'] - mo.description = mi['description'] + pk=li_layer_branch_id_to_toaster_lv_id[lindex['machines'][miId].get_layerbranch_id()])) + mo.up_date = lindex['machines'][miId].get_updated() + mo.name = lindex['machines'][miId].get_name() + mo.description = lindex['machines'][miId].get_description() mo.save() self.mini_progress("machines", i, total) # update recipes; paginate by layer version / layer branch - logger.info("Fetching recipe information") - recipes_info = _get_json_response( - apilinks['recipes'] + "?filter=layerbranch__branch__name:%s" % - "OR".join(whitelist_branch_names)) + logger.info("Processing recipe information") - total = len(recipes_info) - for i, ri in enumerate(recipes_info): + total = len(lindex['recipes']) + for i, riId in enumerate(lindex['recipes']): try: - lv_id = li_layer_branch_id_to_toaster_lv_id[ri['layerbranch']] + lv_id = li_layer_branch_id_to_toaster_lv_id[lindex['recipes'][riId].get_layerbranch_id()] lv = Layer_Version.objects.get(pk=lv_id) ro, created = Recipe.objects.get_or_create( layer_version=lv, - name=ri['pn'] + name=lindex['recipes'][riId].get_pn() ) ro.layer_version = lv - ro.up_date = ri['updated'] - ro.name = ri['pn'] - ro.version = ri['pv'] - ro.summary = ri['summary'] - ro.description = ri['description'] - ro.section = ri['section'] - ro.license = ri['license'] - ro.homepage = ri['homepage'] - ro.bugtracker = ri['bugtracker'] - ro.file_path = ri['filepath'] + "/" + ri['filename'] - if 'inherits' in ri: - ro.is_image = 'image' in ri['inherits'].split() - else: # workaround for old style layer index - ro.is_image = "-image-" in ri['pn'] + ro.up_date = lindex['recipes'][riId].get_updated() + ro.name = lindex['recipes'][riId].get_pn() + ro.version = lindex['recipes'][riId].get_pv() + ro.summary = lindex['recipes'][riId].get_summary() + ro.description = lindex['recipes'][riId].get_description() + ro.section = lindex['recipes'][riId].get_section() + ro.license = lindex['recipes'][riId].get_license() + ro.homepage = lindex['recipes'][riId].get_homepage() + ro.bugtracker = lindex['recipes'][riId].get_bugtracker() + ro.file_path = lindex['recipes'][riId].get_filepath() + "/" + lindex['recipes'][riId].get_filename() + ro.is_image = 'image' in lindex['recipes'][riId].get_inherits().split() ro.save() except Exception as e: logger.warning("Failed saving recipe %s", e)
Signature · 1 line
1.8.3.1
Quoted 10 lines · Mark Hatle
In order to simply existing components, and add support to create some new functionaly -- we need a common apporach for access the layerindex.
The class supports loading multilib layerindexes, but right now that functionality is not being used by either bitbake-layers or the toaster.
There are a few 'TODO' items that remain in the code. These are related to either un-implemented, but planned functionality or to display stuff in bitbake-layers. I'm hoping that part of this review can discuss the TODO items.
FYI 2/5 is a bit large, and is held up in list moderation. I've posted all of the patches to:
http://git.openembedded.org/bitbake-contrib/log/?h=mgh/bitbake-layerindex
The bitbake-layers layerindex-fetch display has changed. For the example of:
$ bitbake-layers layerindex-fetch meta-python
Originally it would have produced:
Layer Required by Git repository
Subdirectory
===================================================================================================================
meta-python -git://git.openembedded.org/meta-openembedded meta-python
meta-oe meta-pythongit://git.openembedded.org/meta-openembedded meta-oe
openembedded-core meta-pythongit://git.openembedded.org/openembedded-core meta
Adding layer "meta-python" (.../oe-core/meta-openembedded/meta-python) to conf/bblayers.conf
Adding layer "meta-oe" (.../oe-core/meta-openembedded/meta-oe) to conf/bblayers.conf
With the new code, the output now looks like:
Layer Git repository (branch)
Subdirectory
=============================================================================================================================
local:sumo:openembedded-coregit://github.com/openembedded/openembedded-core (master) meta
required by: meta-python meta-oe
layers.openembedded.org:sumo:meta-oegit://git.openembedded.org/meta-openembedded (sumo) meta-oe
required by: meta-python
layers.openembedded.org:sumo:meta-pythongit://git.openembedded.org/meta-openembedded (sumo) meta-python
Adding layer "meta-oe" (/home/mhatle/git/oss/openembedded-core/meta-openembedded/meta-oe) to conf/bblayers.conf
Adding layer "meta-python" (/home/mhatle/git/oss/openembedded-core/meta-openembedded/meta-python) to conf/bblayers.conf
You will see that the order changed... the requested layer(s) will not be last instead of first. And the requirements have been moved to the following line. This was made to accommodate the 'layer' information changing. The format there is the '<index>:<index branch>:<layer>'
But as you can see the behavior is functionally equivalent, even though the order has changed.
--Mark
Quoted 46 lines
Mark Hatle (5):
bblayers/layerindex.py: Fix addition of layers
layerindexlib: Initial layer index processing module implementationbblayers/layerindex.py: Switch to use the new layerindexlib class
bitbake-layers: disable parsing for layerindex commandstoaster/orm/management/commands/lsupdates.py: Use new layerindexlib
modulebin/bitbake-selftest | 6 +- lib/bblayers/layerindex.py | 302 +++---- lib/layerindexlib/README | 28 + lib/layerindexlib/__init__.py | 974 +++++++++++++++++++++ lib/layerindexlib/common.py | 161 ++++ lib/layerindexlib/cooker.py | 338 +++++++ lib/layerindexlib/restapi.py | 375 ++++++++ lib/layerindexlib/tests/__init__.py | 0 lib/layerindexlib/tests/common.py | 37 + lib/layerindexlib/tests/cooker.py | 125 +++ lib/layerindexlib/tests/layerindex.py | 233 +++++ lib/layerindexlib/tests/restapi.py | 170 ++++ lib/layerindexlib/tests/testdata/README | 11 + .../tests/testdata/build/conf/bblayers.conf | 15 + .../tests/testdata/layer1/conf/layer.conf | 17 + .../tests/testdata/layer2/conf/layer.conf | 20 + .../tests/testdata/layer3/conf/layer.conf | 19 + .../tests/testdata/layer4/conf/layer.conf | 22 + lib/toaster/orm/management/commands/lsupdates.py | 215 ++--- 19 files changed, 2751 insertions(+), 317 deletions(-) create mode 100644 lib/layerindexlib/README create mode 100644 lib/layerindexlib/__init__.py create mode 100644 lib/layerindexlib/common.py create mode 100644 lib/layerindexlib/cooker.py create mode 100644 lib/layerindexlib/restapi.py create mode 100644 lib/layerindexlib/tests/__init__.py create mode 100644 lib/layerindexlib/tests/common.py create mode 100644 lib/layerindexlib/tests/cooker.py create mode 100644 lib/layerindexlib/tests/layerindex.py create mode 100644 lib/layerindexlib/tests/restapi.py create mode 100644 lib/layerindexlib/tests/testdata/README create mode 100644 lib/layerindexlib/tests/testdata/build/conf/bblayers.conf create mode 100644 lib/layerindexlib/tests/testdata/layer1/conf/layer.conf create mode 100644 lib/layerindexlib/tests/testdata/layer2/conf/layer.conf create mode 100644 lib/layerindexlib/tests/testdata/layer3/conf/layer.conf create mode 100644 lib/layerindexlib/tests/testdata/layer4/conf/layer.conf
Hi Mark
Quoted 11 lines · CEST Mark Hatle
Quoted 10 lines · Mark Hatle
In order to simply existing components, and add support to create some new functionaly -- we need a common apporach for access the layerindex.
The class supports loading multilib layerindexes, but right now that functionality is not being used by either bitbake-layers or the toaster.
There are a few 'TODO' items that remain in the code. These are related to either un-implemented, but planned functionality or to display stuff in bitbake-layers. I'm hoping that part of this review can discuss the TODO items.
This looks good, thanks - great to start to have a client API that we can use in a bunch of different places. Some comments:
1) LAYERSERIES_CORENAMES is treated by bitbake as a list. At the moment it's just one item, but we should treat it the same here - for now we can probably take the easiest way out and just split it and take the first item.
2) I feel like the ;type= stuff is an unnecessary complication. Can we not just treat http URLs as being restapi and local:// (or something similarly simple) as being the local configuration? The plugins could simply have a function that returns True if it can handle the URL, as we do in bb.fetch2, and we take the first one that returns True or error out if none do.
3) "except Exception" is too broad, can we catch a specific exception class or classes instead?
4) From an API perspective, it seems to me that we should be taking lists everywhere rather than space-delimited strings e.g. in get_dependencies() for the names parameter, particularly given the other parameters are actual lists.
5) I'd like to see the data classes (e.g. Recipe) have actual python properties on top of the getter functions, and the rest of the code should then use the properties. recipe.pn is a bit neater than recipe.get_pn() particularly as the former mirrors usage within the layer index code itself as well as tinfoil's TinfoilRecipeInfo (although TinfoilRecipeInfo doesn't actually use properties - it probably should - but the usage syntax is the key bit).
6) There are a number of different instances of variables "lindex" and they are different types. There's even "for lindex in self.lindex". This is a bit confusing.
7) What's loadRecipes = 1 for above load_layerindex() ?
Cheers,
Paul
Signature · 2 lines
Paul Eggleton Intel Open Source Technology Centre
Quoted 15 lines · Paul Eggleton
Hi Mark
Quoted 11 lines · CEST Mark Hatle
Quoted 10 lines · Mark Hatle
In order to simply existing components, and add support to create some new functionaly -- we need a common apporach for access the layerindex.
The class supports loading multilib layerindexes, but right now that functionality is not being used by either bitbake-layers or the toaster.
There are a few 'TODO' items that remain in the code. These are related to either un-implemented, but planned functionality or to display stuff in bitbake-layers. I'm hoping that part of this review can discuss the TODO items.
Quoted 6 lines
This looks good, thanks - great to start to have a client API that we can use in a bunch of different places. Some comments:
1)
LAYERSERIES_CORENAMESis treated by bitbake as a list. At the moment it's just one item, but we should treat it the same here - for now we can probably take the easiest way out and just split it and take the first item.
That was actually the intent, to treat it as a list. It must have fallen away in a refactor, I'll work to get this fixed.
Quoted 5 lines
2) I feel like the ;type= stuff is an unnecessary complication. Can we not just treat http URLs as being restapi and local:// (or something similarly simple) as being the local configuration? The plugins could simply have a function that returns True if it can handle the URL, as we do in bb.fetch2, and we take the first one that returns True or error out if none do.
Behind the scenes the issue is that I expect there to be different plugins that allow data manipulation in similar ways, but with different processing. I was afraid of overriding the URI part, thus added the type field instead.
If we can come up with a proper format for this, then I think we could drop the typing.. but what I've come up with so far is that we need:
Cooker - data from the local cooker instance
restapi-web - knowledge of how to load and parse layerindex-web data
restapi-file - a json formatted file with all of the data.. (Note: in this case, it can be one or more files, but everything has to be loaded together)
(the web and file stuff are co-mingled right now, maybe that is a mistake... they were put together since for 'offline' work, the web should be able to use a cached file...)
Looking at toaster, I could see the need for a 'database' way to store and load it... but I'm not sure that is a good longer term idea.
but I'm open to suggestion there to remove the type stuff..
Quoted 2 lines
3) "except Exception" is too broad, can we catch a specific exception class or classes instead?
This is a mistake in the implementation, the exceptions should have been:
LayerIndexError exceptions. (Defined in common.py)
Quoted 3 lines
4) From an API perspective, it seems to me that we should be taking lists everywhere rather than space-delimited strings e.g. in
get_dependencies()for the names parameter, particularly given the other parameters are actual lists.
Ok, I will update that.
Quoted 7 lines
5) I'd like to see the data classes (e.g. Recipe) have actual python properties on top of the getter functions, and the rest of the code should then use the properties. recipe.pn is a bit neater than
recipe.get_pn()particularly as the former mirrors usage within the layer index code itself as well as tinfoil's TinfoilRecipeInfo (although TinfoilRecipeInfo doesn't actually use properties - it probably should - but the usage syntax is the key bit).
I'm not sure I understand.
You mean something like:
class Recipe(LayerIndexItem_LayerBranch):
...
self.pn = value
so you can do recipe.pn vs recipe.pn() or get_pn()?
The reason it's setup the way it is, is to preserve the data in the same format as the layerindex itself. This allows someone to just dump the recipe.data
directly, and everything stays in format. Does python have a way to return
processed data without it looking like a function call, i.e. with the ()?
Is this what __getattr()__ is for?
Quoted 3 lines
6) There are a number of different instances of variables "lindex" and they are different types. There's even "for lindex in self.lindex". This is a bit confusing.
I was trying to not call everything 'layerindex' every time I used it.. :| Thus lindex..
self.lindex is the list of layerindex objects BTW. The layerindexer can handle more then one collection of objects... (multiple layer indexes specifically).
so the for lindex in self.lindex... is for each index in the list of indexes, do... I'll see what I can do about renaming this stuff.
Quoted 1 line
7) What's loadRecipes = 1 for above
load_layerindex()?
Errant paste.. no usage in this. I'll remove it.
Quoted 3 lines
Cheers,
Paul
Quoted 6 lines · CEST Mark Hatle
Quoted 5 lines
2) I feel like the ;type= stuff is an unnecessary complication. Can we not just treat http URLs as being restapi and local:// (or something similarly simple) as being the local configuration? The plugins could simply have a function that returns True if it can handle the URL, as we do in bb.fetch2, and we take the first one that returns True or error out if none do.
Quoted 8 lines
Behind the scenes the issue is that I expect there to be different plugins that allow data manipulation in similar ways, but with different processing. I was afraid of overriding the URI part, thus added the type field instead.
If we can come up with a proper format for this, then I think we could drop the typing.. but what I've come up with so far is that we need:
Cooker - data from the local cooker instance
local:// ?
Quoted 1 line
restapi-web - knowledge of how to load and parse layerindex-web data
http:// or https:// surely?
Quoted 2 lines
restapi-file - a json formatted file with all of the data.. (Note: in this case, it can be one or more files, but everything has to be loaded together)
file:// ?
If the desire was to also allow downloading json files over http/https you could make the decision after a quick query or simply check if the URL ends in .json.
Quoted 6 lines
(the web and file stuff are co-mingled right now, maybe that is a mistake... they were put together since for 'offline' work, the web should be able to use a cached file...)
Looking at toaster, I could see the need for a 'database' way to store and load it... but I'm not sure that is a good longer term idea.
Toaster uses the Django ORM to access the database, so you wouldn't be connecting to the database directly; you could make it accessible via a simple scheme such as toaster://.
Quoted 17 lines
Quoted 7 lines
5) I'd like to see the data classes (e.g. Recipe) have actual python properties on top of the getter functions, and the rest of the code should then use the properties. recipe.pn is a bit neater than
recipe.get_pn()particularly as the former mirrors usage within the layer index code itself as well as tinfoil's TinfoilRecipeInfo (although TinfoilRecipeInfo doesn't actually use properties - it probably should - but the usage syntax is the key bit).I'm not sure I understand.
You mean something like:
class
Recipe(LayerIndexItem_LayerBranch):
...self.pn = value
Quoted 8 lines
so you can do recipe.pn vs
recipe.pn()orget_pn()?The reason it's setup the way it is, is to preserve the data in the same format as the layerindex itself. This allows someone to just dump the recipe.data
directly, and everything stays in format. Does python have a way to return
processed data without it looking like a function call, i.e. with the ()?Is this what __getattr()__ is for?
It's one way of implementing it, but the much cleaner way is to use python's built-in support for properties:
https://www.programiz.com/python-programming/property
The underlying data storage doesn't have to change, your getter function can still read the values in whatever way it wants to.
Cheers,
Paul
Signature · 2 lines
Paul Eggleton Intel Open Source Technology Centre