~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/model/binarypackagebuild.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2012-01-01 12:03:28 UTC
  • mfrom: (14612.3.1 feeds-stories)
  • Revision ID: launchpad@pqm.canonical.com-20120101120328-4nypd4mqnjzk62a7
[r=wgrant][no-qa] Move feeds stories from lp.services.session to
        lp.services.feeds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
433
433
                "It is expected to be a tuple containing only another "
434
434
                "tuple with 3 elements  (name, version, relation)."
435
435
                % (token, self.title, self.id, self.dependencies))
436
 
        # Map relations to the canonical form used in control files.
437
 
        if relation == '<':
438
 
            relation = '<<'
439
 
        elif relation == '>':
440
 
            relation = '>>'
441
436
        return (name, version, relation)
442
437
 
443
438
    def _checkDependencyVersion(self, available, required, relation):
444
439
        """Return True if the available version satisfies the context."""
445
440
        # This dict maps the package version relationship syntax in lambda
446
441
        # functions which returns boolean according the results of
447
 
        # apt_pkg.version_compare function (see the order above).
 
442
        # apt_pkg.VersionCompare function (see the order above).
448
443
        # For further information about pkg relationship syntax see:
449
444
        #
450
445
        # http://www.debian.org/doc/debian-policy/ch-relationships.html
452
447
        version_relation_map = {
453
448
            # any version is acceptable if no relationship is given
454
449
            '': lambda x: True,
455
 
            # strictly later
 
450
            # stricly later
456
451
            '>>': lambda x: x == 1,
457
452
            # later or equal
458
453
            '>=': lambda x: x >= 0,
459
 
            # strictly equal
 
454
            # stricly equal
460
455
            '=': lambda x: x == 0,
461
456
            # earlier or equal
462
457
            '<=': lambda x: x <= 0,
468
463
        # it behaves similar to cmp, i.e. returns negative
469
464
        # if first < second, zero if first == second and
470
465
        # positive if first > second.
471
 
        dep_result = apt_pkg.version_compare(available, required)
 
466
        dep_result = apt_pkg.VersionCompare(available, required)
472
467
 
473
468
        return version_relation_map[relation](dep_result)
474
469
 
505
500
    def updateDependencies(self):
506
501
        """See `IBuild`."""
507
502
 
508
 
        # apt_pkg requires init_system to get version_compare working
509
 
        # properly.
510
 
        apt_pkg.init_system()
 
503
        # apt_pkg requires InitSystem to get VersionCompare working properly.
 
504
        apt_pkg.InitSystem()
511
505
 
512
506
        # Check package build dependencies using apt_pkg
513
507
        try:
514
 
            parsed_deps = apt_pkg.parse_depends(self.dependencies)
 
508
            parsed_deps = apt_pkg.ParseDepends(self.dependencies)
515
509
        except (ValueError, TypeError):
516
510
            raise UnparsableDependencies(
517
511
                "Build dependencies for %s (%s) could not be parsed: '%s'\n"
871
865
            return None
872
866
        return resulting_tuple[0]
873
867
 
874
 
    def preloadBuildsData(self, builds):
875
 
        # Circular imports.
876
 
        from lp.soyuz.model.distroarchseries import (
877
 
            DistroArchSeries
878
 
            )
879
 
        from lp.registry.model.distroseries import (
880
 
            DistroSeries
881
 
            )
882
 
        from lp.registry.model.distribution import (
883
 
            Distribution
884
 
            )
885
 
        from lp.soyuz.model.archive import Archive
886
 
        from lp.registry.model.person import Person
887
 
        self._prefetchBuildData(builds)
888
 
        distro_arch_series = load_related(
889
 
            DistroArchSeries, builds, ['distro_arch_series_id'])
890
 
        package_builds = load_related(
891
 
            PackageBuild, builds, ['package_build_id'])
892
 
        archives = load_related(Archive, package_builds, ['archive_id'])
893
 
        load_related(Person, archives, ['ownerID'])
894
 
        distroseries = load_related(
895
 
            DistroSeries, distro_arch_series, ['distroseriesID'])
896
 
        load_related(
897
 
            Distribution, distroseries, ['distributionID'])
898
 
 
899
868
    def getByBuildFarmJobs(self, build_farm_jobs):
900
869
        """See `ISpecificBuildFarmJobSource`."""
901
870
        if len(build_farm_jobs) == 0:
904
873
        build_farm_job_ids = [
905
874
            build_farm_job.id for build_farm_job in build_farm_jobs]
906
875
 
 
876
        def eager_load(rows):
 
877
            # Circular imports.
 
878
            from lp.soyuz.model.distroarchseries import (
 
879
                DistroArchSeries
 
880
                )
 
881
            from lp.registry.model.distroseries import (
 
882
                DistroSeries
 
883
                )
 
884
            from lp.registry.model.distribution import (
 
885
                Distribution
 
886
                )
 
887
            from lp.soyuz.model.archive import Archive
 
888
            from lp.registry.model.person import Person
 
889
            self._prefetchBuildData(rows)
 
890
            distro_arch_series = load_related(
 
891
                DistroArchSeries, rows, ['distro_arch_series_id'])
 
892
            package_builds = load_related(
 
893
                PackageBuild, rows, ['package_build_id'])
 
894
            archives = load_related(Archive, package_builds, ['archive_id'])
 
895
            load_related(Person, archives, ['ownerID'])
 
896
            distroseries = load_related(
 
897
                DistroSeries, distro_arch_series, ['distroseriesID'])
 
898
            load_related(
 
899
                Distribution, distroseries, ['distributionID'])
907
900
        resultset = Store.of(build_farm_jobs[0]).using(*clause_tables).find(
908
901
            BinaryPackageBuild,
909
902
            BinaryPackageBuild.package_build == PackageBuild.id,
910
903
            PackageBuild.build_farm_job == BuildFarmJob.id,
911
904
            BuildFarmJob.id.is_in(build_farm_job_ids))
912
 
        return DecoratedResultSet(
913
 
            resultset, pre_iter_hook=self.preloadBuildsData)
 
905
        return DecoratedResultSet(resultset, pre_iter_hook=eager_load)
914
906
 
915
907
    def getPendingBuildsForArchSet(self, archseries):
916
908
        """See `IBinaryPackageBuildSet`."""