Example #1
0
    def get_queryset(self):
        self.maintplan_name = self.kwargs['maintplan_name']
        maintplan = get_object_or_404(MaintenancePlan,
                                      name=self.maintplan_name)
        self.release_name = self.kwargs['release_name']
        release = get_object_or_404(Release,
                                    plan=maintplan,
                                    name=self.release_name)

        self.milestone_name = self.kwargs['milestone_name']
        milestone = get_object_or_404(Milestone,
                                      release=release,
                                      name=self.milestone_name)

        if 'upstream_status' in self.request.GET.keys():
            self.upstream_status = self.request.GET['upstream_status']
        else:
            self.upstream_status = 'All'

        if 'maintainer_name' in self.request.GET.keys():
            self.maintainer_name = self.request.GET['maintainer_name']
        else:
            self.maintainer_name = 'All'

        if 'search' in self.request.GET.keys():
            self.search = self.request.GET['search']

            # only allow one type of filter search or upstream_status/maintainer
            self.upstream_status = 'All'
            self.maintainer_name = 'All'
        else:
            self.search = ''

        _check_url_params(self.upstream_status, self.maintainer_name)

        self.milestone_statistics = _get_milestone_statistics(milestone)

        self.recipe_maintainer_history = {}
        for maintplanlayer in maintplan.maintenanceplanlayerbranch_set.all():
            layerbranch = maintplanlayer.layerbranch
            self.recipe_maintainer_history[
                layerbranch.id] = RecipeMaintainerHistory.get_by_end_date(
                    layerbranch, milestone.end_date)

        recipe_list = _get_recipe_list(milestone)
        self.recipe_list_count = len(recipe_list)

        return recipe_list
Example #2
0
def _get_recipe_upgrade_detail(maintplan, recipe_upgrade):
    release_name = ''
    milestone_name = ''
    recipe_maintainer_history = None

    release = Release.get_by_date(maintplan, recipe_upgrade.commit_date)
    if release:
        release_name = release.name
        milestone = Milestone.get_by_release_and_date(
            release, recipe_upgrade.commit_date)
        if milestone:
            milestone_name = milestone.name
            recipe_maintainer_history = RecipeMaintainerHistory.get_by_end_date(
                recipe_upgrade.recipesymbol.layerbranch, milestone.end_date)

    is_recipe_maintainer = False
    maintainer_name = ''
    if not recipe_upgrade.maintainer is None:
        maintainer_name = recipe_upgrade.maintainer.name

        if not recipe_maintainer_history is None and \
            RecipeMaintainer.objects.filter(maintainer__name
            = maintainer_name, history = recipe_maintainer_history) \
            .count() > 0:
            is_recipe_maintainer = True

    commit_date = recipe_upgrade.commit_date.date().isoformat()
    commit = recipe_upgrade.sha1[:10]
    commit_url = recipe_upgrade.recipesymbol.layerbranch.commit_url(
        recipe_upgrade.sha1)

    rud = RecipeUpgradeDetail(recipe_upgrade.title, recipe_upgrade.version, \
            maintplan.name, release_name, milestone_name, commit_date, maintainer_name, \
            is_recipe_maintainer, commit, commit_url, recipe_upgrade.upgrade_type, \
            recipe_upgrade.group)

    return rud
