Example #1
0
    def fork_copr(cls, copr, user, dstname, dstgroup=None):
        forking = ProjectForking(user, dstgroup)
        created = (not bool(forking.get(copr, dstname)))
        fcopr = forking.fork_copr(copr, dstname)

        if fcopr.full_name == copr.full_name:
            raise exceptions.DuplicateException(
                "Source project should not be same as destination")

        builds_map = {}
        for package in copr.main_dir.packages:
            fpackage = forking.fork_package(package, fcopr)
            build = package.last_build(successful=True)
            if not build:
                continue

            fbuild = forking.fork_build(build, fcopr, fpackage)

            if build.result_dir:
                builds_map['srpm-builds'] = (build.result_dir,
                                             fbuild.result_dir)

            for chroot, fchroot in zip(build.build_chroots,
                                       fbuild.build_chroots):
                if chroot.result_dir:
                    builds_map[chroot.name] = (chroot.result_dir,
                                               fchroot.result_dir)

        db.session.commit()
        ActionsLogic.send_fork_copr(copr, fcopr, builds_map)
        return fcopr, created
Example #2
0
    def fork_copr(cls, copr, user, dstname, dstgroup=None):
        if dstgroup and not user.can_build_in_group(dstgroup):
            raise exceptions.InsufficientRightsException(
                "Only members may create projects in the particular groups.")

        fcopr = CoprsLogic.get_by_group_id(dstgroup.id, dstname).first() if dstgroup \
            else CoprsLogic.filter_without_group_projects(CoprsLogic.get(flask.g.user.name, dstname)).first()

        if fcopr:
            raise exceptions.DuplicateException("You already have {}/{} project".format(user.name, copr.name))

        # @TODO Move outside and properly test it
        def create_object(clazz, from_object, exclude=list()):
            arguments = {}
            for name, column in from_object.__mapper__.columns.items():
                if not name in exclude:
                    arguments[name] = getattr(from_object, name)
            return clazz(**arguments)

        fcopr = create_object(models.Copr, copr, exclude=["id", "group_id"])
        fcopr.forked_from_id = copr.id
        fcopr.owner = user
        fcopr.owner_id = user.id
        if dstname:
            fcopr.name = dstname
        if dstgroup:
            fcopr.group = dstgroup
            fcopr.group_id = dstgroup.id

        for chroot in list(copr.copr_chroots):
            CoprChrootsLogic.create_chroot(user, fcopr, chroot.mock_chroot, chroot.buildroot_pkgs,
                                           comps=chroot.comps, comps_name=chroot.comps_name)

        builds_map = {}
        for package in copr.packages:
            fpackage = create_object(models.Package, package, exclude=["id", "copr_id"])
            fpackage.copr = fcopr
            db.session.add(fpackage)

            build = package.last_build()
            if not build:
                continue

            fbuild = create_object(models.Build, build, exclude=["id", "copr_id", "package_id"])
            fbuild.copr = fcopr
            fbuild.package = fpackage
            fbuild.build_chroots = [create_object(models.BuildChroot, c, exclude=["id"]) for c in build.build_chroots]
            db.session.add(fbuild)
            builds_map[fbuild.id] = build.id

        ActionsLogic.send_fork_copr(copr, fcopr, builds_map)
        db.session.add(fcopr)
        return fcopr
Example #3
0
    def fork_copr(cls, copr, user, dstname, dstgroup=None):
        forking = ProjectForking(user, dstgroup)
        fcopr = forking.fork_copr(copr, dstname)
        created = fcopr in db.session.new

        if fcopr.full_name == copr.full_name:
            raise exceptions.DuplicateException("Source project should not be same as destination")

        builds_map = {}
        for package in copr.packages:
            fpackage = forking.fork_package(package, fcopr)
            build = package.last_build()
            if not build:
                continue

            fbuild = forking.fork_build(build, fcopr, fpackage)
            builds_map[fbuild.id] = build.result_dir_name

        ActionsLogic.send_fork_copr(copr, fcopr, builds_map)
        return fcopr, created
Example #4
0
    def fork_copr(cls, copr, user, dstname, dstgroup=None):
        forking = ProjectForking(user, dstgroup)
        created = (not bool(forking.get(copr, dstname)))
        fcopr = forking.fork_copr(copr, dstname)

        if fcopr.full_name == copr.full_name:
            raise exceptions.DuplicateException("Source project should not be same as destination")

        builds_map = {}
        for package in copr.packages:
            fpackage = forking.fork_package(package, fcopr)
            build = package.last_build()
            if not build:
                continue

            fbuild = forking.fork_build(build, fcopr, fpackage)
            builds_map[fbuild.id] = build.result_dir_name

        ActionsLogic.send_fork_copr(copr, fcopr, builds_map)
        return fcopr, created