Ejemplo n.º 1
0
    def run(self, cmdline, db):
        result = set()

        if len(cmdline.opsys) < 1:
            for osname, osplugin in systems.items():
                db_opsys = get_opsys_by_name(db, osplugin.nice_name)
                if db_opsys is None:
                    self.log_warn("Operating system '{0}' is not installed".format(osplugin.nice_name))
                    continue

                result.add((osplugin, db_opsys))
        else:
            for osname in cmdline.opsys:
                if osname not in systems:
                    self.log_warn("Operating system '{0}' is not supported".format(osname))
                    continue

                osplugin = systems[osname]
                db_opsys = get_opsys_by_name(db, osplugin.nice_name)
                if db_opsys is None:
                    self.log_warn("Operating system '{0}' is not installed".format(osplugin.nice_name))
                    continue

                result.add((osplugin, db_opsys))

        for osplugin, db_opsys in result:
            db_components = get_components_by_opsys(db, db_opsys)
            components = {}
            for db_component in db_components:
                components[db_component.name] = db_component

            i = 0
            db_builds = osplugin.get_build_candidates(db)
            for db_build in db_builds:
                i += 1

                self.log_info("[{0} / {1}] Processing '{2}'".format(i, len(db_builds), db_build.nevr()))

                comp_name = db_build.base_package_name
                if comp_name not in components:
                    self.log_debug(
                        "Component '{0}' not found in operating " "system '{1}'".format(comp_name, osplugin.nice_name)
                    )
                    continue

                db_component = components[comp_name]

                if any(db_component == bcomp.component for bcomp in db_build.components):
                    self.log_debug("Already assigned")
                    continue

                self.log_info("Assigning to component '{0}'".format(comp_name))
                db_buildcomponent = BuildComponent()
                db_buildcomponent.build = db_build
                db_buildcomponent.component = db_component
                db.session.add(db_buildcomponent)

            db.session.flush()
Ejemplo n.º 2
0
    def run(self, cmdline, db):
        if not cmdline.opsys:
            cmdline.opsys = list(systems.keys())

        opsyss = []
        for shortname in cmdline.opsys:
            if shortname not in systems:
                self.log_warn("Operating system '{0}' is not installed"
                              .format(shortname))
                continue

            opsys = systems[shortname]
            db_opsys = get_opsys_by_name(db, opsys.nice_name)
            if db_opsys is None:
                self.log_warn("Operating system '{0}' is not initialized"
                              .format(shortname))
                continue

            opsyss.append((opsys, db_opsys))

        new_associates = {}
        i = 0
        for (opsys, db_opsys) in opsyss:
            i += 1

            self.log_info("[{0} / {1}] Processing {2}"
                          .format(i, len(opsyss), opsys.nice_name))

            j = 0
            components = get_components_by_opsys(db, db_opsys).all()
            for db_component in components:
                j += 1

                name = db_component.name
                self.log_debug("  [{0} / {1}] Processing component '{2}'"
                               .format(j, len(components), name))
                try:
                    acls = opsys.get_component_acls(name)
                except TypeError:
                    self.log_warn("Error getting ACLs.")
                    continue

                acl_lists = {
                    "watchbugzilla": [],
                    "commit": []
                }

                for associate in acls:
                    for permission in acl_lists:
                        if acls[associate].get(permission, False):
                            acl_lists[permission].append(associate)

                for permission in acl_lists:
                    k = 0
                    for associate in acl_lists[permission]:
                        k += 1
                        self.log_debug("    [{0} / {1}] Processing associate '{2}' "
                                       "permission {3}"
                                       .format(k, len(acl_lists[permission]),
                                               associate, permission))

                        db_associate = get_associate_by_name(db, associate)
                        if db_associate is None:
                            if associate in new_associates:
                                db_associate = new_associates[associate]
                            else:
                                db_associate = AssociatePeople()
                                db_associate.name = associate
                                db.session.add(db_associate)
                                new_associates[associate] = db_associate

                                self.log_info("Adding a new associate '{0}'"
                                              .format(associate))

                        associates = [a.associates for a in db_component.associates
                                      if a.permission == permission]
                        if db_associate not in associates:
                            db_associate_comp = OpSysComponentAssociate()
                            db_associate_comp.component = db_component
                            db_associate_comp.associates = db_associate
                            db_associate_comp.permission = permission
                            db.session.add(db_associate_comp)

                            self.log_info("Assigning associate '{0}' to component "
                                          "'{1}' with permission {2}"
                                          .format(associate, name, permission))

                    for db_associate_comp in db_component.associates:
                        if (db_associate_comp.permission == permission
                                and db_associate_comp.associates.name not in acl_lists[permission]):
                            db.session.delete(db_associate_comp)
                            self.log_info("Removing associate '{0}' permission "
                                          "{1} from component '{2}'"
                                          .format(db_associate_comp.associates.name,
                                                  permission, name))

                db.session.flush()