def maintainers_inc_history(options, logger, maintplan, layerbranch, repodir,
                            layerdir):
    maintainers_full_path = os.path.join(layerdir, MAINTAINERS_INCLUDE_PATH)
    if not os.path.exists(maintainers_full_path):
        logger.warning(
            'Maintainer style is maintainers.inc for plan %s but no maintainers.inc exists in for %s'
            % (maintplan, layerbranch))
        return

    logger.debug('Checking maintainers.inc history for %s' % layerbranch)

    commits = utils.runcmd(
        "git log --format='%%H' --reverse --date=rfc origin/master %s" %
        os.path.join(layerbranch.vcs_subdir, MAINTAINERS_INCLUDE_PATH),
        repodir,
        logger=logger)

    no_maintainer, _ = Maintainer.objects.get_or_create(name='No maintainer')

    try:
        with transaction.atomic():
            for commit in commits.strip().split("\n"):
                if RecipeMaintainerHistory.objects.filter(
                        layerbranch=layerbranch, sha1=commit):
                    continue

                logger.debug("Analysing commit %s ..." % (commit))

                (author_name, author_email, date, title) = \
                    get_commit_info(utils.runcmd("git show " + commit, repodir,
                        logger=logger), logger)

                author = Maintainer.create_or_update(author_name, author_email)
                rms = RecipeMaintainerHistory(title=title,
                                              date=date,
                                              author=author,
                                              sha1=commit,
                                              layerbranch=layerbranch)
                rms.save()

                utils.runcmd("git checkout %s -f" % commit,
                             repodir,
                             logger=logger)

                lines = [line.strip() for line in open(maintainers_full_path)]
                for line in lines:
                    res = get_recipe_maintainer(line, logger)
                    if res:
                        (pn, name, email) = res
                        qry = Recipe.objects.filter(pn=pn,
                                                    layerbranch=layerbranch)

                        if qry:
                            m = Maintainer.create_or_update(name, email)

                            rm = RecipeMaintainer()
                            rm.recipe = qry[0]
                            rm.maintainer = m
                            rm.history = rms
                            rm.save()

                            logger.debug("%s: Change maintainer to %s in commit %s." % \
                                    (pn, m.name, commit))
                        else:
                            logger.debug("%s: Not found in %s." % \
                                    (pn, layerbranch))

                # set missing recipes to no maintainer
                for recipe in layerbranch.recipe_set.all():
                    if not RecipeMaintainer.objects.filter(recipe=recipe,
                                                           history=rms):
                        rm = RecipeMaintainer()
                        rm.recipe = recipe
                        link_maintainer = RecipeMaintenanceLink.link_maintainer(
                            recipe.pn, rms)
                        if link_maintainer:
                            rm.maintainer = link_maintainer.maintainer
                        else:
                            rm.maintainer = no_maintainer
                        rm.history = rms
                        rm.save()
                        if link_maintainer:
                            logger.debug(
                                "%s: linked to maintainer for %s" %
                                (recipe.pn, link_maintainer.recipe.pn))
                        else:
                            logger.debug("%s: Not found maintainer in commit %s set to 'No maintainer'." % \
                                            (recipe.pn, rms.sha1))

            # set new recipes to no maintainer if don't have one
            rms = RecipeMaintainerHistory.get_last(layerbranch)
            for recipe in layerbranch.recipe_set.all():
                if not RecipeMaintainer.objects.filter(recipe=recipe,
                                                       history=rms):
                    rm = RecipeMaintainer()
                    rm.recipe = recipe
                    link_maintainer = RecipeMaintenanceLink.link_maintainer(
                        recipe.pn, rms)
                    if link_maintainer:
                        rm.maintainer = link_maintainer.maintainer
                    else:
                        rm.maintainer = no_maintainer
                    rm.history = rms
                    rm.save()
                    if link_maintainer:
                        logger.debug(
                            "%s: New recipe linked to maintainer for %s" %
                            (recipe.pn, link_maintainer.recipe.pn))
                    else:
                        logger.debug("%s: New recipe not found maintainer set to 'No maintainer'." % \
                                    (recipe.pn))
        if options.dry_run:
            raise DryRunRollbackException
    except DryRunRollbackException:
        pass
def main():
    parser = optparse.OptionParser(usage="""
    %prog [options]""")

    parser.add_option(
        "-p",
        "--plan",
        help=
        "Specify maintenance plan to operate on (default is all plans that have updates enabled)",
        action="store",
        dest="plan",
        default=None)

    parser.add_option("-s",
                      "--subject",
                      action="store",
                      dest="subject",
                      help='Override email subject')
    parser.add_option("-f",
                      "--from",
                      action="store",
                      dest="_from",
                      help='Override sender address')
    parser.add_option("-t",
                      "--to",
                      action="store",
                      dest="to",
                      help='Override recipient address')
    parser.add_option("-d",
                      "--debug",
                      help="Enable debug output",
                      action="store_const",
                      const=logging.DEBUG,
                      dest="loglevel",
                      default=logging.INFO)
    parser.add_option("-q",
                      "--quiet",
                      help="Hide all output except error messages",
                      action="store_const",
                      const=logging.ERROR,
                      dest="loglevel")

    options, args = parser.parse_args(sys.argv)
    logger.setLevel(options.loglevel)

    # get recipes for send email
    if options.plan:
        maintplans = MaintenancePlan.objects.filter(id=int(options.plan))
        if not maintplans.exists():
            logger.error('No maintenance plan with ID %s found' % options.plan)
            sys.exit(1)
    else:
        maintplans = MaintenancePlan.objects.filter(email_enabled=True)
        if not maintplans.exists():
            logger.error('No maintenance plans with email enabled were found')
            sys.exit(1)

    for maintplan in maintplans:
        recipes = {}
        for item in maintplan.maintenanceplanlayerbranch_set.all():
            layerbranch = item.layerbranch

            recipe_upstream_history = RecipeUpstreamHistory.get_last(
                layerbranch)
            if recipe_upstream_history is None:
                logger.warn(
                    'I don\'t have Upstream information yet, run update.py script'
                )
                sys.exit(1)

            recipe_maintainer_history = RecipeMaintainerHistory.get_last(
                layerbranch)
            if recipe_maintainer_history is None:
                logger.warn('I don\'t have Maintainership information yet,' +
                            ' run rrs_maintainer_history.py script')
                sys.exit(1)

            for recipe in layerbranch.recipe_set.all():
                recipe_upstream_query = RecipeUpstream.objects.filter(
                    recipe=recipe, history=recipe_upstream_history)
                if recipe_upstream_query and recipe_upstream_query[
                        0].status == 'N':
                    recipes[recipe] = {}

                    recipe_maintainer = RecipeMaintainer.objects.filter(
                        recipe=recipe, history=recipe_maintainer_history)[0]
                    recipes[recipe]['maintainer'] = recipe_maintainer
                    recipes[recipe]['upstream'] = recipe_upstream_query[0]

        send_email(maintplan, recipes, options)
