Ejemplo n.º 1
0
    def main(self):
        series = self._getTargetSeries()

        # Both translation UI and imports for this series should be blocked
        # while the copy is in progress, to reduce the chances of deadlocks or
        # other conflicts.
        blocked = (series.hide_all_translations
                   and series.defer_translation_imports)
        if not blocked and not self.options.force:
            self.txn.abort()
            self.logger.error(
                'Before this process starts, set the '
                'hide_all_translations and defer_translation_imports '
                'flags for distribution %s, series %s; or use the '
                '--force option to make it happen automatically.' %
                (self.options.distro, self.options.series))
            sys.exit(1)

        self.logger.info('Starting...')

        # Actual work is done here.
        copy_distroseries_translations(series, self.txn, self.logger)

        # We would like to update the DistroRelase statistics, but it takes
        # too long so this should be done after.
        #
        # Finally, we changed many things related with cached statistics, so
        # we may want to update those.
        # self.logger.info('Updating DistroSeries statistics...')
        # series.updateStatistics(self.txn)

        self.txn.commit()
        self.logger.info('Done.')
    def main(self):
        series = self._getTargetSeries()

        # Both translation UI and imports for this series should be blocked
        # while the copy is in progress, to reduce the chances of deadlocks or
        # other conflicts.
        blocked = (
            series.hide_all_translations and series.defer_translation_imports)
        if not blocked and not self.options.force:
            self.txn.abort()
            self.logger.error(
                'Before this process starts, set the '
                'hide_all_translations and defer_translation_imports '
                'flags for distribution %s, series %s; or use the '
                '--force option to make it happen automatically.' % (
                    self.options.distro, self.options.series))
            sys.exit(1)

        self.logger.info('Starting...')

        # Actual work is done here.
        copy_distroseries_translations(series, self.txn, self.logger)

        # We would like to update the DistroRelase statistics, but it takes
        # too long so this should be done after.
        #
        # Finally, we changed many things related with cached statistics, so
        # we may want to update those.
        # self.logger.info('Updating DistroSeries statistics...')
        # series.updateStatistics(self.txn)

        self.txn.commit()
        self.logger.info('Done.')
    def test_published_packages_only_different_archive(self):
        # If an archive parameter is passed,
        # copy_distroseries_translations's published_sources_only flag
        # checks source package publications in that archive rather than in
        # the target's main archive.
        distro = self.factory.makeDistribution(name='notbuntu')
        dapper = self.factory.makeDistroSeries(distribution=distro,
                                               name='dapper')
        spns = [self.factory.makeSourcePackageName() for i in range(3)]
        for spn in spns:
            self.factory.makePOTemplate(distroseries=dapper,
                                        sourcepackagename=spn)
        ppa = self.factory.makeArchive(purpose=ArchivePurpose.PPA)

        def get_template_spns(series):
            return [
                pot.sourcepackagename
                for pot in getUtility(IPOTemplateSet).getSubset(
                    distroseries=series)
            ]

        edgy = self.factory.makeDistroSeries(distribution=distro, name='edgy')
        edgy_derived = self.factory.makeDistroSeries(
            distribution=ppa.distribution, name='edgy-derived')
        self.factory.makeSourcePackagePublishingHistory(
            archive=ppa,
            distroseries=edgy_derived,
            sourcepackagename=spns[0],
            status=PackagePublishingStatus.PUBLISHED)
        self.factory.makeSourcePackagePublishingHistory(
            archive=edgy.main_archive,
            distroseries=edgy,
            sourcepackagename=spns[1],
            status=PackagePublishingStatus.PUBLISHED)
        self.factory.makeSourcePackagePublishingHistory(
            archive=ppa,
            distroseries=edgy_derived,
            sourcepackagename=spns[2],
            status=PackagePublishingStatus.PENDING)

        self.assertContentEqual(spns, get_template_spns(dapper))
        self.assertContentEqual([], get_template_spns(edgy))
        copy_distroseries_translations(dapper,
                                       edgy,
                                       self.txn,
                                       logging,
                                       published_sources_only=True,
                                       check_archive=ppa,
                                       check_distroseries=edgy_derived)
        self.assertContentEqual([spns[0], spns[2]], get_template_spns(edgy))
    def test_flagsHandling(self):
        """Flags are correctly restored, no matter what their values."""
        sid = getUtility(IDistributionSet)['debian']['sid']
        source = sid.previous_series

        sid.hide_all_translations = True
        sid.defer_translation_imports = True
        copy_distroseries_translations(source, sid, self.txn, logging)
        self.assertTrue(sid.hide_all_translations)
        self.assertTrue(sid.defer_translation_imports)

        sid.hide_all_translations = True
        sid.defer_translation_imports = False
        copy_distroseries_translations(source, sid, self.txn, logging)
        self.assertTrue(sid.hide_all_translations)
        self.assertFalse(sid.defer_translation_imports)

        sid.hide_all_translations = False
        sid.defer_translation_imports = True
        copy_distroseries_translations(source, sid, self.txn, logging)
        self.assertFalse(sid.hide_all_translations)
        self.assertTrue(sid.defer_translation_imports)

        sid.hide_all_translations = False
        sid.defer_translation_imports = False
        copy_distroseries_translations(source, sid, self.txn, logging)
        self.assertFalse(sid.hide_all_translations)
        self.assertFalse(sid.defer_translation_imports)
    def test_flagsHandling(self):
        """Flags are correctly restored, no matter what their values."""
        sid = getUtility(IDistributionSet)["debian"]["sid"]

        sid.hide_all_translations = True
        sid.defer_translation_imports = True
        copy_distroseries_translations(sid, self.txn, logging)
        self.assertTrue(sid.hide_all_translations)
        self.assertTrue(sid.defer_translation_imports)

        sid.hide_all_translations = True
        sid.defer_translation_imports = False
        copy_distroseries_translations(sid, self.txn, logging)
        self.assertTrue(sid.hide_all_translations)
        self.assertFalse(sid.defer_translation_imports)

        sid.hide_all_translations = False
        sid.defer_translation_imports = True
        copy_distroseries_translations(sid, self.txn, logging)
        self.assertFalse(sid.hide_all_translations)
        self.assertTrue(sid.defer_translation_imports)

        sid.hide_all_translations = False
        sid.defer_translation_imports = False
        copy_distroseries_translations(sid, self.txn, logging)
        self.assertFalse(sid.hide_all_translations)
        self.assertFalse(sid.defer_translation_imports)
    def test_published_packages_only(self):
        # copy_distroseries_translations's published_sources_only flag
        # restricts the copied templates to those with a corresponding
        # published source package in the target.
        distro = self.factory.makeDistribution(name='notbuntu')
        dapper = self.factory.makeDistroSeries(distribution=distro,
                                               name='dapper')
        spns = [self.factory.makeSourcePackageName() for i in range(3)]
        for spn in spns:
            self.factory.makePOTemplate(distroseries=dapper,
                                        sourcepackagename=spn)

        def get_template_spns(series):
            return [
                pot.sourcepackagename
                for pot in getUtility(IPOTemplateSet).getSubset(
                    distroseries=series)
            ]

        # Create a fresh series with two sources published.
        edgy = self.factory.makeDistroSeries(distribution=distro, name='edgy')
        self.factory.makeSourcePackagePublishingHistory(
            archive=edgy.main_archive,
            distroseries=edgy,
            sourcepackagename=spns[0],
            status=PackagePublishingStatus.PUBLISHED)
        self.factory.makeSourcePackagePublishingHistory(
            archive=edgy.main_archive,
            distroseries=edgy,
            sourcepackagename=spns[2],
            status=PackagePublishingStatus.PENDING)

        self.assertContentEqual(spns, get_template_spns(dapper))
        self.assertContentEqual([], get_template_spns(edgy))
        copy_distroseries_translations(dapper,
                                       edgy,
                                       self.txn,
                                       logging,
                                       published_sources_only=True)
        self.assertContentEqual([spns[0], spns[2]], get_template_spns(edgy))