Ejemplo n.º 3
0
    def run(self, cmdline, db) -> None:
        if not cmdline.opsys:
            cmdline.opsys = list(systems.keys())

        opsyss = []
        for shortname in cmdline.opsys:
            if shortname not in systems:
                self.log_warn("Operating system '{0}' is not installed".format(
                    shortname))
                continue

            opsys = systems[shortname]
            db_opsys = get_opsys_by_name(db, opsys.nice_name)
            if db_opsys is None:
                self.log_warn(
                    "Operating system '{0}' is not initialized".format(
                        shortname))
                continue

            opsyss.append((opsys, db_opsys))

        new_associates: Dict[str, AssociatePeople] = {}
        opsyss_len = len(opsyss)
        for i, (opsys, db_opsys) in enumerate(opsyss, start=1):
            self.log_info("[{0} / {1}] Processing {2}".format(
                i, opsyss_len, opsys.nice_name))

            components = get_components_by_opsys(db, db_opsys).all()
            components_len = len(components)
            for j, db_component in enumerate(components, start=1):
                name = db_component.name
                self.log_debug("\t[%d / %d] Processing component '%s'", j,
                               components_len, name)
                try:
                    acls = opsys.get_component_acls(name)
                except TypeError:
                    self.log_warn("Error getting ACLs.")
                    continue

                acl_lists: Dict[str, List[str]] = {
                    "watchbugzilla": [],
                    "commit": []
                }

                for associate_name, associate_perms in acls.items():
                    for permission, permission_members in acl_lists.items():
                        if associate_perms.get(permission, False):
                            permission_members.append(associate_name)

                for permission, permission_members in acl_lists.items():
                    acl_list_perm_len = len(permission_members)
                    for k, associate in enumerate(permission_members, start=1):
                        self.log_debug(
                            "\t[%d / %d] Processing associate '%s' permission %s",
                            k, acl_list_perm_len, associate, permission)

                        db_associate = get_associate_by_name(db, associate)
                        if db_associate is None:
                            if associate in new_associates:
                                db_associate = new_associates[associate]
                            else:
                                db_associate = AssociatePeople()
                                db_associate.name = associate
                                db.session.add(db_associate)
                                new_associates[associate] = db_associate

                                self.log_info(
                                    "Adding a new associate '{0}'".format(
                                        associate))

                        associates = [
                            a.associates for a in db_component.associates
                            if a.permission == permission
                        ]
                        if db_associate not in associates:
                            db_associate_comp = OpSysComponentAssociate()
                            db_associate_comp.component = db_component
                            db_associate_comp.associates = db_associate
                            db_associate_comp.permission = permission
                            db.session.add(db_associate_comp)

                            self.log_info(
                                "Assigning associate '{0}' to component "
                                "'{1}' with permission {2}".format(
                                    associate, name, permission))

                    for db_associate_comp in db_component.associates:
                        if (db_associate_comp.permission == permission
                                and db_associate_comp.associates.name
                                not in permission_members):
                            db.session.delete(db_associate_comp)
                            self.log_info(
                                "Removing associate '{0}' permission "
                                "{1} from component '{2}'".format(
                                    db_associate_comp.associates.name,
                                    permission, name))

                db.session.flush()
