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
Beispiel #2
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
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)
Beispiel #4
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