Beispiel #1
0
def rrs_import(args):
    utils.setup_django()
    import settings
    from django.db import transaction
    from rrs.models import RecipeUpstreamHistory, RecipeUpstream
    from layerindex.models import Recipe

    core_layer = utils.get_layer(settings.CORE_LAYER_NAME)
    if not core_layer:
        logger.error('Unable to find core layer %s' % settings.CORE_LAYER_NAME)
        return 1
    core_layerbranch = core_layer.get_layerbranch('master')
    if not core_layerbranch:
        logger.error('Unable to find branch master of layer %s' % core_layerbranch.name)
        return 1

    layerbranch = core_layerbranch
    try:
        with transaction.atomic():
            with open(args.infile, 'r') as f:
                data = json.load(f)
                for item, itemdata in data.items():
                    if item == 'recipeupstreamhistory':
                        for histdata in itemdata:
                            ruh = RecipeUpstreamHistory()
                            ruh.start_date = histdata['start_date']
                            ruh.end_date = histdata['end_date']
                            ruh.layerbranch = layerbranch
                            ruh.save()
                            for upstreamdata in histdata['upstreams']:
                                ru = RecipeUpstream()
                                ru.history = ruh
                                pn = upstreamdata['recipe']
                                recipe = Recipe.objects.filter(layerbranch=layerbranch, pn=pn).first()
                                if not recipe:
                                    logger.warning('Could not find recipe %s in layerbranch %s' % (pn, layerbranch))
                                    continue
                                ru.recipe = recipe
                                ru.version = upstreamdata['version']
                                ru.type = upstreamdata['type']
                                ru.status = upstreamdata['status']
                                ru.no_update_reason = upstreamdata['no_update_reason']
                                ru.date = upstreamdata['date']
                                ru.save()

            if args.dry_run:
                raise DryRunRollbackException
    except DryRunRollbackException:
        pass

    return 0
Beispiel #2
0
def _get_recipe_list(milestone):
    recipe_list = []
    recipes_ids = []
    recipe_upstream_dict_all = {}
    recipe_last_updated_dict_all = {}
    maintainers_dict_all = {}
    current_date = date.today()

    for maintplanlayer in milestone.release.plan.maintenanceplanlayerbranch_set.all(
    ):
        layerbranch = maintplanlayer.layerbranch

        recipe_maintainer_history = Raw.get_remahi_by_end_date(
            layerbranch.id, milestone.end_date)

        recipe_upstream_history = RecipeUpstreamHistory.get_last_by_date_range(
            layerbranch, milestone.start_date, milestone.end_date)

        recipes = Raw.get_reupg_by_date(layerbranch.id, milestone.end_date)
        for i, re in enumerate(recipes):
            if 'pv' in re:
                recipes[i]['version'] = re['pv']
            recipes_ids.append(re['id'])

        if recipes:
            recipe_last_updated = Raw.get_reup_by_last_updated(
                layerbranch.id, milestone.end_date)
            for rela in recipe_last_updated:
                recipe_last_updated_dict_all[rela['recipe_id']] = rela

            if recipe_upstream_history:
                recipe_upstream_all = Raw.get_reup_by_recipes_and_date(
                    recipes_ids, recipe_upstream_history.id)
                for reup in recipe_upstream_all:
                    recipe_upstream_dict_all[reup['recipe_id']] = reup

            if recipe_maintainer_history:
                maintainers_all = Raw.get_ma_by_recipes_and_date(
                    recipes_ids, recipe_maintainer_history[0])
                for ma in maintainers_all:
                    maintainers_dict_all[ma['recipe_id']] = ma['name']

    for recipe in recipes:
        upstream_version = ''
        upstream_status = ''
        no_update_reason = ''
        outdated = ''

        if recipe_upstream_history:
            recipe_upstream = recipe_upstream_dict_all.get(recipe['id'])
            if not recipe_upstream:
                recipe_add = Recipe.objects.filter(id=recipe['id'])[0]
                recipe_upstream_add = RecipeUpstream()
                recipe_upstream_add.history = recipe_upstream_history
                recipe_upstream_add.recipe = recipe_add
                recipe_upstream_add.version = ''
                recipe_upstream_add.type = 'M'  # Manual
                recipe_upstream_add.status = 'U'  # Unknown
                recipe_upstream_add.no_update_reason = ''
                recipe_upstream_add.date = recipe_upstream_history.end_date
                recipe_upstream_add.save()
                recipe_upstream = {
                    'version': '',
                    'status': 'U',
                    'type': 'M',
                    'no_update_reason': ''
                }

            if recipe_upstream['status'] == 'N' and recipe_upstream[
                    'no_update_reason']:
                recipe_upstream['status'] = 'C'
            upstream_status = \
                    RecipeUpstream.RECIPE_UPSTREAM_STATUS_CHOICES_DICT[
                        recipe_upstream['status']]
            if upstream_status == 'Downgrade':
                upstream_status = 'Unknown'  # Downgrade is displayed as Unknown
            upstream_version = recipe_upstream['version']
            no_update_reason = recipe_upstream['no_update_reason']

            #Get how long the recipe hasn't been updated
            recipe_last_updated = \
                recipe_last_updated_dict_all.get(recipe['id'])
            if recipe_last_updated:
                recipe_date = recipe_last_updated['date']
                outdated = recipe_date.date().isoformat()
            else:
                outdated = ""

        maintainer_name = maintainers_dict_all.get(recipe['id'], '')
        recipe_list_item = RecipeList(recipe['id'], recipe['pn'],
                                      recipe['summary'])
        recipe_list_item.version = recipe['version']
        recipe_list_item.upstream_status = upstream_status
        recipe_list_item.upstream_version = upstream_version
        recipe_list_item.outdated = outdated
        patches = Patch.objects.filter(recipe__id=recipe['id'])
        recipe_list_item.patches_total = patches.count()
        recipe_list_item.patches_pending = patches.filter(status='P').count()
        recipe_list_item.maintainer_name = maintainer_name
        recipe_list_item.no_update_reason = no_update_reason
        recipe_list.append(recipe_list_item)

    return recipe_list