Ejemplo n.º 7
0
    def main(self):
        target = getUtility(IDistributionSet)[self.options.distro][
            self.options.series]
        if self.options.from_distro:
            source = getUtility(IDistributionSet)[self.options.from_distro][
                self.options.from_series]
        else:
            source = target.previous_series
        if source is None:
            self.parser.error(
                "No source series specified and target has no previous "
                "series.")
        if self.options.check_archive is not None:
            check_archive = getUtility(IArchiveSet).getByReference(
                self.options.check_archive)
        else:
            check_archive = target.main_archive
        check_distribution = check_archive.distribution
        if self.options.check_distroseries is not None:
            check_distroseries = check_distribution[
                self.options.check_distroseries]
        else:
            check_distroseries = check_distribution[self.options.series]

        # Both translation UI and imports for this series should be blocked
        # while the copy is in progress, to reduce the chances of deadlocks or
        # other conflicts.
        blocked = (target.hide_all_translations
                   and target.defer_translation_imports)
        if not blocked and not self.options.force:
            self.txn.abort()
            self.logger.error(
                'Before this process starts, set the '
                'hide_all_translations and defer_translation_imports '
                'flags for distribution %s, series %s; or use the '
                '--force option to make it happen automatically.' %
                (self.options.distro, self.options.series))
            sys.exit(1)

        self.logger.info('Starting...')

        # Actual work is done here.
        copy_distroseries_translations(
            source,
            target,
            self.txn,
            self.logger,
            published_sources_only=self.options.published_sources_only,
            check_archive=check_archive,
            check_distroseries=check_distroseries,
            skip_duplicates=self.options.skip_duplicates)

        # We would like to update the DistroRelase statistics, but it takes
        # too long so this should be done after.
        #
        # Finally, we changed many things related with cached statistics, so
        # we may want to update those.
        # self.logger.info('Updating DistroSeries statistics...')
        # series.updateStatistics(self.txn)

        self.txn.commit()
        self.logger.info('Done.')