diff options
author | Aníbal Limón <anibal.limon@linux.intel.com> | 2015-07-13 16:25:16 -0500 |
---|---|---|
committer | Paul Eggleton <paul.eggleton@linux.intel.com> | 2018-05-04 23:57:52 +1200 |
commit | 1c2f2b8edbc71a5d9bc8cafe831ecb4be7641e9e (patch) | |
tree | ebd5d4bc1cefdaee5253d14dc84839aec2ebf947 /rrs/tools/rrs_distros.py | |
parent | ffee2377d11cea48c2171c4b0009c0bf1b307e4d (diff) | |
download | openembedded-core-contrib-1c2f2b8edbc71a5d9bc8cafe831ecb4be7641e9e.tar.gz |
rrs/tools: Add rrs_distros script.
This script updates the information about recipes in other distros.
Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
Diffstat (limited to 'rrs/tools/rrs_distros.py')
-rwxr-xr-x | rrs/tools/rrs_distros.py | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/rrs/tools/rrs_distros.py b/rrs/tools/rrs_distros.py new file mode 100755 index 0000000000..9dd564afa5 --- /dev/null +++ b/rrs/tools/rrs_distros.py @@ -0,0 +1,135 @@ +#!/usr/bin/env python + +# Update current distro information for recipes. +# +# Copyright (C) 2015 Intel Corporation +# Author: Anibal Limon <anibal.limon@linux.intel.com> +# +# Licensed under the MIT license, see COPYING.MIT for details + +import sys +import os.path +import optparse +import logging +from datetime import datetime + +sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__)))) +from common import common_setup, update_repo, load_recipes, \ + get_pv_type, get_logger +common_setup() +from layerindex import utils + +utils.setup_django() +from django.db import transaction +import settings + +logger = get_logger("RecipeDistros", settings) +fetchdir = settings.LAYER_FETCH_DIR +if not fetchdir: + logger.error("Please set LAYER_FETCH_DIR in settings.py") + sys.exit(1) + +update_repo(settings.LAYER_FETCH_DIR, 'poky', settings.POKY_REPO_URL, + True, logger) + +# setup bitbake path +bitbakepath = os.path.join(fetchdir, 'bitbake') +sys.path.insert(0, os.path.join(bitbakepath, 'lib')) + +from layerindex.models import Recipe, LayerBranch +from rrs.models import RecipeDistro + +""" + Searches the recipe's package in major distributions. + Returns a dictionary containing pairs of (distro name, package aliases). +""" +def search_package_in_distros(pkglst_dir, recipe, data): + distros = {} + distro_aliases = {} + + recipe_name = recipe.pn + + removes = ['nativesdk-', '-native', '-cross', '-initial'] + for r in removes: + recipe_name.replace(r, '') + + distro_alias = data.getVar('DISTRO_PN_ALIAS', True) + if distro_alias: + # Gets info from DISTRO_PN_ALIAS into a dictionary containing + # the distribution as a key and the package name as value. + for alias in distro_alias.split(): + if alias.find("=") != -1: + (dist, pn_alias) = alias.split('=') + distro_aliases[dist.strip().lower()] = pn_alias.strip() + + for distro_file in os.listdir(pkglst_dir): + (distro, distro_release) = distro_file.split("-") + + if distro.lower() in distro_aliases: + pn = distro_aliases[distro.lower()] + else: + pn = recipe_name + + f = open(os.path.join(pkglst_dir, distro_file), "rb") + for line in f: + (pkg, section) = line.split(":") + if pn == pkg: + distro_complete = distro + "-" + section[:-1] + distros[distro_complete] = pn + f.close() + break + f.close() + + return distros + +if __name__=="__main__": + parser = optparse.OptionParser(usage = """%prog [options]""") + + parser.add_option("-d", "--debug", + help = "Enable debug output", + action="store_const", const=logging.DEBUG, dest="loglevel", default=logging.INFO) + + options, args = parser.parse_args(sys.argv) + logger.setLevel(options.loglevel) + + logger.debug("Starting recipe distros update ...") + + transaction.enter_transaction_management() + transaction.managed(True) + + for layerbranch in LayerBranch.objects.all(): + (tinfoil, d, recipes) = load_recipes(layerbranch, bitbakepath, + fetchdir, settings, logger) + + if not recipes: + continue + + from oe import distro_check + logger.debug("Downloading distro's package information ...") + distro_check.create_distro_packages_list(fetchdir) + pkglst_dir = os.path.join(fetchdir, "package_lists") + + RecipeDistro.objects.filter(recipe__layerbranch = layerbranch).delete() + + for recipe_data in recipes: + pn = recipe_data.getVar('PN', True) + + try: + recipe = Recipe.objects.get(pn = pn, layerbranch = layerbranch) + except: + logger.warn('%s: layer branch %s, NOT found' % (pn, + str(layerbranch))) + continue + + distro_info = search_package_in_distros(pkglst_dir, recipe, recipe_data) + for distro, alias in distro_info.iteritems(): + recipedistro = RecipeDistro() + recipedistro.recipe = recipe + recipedistro.distro = distro + recipedistro.alias = alias + recipedistro.save() + logger.debug('%s: layer branch %s, add distro %s alias %s' % (pn, + str(layerbranch), distro, alias)) + + transaction.commit() + transaction.leave_transaction_management() |