Example #5
0
    def get_queryset(self):
        maintainer_list = []
        self.maintainer_count = 0

        self.maintplan_name = self.kwargs['maintplan_name']
        maintplan = get_object_or_404(MaintenancePlan,
                                      name=self.maintplan_name)
        self.release_name = self.kwargs['release_name']
        release = get_object_or_404(Release,
                                    plan=maintplan,
                                    name=self.release_name)
        self.milestone_name = self.kwargs['milestone_name']
        milestone = get_object_or_404(Milestone,
                                      release=release,
                                      name=self.milestone_name)

        if "All" in milestone.name:
            intervals = milestone.get_milestone_intervals(release)
            interval_type = 'Milestone'
        else:
            intervals = milestone.get_week_intervals()
            interval_type = 'Week'

        self.milestone_statistics = _get_milestone_statistics(milestone)

        self.maintainer_count = 0
        for maintplanlayer in maintplan.maintenanceplanlayerbranch_set.all():
            layerbranch = maintplanlayer.layerbranch

            recipe_maintainer_history = RecipeMaintainerHistory.get_by_end_date(
                layerbranch, milestone.end_date)

            if recipe_maintainer_history:
                for rm in RecipeMaintainer.objects.filter(
                        history=recipe_maintainer_history).values(
                            'maintainer__name').distinct().order_by(
                                'maintainer__name'):
                    maintainer_list.append(
                        MaintainerList(rm['maintainer__name']))

                self.maintainer_count += len(maintainer_list)

        self.intervals = sorted(intervals.keys())
        current_date = date.today()
        for ml in maintainer_list:
            milestone_statistics = _get_milestone_statistics(
                milestone, ml.name)
            ml.recipes_all = milestone_statistics['all']
            ml.recipes_up_to_date = (''
                                     if milestone_statistics['up_to_date'] == 0
                                     else milestone_statistics['up_to_date'])
            ml.recipes_not_updated = ('' if milestone_statistics['not_updated']
                                      == 0 else
                                      milestone_statistics['not_updated'])
            ml.recipes_cant_be_updated = (
                '' if milestone_statistics['cant_be_updated'] == 0 else
                milestone_statistics['cant_be_updated'])
            ml.recipes_unknown = ('' if milestone_statistics['unknown'] == 0
                                  else milestone_statistics['unknown'])
            ml.percentage_done = milestone_statistics['percentage'] + '%'

            ml.interval_statistics = []
            self.current_interval = -1
            for idx, i in enumerate(sorted(intervals.keys())):
                start_date = intervals[i]['start_date']
                end_date = intervals[i]['end_date']

                if current_date >= start_date and current_date <= end_date:
                    self.current_interval = idx

                number = RecipeUpgrade.objects.filter(
                    maintainer__name=ml.name,
                    commit_date__gte=start_date,
                    commit_date__lte=end_date).count()
                ml.interval_statistics.append('' if number == 0 else number)

        # To add Wk prefix after get statics to avoid sorting problems
        if interval_type == 'Week':
            self.intervals = ['Wk' + str(i) for i in self.intervals]

        return maintainer_list
Example #6
0
    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
Example #7
0
    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