Ejemplo n.º 4
0
    def run(self, cmdline, db):
        result = set()

        if len(cmdline.opsys) < 1:
            for osname, osplugin in systems.items():
                db_opsys = get_opsys_by_name(db, osplugin.nice_name)
                if db_opsys is None:
                    self.log_warn(
                        "Operating system '{0}' is not installed".format(
                            osplugin.nice_name))
                    continue

                result.add((osplugin, db_opsys))
        else:
            for osname in cmdline.opsys:
                if osname not in systems:
                    self.log_warn(
                        "Operating system '{0}' is not supported".format(
                            osname))
                    continue

                osplugin = systems[osname]
                db_opsys = get_opsys_by_name(db, osplugin.nice_name)
                if db_opsys is None:
                    self.log_warn(
                        "Operating system '{0}' is not installed".format(
                            osplugin.nice_name))
                    continue

                result.add((osplugin, db_opsys))

        for osplugin, db_opsys in result:
            db_components = get_components_by_opsys(db, db_opsys)
            components = {}
            for db_component in db_components:
                components[db_component.name] = db_component

            i = 0
            db_builds = osplugin.get_build_candidates(db)
            for db_build in db_builds:
                i += 1

                self.log_info("[{0} / {1}] Processing '{2}'".format(
                    i, len(db_builds), db_build.nevr()))

                comp_name = db_build.base_package_name
                if comp_name not in components:
                    self.log_debug("Component '{0}' not found in operating "
                                   "system '{1}'".format(
                                       comp_name, osplugin.nice_name))
                    continue

                db_component = components[comp_name]

                if any(db_component == bcomp.component
                       for bcomp in db_build.components):
                    self.log_debug("Already assigned")
                    continue

                self.log_info("Assigning to component '{0}'".format(comp_name))
                db_buildcomponent = BuildComponent()
                db_buildcomponent.build = db_build
                db_buildcomponent.component = db_component
                db.session.add(db_buildcomponent)

            db.session.flush()
Ejemplo n.º 5
0
    def run(self, cmdline, db):
        if len(cmdline.opsys) == 0:
            cmdline.opsys = systems.keys()

        opsyss = []
        for shortname in cmdline.opsys:
            if shortname not in systems:
                self.log_warn("Operating system '{0}' is not installed".format(
                    shortname))
                continue

            opsys = systems[shortname]
            db_opsys = get_opsys_by_name(db, opsys.nice_name)
            if db_opsys is None:
                self.log_warn(
                    "Operating system '{0}' is not initialized".format(
                        shortname))
                continue

            opsyss.append((opsys, db_opsys))

        new_associates = {}
        i = 0
        for (opsys, db_opsys) in opsyss:
            i += 1

            self.log_info("[{0} / {1}] Processing {2}".format(
                i, len(opsyss), opsys.nice_name))

            j = 0
            components = get_components_by_opsys(db, db_opsys).all()
            for db_component in components:
                j += 1

                name = db_component.name
                self.log_debug(
                    "  [{0} / {1}] Processing component '{2}'".format(
                        j, len(components), name))
                try:
                    acls = opsys.get_component_acls(name)
                except TypeError:
                    self.log_warn("Error getting ACLs.")
                    continue

                acl_lists = {"watchbugzilla": [], "commit": []}

                for associate in acls.keys():
                    for permission in acl_lists.keys():
                        if acls[associate].get(permission, False):
                            acl_lists[permission].append(associate)

                for permission in acl_lists.keys():
                    k = 0
                    for associate in acl_lists[permission]:
                        k += 1
                        self.log_debug(
                            "    [{0} / {1}] Processing associate '{2}' "
                            "permission {3}".format(k,
                                                    len(acl_lists[permission]),
                                                    associate, permission))

                        db_associate = get_associate_by_name(db, associate)
                        if db_associate is None:
                            if associate in new_associates:
                                db_associate = new_associates[associate]
                            else:
                                db_associate = AssociatePeople()
                                db_associate.name = associate
                                db.session.add(db_associate)
                                new_associates[associate] = db_associate

                                self.log_info(
                                    "Adding a new associate '{0}'".format(
                                        associate))

                        associates = [
                            a.associates for a in db_component.associates
                            if a.permission == permission
                        ]
                        if db_associate not in associates:
                            db_associate_comp = OpSysComponentAssociate()
                            db_associate_comp.component = db_component
                            db_associate_comp.associates = db_associate
                            db_associate_comp.permission = permission
                            db.session.add(db_associate_comp)

                            self.log_info(
                                "Assigning associate '{0}' to component "
                                "'{1}' with permission {2}".format(
                                    associate, name, permission))

                    for db_associate_comp in db_component.associates:
                        if (db_associate_comp.permission == permission
                                and db_associate_comp.associates.name
                                not in acl_lists[permission]):
                            db.session.delete(db_associate_comp)
                            self.log_info(
                                "Removing associate '{0}' permission "
                                "{1} from component '{2}'".format(
                                    db_associate_comp.associates.name,
                                    permission, name))

                db.session.flush()