diff options
Diffstat (limited to 'bitbake/lib/layerindexlib/restapi.py')
-rw-r--r-- | bitbake/lib/layerindexlib/restapi.py | 54 |
1 files changed, 24 insertions, 30 deletions
diff --git a/bitbake/lib/layerindexlib/restapi.py b/bitbake/lib/layerindexlib/restapi.py index d08eb20555..81d99b02ea 100644 --- a/bitbake/lib/layerindexlib/restapi.py +++ b/bitbake/lib/layerindexlib/restapi.py @@ -1,23 +1,17 @@ # Copyright (C) 2016-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. +# SPDX-License-Identifier: GPL-2.0-only # -# 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 logging import json +import os + from urllib.parse import unquote from urllib.parse import urlparse +import bb + import layerindexlib import layerindexlib.plugin @@ -37,7 +31,7 @@ class RestApiPlugin(layerindexlib.plugin.IndexPlugin): The return value is a LayerIndexObj. url is the url to the rest api of the layer index, such as: - http://layers.openembedded.org/layerindex/api/ + https://layers.openembedded.org/layerindex/api/ Or a local file... """ @@ -88,7 +82,7 @@ class RestApiPlugin(layerindexlib.plugin.IndexPlugin): def load_cache(path, index, branches=[]): - logger.debug(1, 'Loading json file %s' % path) + logger.debug('Loading json file %s' % path) with open(path, 'rt', encoding='utf-8') as f: pindex = json.load(f) @@ -108,7 +102,7 @@ class RestApiPlugin(layerindexlib.plugin.IndexPlugin): if newpBranch: index.add_raw_element('branches', layerindexlib.Branch, newpBranch) else: - logger.debug(1, 'No matching branches (%s) in index file(s)' % branches) + logger.debug('No matching branches (%s) in index file(s)' % branches) # No matching branches.. return nothing... return @@ -126,7 +120,7 @@ class RestApiPlugin(layerindexlib.plugin.IndexPlugin): load_cache(up.path, index, branches) return index - logger.debug(1, 'Loading from dir %s...' % (up.path)) + logger.debug('Loading from dir %s...' % (up.path)) for (dirpath, _, filenames) in os.walk(up.path): for filename in filenames: if not filename.endswith('.json'): @@ -144,13 +138,13 @@ class RestApiPlugin(layerindexlib.plugin.IndexPlugin): The return value is a LayerIndexObj. ud is the parsed url to the rest api of the layer index, such as: - http://layers.openembedded.org/layerindex/api/ + https://layers.openembedded.org/layerindex/api/ """ def _get_json_response(apiurl=None, username=None, password=None, retry=True): assert apiurl is not None - logger.debug(1, "fetching %s" % apiurl) + logger.debug("fetching %s" % apiurl) up = urlparse(apiurl) @@ -169,11 +163,11 @@ class RestApiPlugin(layerindexlib.plugin.IndexPlugin): parsed = json.loads(res.read().decode('utf-8')) except ConnectionResetError: if retry: - logger.debug(1, "%s: Connection reset by peer. Retrying..." % url) + logger.debug("%s: Connection reset by peer. Retrying..." % url) parsed = _get_json_response(apiurl=up_stripped.geturl(), username=username, password=password, retry=False) - logger.debug(1, "%s: retry successful.") + logger.debug("%s: retry successful.") else: - raise LayerIndexFetchError('%s: Connection reset by peer. Is there a firewall blocking your connection?' % apiurl) + raise layerindexlib.LayerIndexFetchError('%s: Connection reset by peer. Is there a firewall blocking your connection?' % apiurl) return parsed @@ -213,25 +207,25 @@ class RestApiPlugin(layerindexlib.plugin.IndexPlugin): if "*" not in branches: filter = "?filter=name:%s" % "OR".join(branches) - logger.debug(1, "Loading %s from %s" % (branches, index.apilinks['branches'])) + logger.debug("Loading %s from %s" % (branches, index.apilinks['branches'])) # The link won't include username/password, so pull it from the original url pindex['branches'] = _get_json_response(index.apilinks['branches'] + filter, username=up.username, password=up.password) if not pindex['branches']: - logger.debug(1, "No valid branches (%s) found at url %s." % (branch, url)) + logger.debug("No valid branches (%s) found at url %s." % (branch, url)) return index index.add_raw_element("branches", layerindexlib.Branch, pindex['branches']) # Load all of the layerItems (these can not be easily filtered) - logger.debug(1, "Loading %s from %s" % ('layerItems', index.apilinks['layerItems'])) + logger.debug("Loading %s from %s" % ('layerItems', index.apilinks['layerItems'])) # The link won't include username/password, so pull it from the original url pindex['layerItems'] = _get_json_response(index.apilinks['layerItems'], username=up.username, password=up.password) if not pindex['layerItems']: - logger.debug(1, "No layers were found at url %s." % (url)) + logger.debug("No layers were found at url %s." % (url)) return index index.add_raw_element("layerItems", layerindexlib.LayerItem, pindex['layerItems']) @@ -241,13 +235,13 @@ class RestApiPlugin(layerindexlib.plugin.IndexPlugin): for branch in index.branches: filter = "?filter=branch__name:%s" % index.branches[branch].name - logger.debug(1, "Loading %s from %s" % ('layerBranches', index.apilinks['layerBranches'])) + logger.debug("Loading %s from %s" % ('layerBranches', index.apilinks['layerBranches'])) # The link won't include username/password, so pull it from the original url pindex['layerBranches'] = _get_json_response(index.apilinks['layerBranches'] + filter, username=up.username, password=up.password) if not pindex['layerBranches']: - logger.debug(1, "No valid layer branches (%s) found at url %s." % (branches or "*", url)) + logger.debug("No valid layer branches (%s) found at url %s." % (branches or "*", url)) return index index.add_raw_element("layerBranches", layerindexlib.LayerBranch, pindex['layerBranches']) @@ -262,7 +256,7 @@ class RestApiPlugin(layerindexlib.plugin.IndexPlugin): ("distros", layerindexlib.Distro)]: if lName not in load: continue - logger.debug(1, "Loading %s from %s" % (lName, index.apilinks[lName])) + logger.debug("Loading %s from %s" % (lName, index.apilinks[lName])) # The link won't include username/password, so pull it from the original url pindex[lName] = _get_json_response(index.apilinks[lName] + filter, @@ -289,7 +283,7 @@ class RestApiPlugin(layerindexlib.plugin.IndexPlugin): if up.scheme != 'file': raise layerindexlib.plugin.LayerIndexPluginUrlError(self.type, url) - logger.debug(1, "Storing to %s..." % up.path) + logger.debug("Storing to %s..." % up.path) try: layerbranches = index.layerBranches @@ -305,12 +299,12 @@ class RestApiPlugin(layerindexlib.plugin.IndexPlugin): if getattr(index, objects)[obj].layerbranch_id == layerbranchid: filtered.append(getattr(index, objects)[obj]._data) except AttributeError: - logger.debug(1, 'No obj.layerbranch_id: %s' % objects) + logger.debug('No obj.layerbranch_id: %s' % objects) # No simple filter method, just include it... try: filtered.append(getattr(index, objects)[obj]._data) except AttributeError: - logger.debug(1, 'No obj._data: %s %s' % (objects, type(obj))) + logger.debug('No obj._data: %s %s' % (objects, type(obj))) filtered.append(obj) return filtered |