def get_upstream_info(layerbranch, recipe_data, result): from bb.utils import vercmp_string from oe.recipeutils import get_recipe_upstream_version, \ get_recipe_pv_without_srcpv pn = recipe_data.getVar('PN', True) recipes = Recipe.objects.filter(layerbranch=layerbranch, pn=pn) if not recipes: logger.warning("%s: in layer branch %s not found." % \ (pn, str(layerbranch))) return recipe = recipes[0] ru = RecipeUpstream() ru.recipe = recipe ru_info = None try: ru_info = get_recipe_upstream_version(recipe_data) except Exception as e: logger.exception("%s: in layer branch %s, %s" % (pn, str(layerbranch), str(e))) if ru_info is not None and ru_info['version']: ru.version = ru_info['version'] ru.type = ru_info['type'] ru.date = ru_info['datetime'] pv, _, _ = get_recipe_pv_without_srcpv(recipe.pv, get_pv_type(recipe.pv)) upv, _, _ = get_recipe_pv_without_srcpv( ru_info['version'], get_pv_type(ru_info['version'])) if pv and upv: cmp_ver = vercmp_string(pv, upv) if cmp_ver == -1: ru.status = 'N' # Not update elif cmp_ver == 0: ru.status = 'Y' # Up-to-date elif cmp_ver == 1: ru.status = 'D' # Downgrade, need to review why else: logger.debug( 'Unable to determine upgrade status for %s: %s -> %s' % (recipe.pn, pv, upv)) ru.status = 'U' # Unknown else: ru.version = '' ru.type = 'M' ru.date = datetime.now() ru.status = 'U' # Unknown ru.no_update_reason = recipe_data.getVar('RECIPE_NO_UPDATE_REASON', True) or '' result.append((recipe, ru))
def get_context_data(self, **kwargs): context = super(RecipeDetailView, self).get_context_data(**kwargs) recipe = self.get_object() if not recipe: raise django.http.Http404 maintplan = get_object_or_404(MaintenancePlan, name=self.maintplan_name) context['maintplan_name'] = maintplan.name context['maintplan'] = maintplan release = Release.get_current(maintplan) context['release_name'] = release.name milestone = Milestone.get_current(release) context['milestone_name'] = milestone.name context['upstream_status'] = '' context['upstream_version'] = '' context['upstream_no_update_reason'] = '' recipe_upstream_history = RecipeUpstreamHistory.get_last_by_date_range( recipe.layerbranch, milestone.start_date, milestone.end_date) if recipe_upstream_history: recipe_upstream = RecipeUpstream.get_by_recipe_and_history( recipe, recipe_upstream_history) if recipe_upstream: if recipe_upstream.status == 'N' and recipe_upstream.no_update_reason: recipe_upstream.status = 'C' elif recipe_upstream.status == 'D': recipe_upstream.status = 'U' context['upstream_status'] = \ RecipeUpstream.RECIPE_UPSTREAM_STATUS_CHOICES_DICT[recipe_upstream.status] context['upstream_version'] = recipe_upstream.version context[ 'upstream_no_update_reason'] = recipe_upstream.no_update_reason self.recipe_maintainer_history = RecipeMaintainerHistory.get_last( recipe.layerbranch) recipe_maintainer = RecipeMaintainer.objects.filter( recipe=recipe, history=self.recipe_maintainer_history) if recipe_maintainer: maintainer = recipe_maintainer[0].maintainer context['maintainer_name'] = maintainer.name else: context['maintainer_name'] = 'No maintainer' context['recipe_upgrade_details'] = [] for ru in RecipeUpgrade.objects.filter( recipe=recipe).order_by('-commit_date'): context['recipe_upgrade_details'].append( _get_recipe_upgrade_detail(maintplan, ru)) context['recipe_upgrade_detail_count'] = len( context['recipe_upgrade_details']) context['recipe_layer_branch_url'] = _get_layer_branch_url( recipe.layerbranch.branch.name, recipe.layerbranch.layer.name) context['recipe_provides'] = [] for p in recipe.provides.split(): context['recipe_provides'].append(p) context['recipe_depends'] = StaticBuildDep.objects.filter( recipes__id=recipe.id).values_list('name', flat=True) context['recipe_distros'] = RecipeDistro.get_distros_by_recipe(recipe) return context
def get_context_data(self, **kwargs): context = super(RecipeDetailView, self).get_context_data(**kwargs) recipesymbol = self.get_object() if not recipesymbol: raise django.http.Http404 recipe = recipesymbol.layerbranch.recipe_set.filter( pn=recipesymbol.pn, layerbranch=recipesymbol.layerbranch).last() context['recipe'] = recipe maintplan = get_object_or_404(MaintenancePlan, name=self.maintplan_name) context['maintplan_name'] = maintplan.name context['maintplan'] = maintplan release = Release.get_current(maintplan) context['release_name'] = release.name milestone = Milestone.get_current(release) context['milestone_name'] = milestone.name context['upstream_status'] = '' context['upstream_version'] = '' context['upstream_no_update_reason'] = '' recipe_upstream_history = RecipeUpstreamHistory.get_last_by_date_range( recipesymbol.layerbranch, milestone.start_date, milestone.end_date) if recipe_upstream_history: recipe_upstream = RecipeUpstream.get_by_recipe_and_history( recipesymbol, recipe_upstream_history) if recipe_upstream: if recipe_upstream.status == 'N' and recipe_upstream.no_update_reason: recipe_upstream.status = 'C' elif recipe_upstream.status == 'D': recipe_upstream.status = 'U' context['upstream_status'] = \ RecipeUpstream.RECIPE_UPSTREAM_STATUS_CHOICES_DICT[recipe_upstream.status] context['upstream_version'] = recipe_upstream.version context[ 'upstream_no_update_reason'] = recipe_upstream.no_update_reason self.recipe_maintainer_history = RecipeMaintainerHistory.get_last( recipesymbol.layerbranch) recipe_maintainer = RecipeMaintainer.objects.filter( recipesymbol=recipesymbol, history=self.recipe_maintainer_history) if recipe_maintainer: maintainer = recipe_maintainer[0].maintainer context['maintainer_name'] = maintainer.name else: context['maintainer_name'] = 'No maintainer' details = [] multigroup = False lastgroup = '' # can't use None here for ru in RecipeUpgrade.objects.filter( recipesymbol=recipesymbol).exclude(upgrade_type='M').order_by( 'group', '-commit_date', '-id'): details.append(_get_recipe_upgrade_detail(maintplan, ru)) if not multigroup: if lastgroup == '': lastgroup = ru.group elif ru.group != lastgroup: multigroup = True details.sort(key=lambda s: RecipeUpgradeGroupSortItem(s.group), reverse=True) context['multigroup'] = multigroup context['recipe_upgrade_details'] = details context['recipe_upgrade_detail_count'] = len(details) if not recipe: ru = RecipeUpgrade.objects.filter( recipesymbol=recipesymbol).order_by('-commit_date', '-id').first() if ru: context['last_filepath'] = ru.filepath context['recipe_layer_branch_url'] = _get_layer_branch_url( recipesymbol.layerbranch.branch.name, recipesymbol.layerbranch.layer.name) context['recipe_provides'] = [] if recipe: for p in recipe.provides.split(): context['recipe_provides'].append(p) context['recipe_depends'] = StaticBuildDep.objects.filter( recipes__id=recipe.id).values_list('name', flat=True) context['recipe_distros'] = RecipeDistro.get_distros_by_recipe( recipe) else: context['recipe_depends'] = [] context['recipe_distros'] = [] context['otherbranch_recipes'] = Recipe.objects.filter( layerbranch__layer=recipesymbol.layerbranch.layer, layerbranch__branch__comparison=False, pn=recipesymbol.pn).order_by('layerbranch__branch__sort_priority') return context
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
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