Exemple #1
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()
Exemple #2
0
def maintainer_default():
    if g.user is not None:
        associate = get_associate_by_name(db, g.user.username)
        if associate is not None:
            return associate
Exemple #3
0
    def run(self, cmdline, db):
        if len(cmdline.opsys) == 0:
            tasks = []
            for opsys in systems.values():
                releases = get_releases(db, opsys_name=opsys.nice_name)
                tasks += [(opsys, release) for release in releases if
                          release.status != "EOL"]
        elif len(cmdline.opsys) == 1:
            shortname = cmdline.opsys[0]
            if shortname not in systems:
                self.log_error("Operating system '{0}' is not installed"
                               .format(shortname))
                return 1

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

            if len(cmdline.opsys_release) < 1:
                tasks = [(opsys, r) for r in db_opsys.releases]
            else:
                tasks = [(opsys, r) for r in db_opsys.releases
                         if r.version in cmdline.opsys_release]
        else:
            tasks = []
            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

                tasks += [(opsys, rel) for rel in db_opsys.releases]

        new_associates = {}
        i = 0
        for opsys, db_release in tasks:
            i += 1

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

            j = 0
            for db_component in db_release.components:
                j += 1

                name = db_component.component.name
                self.log_debug("  [{0} / {1}] Processing component '{2}'"
                               .format(j, len(db_release.components), name))

                acls = opsys.get_component_acls(name,
                                                release=db_release.version)
                k = 0
                for associate in acls:
                    k += 1
                    self.log_debug("    [{0} / {1}] Processing associate '{2}'"
                                   .format(k, len(acls), associate))

                    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 db_associate not in associates:
                        db_associate_comp = OpSysReleaseComponentAssociate()
                        db_associate_comp.component = db_component
                        db_associate_comp.associates = db_associate
                        db.session.add(db_associate_comp)

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

                db.session.flush()
Exemple #4
0
    def run(self, cmdline, db):
        if len(cmdline.opsys) == 0:
            tasks = []
            for opsys in systems.values():
                releases = get_releases(db, opsys_name=opsys.nice_name)
                tasks += [(opsys, release) for release in releases
                          if release.status != "EOL"]
        elif len(cmdline.opsys) == 1:
            shortname = cmdline.opsys[0]
            if shortname not in systems:
                self.log_error(
                    "Operating system '{0}' is not installed".format(
                        shortname))
                return 1

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

            if len(cmdline.opsys_release) < 1:
                tasks = [(opsys, r) for r in db_opsys.releases]
            else:
                tasks = [(opsys, r) for r in db_opsys.releases
                         if r.version in cmdline.opsys_release]
        else:
            tasks = []
            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

                tasks += [(opsys, rel) for rel in db_opsys.releases]

        new_associates = {}
        i = 0
        for opsys, db_release in tasks:
            i += 1

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

            j = 0
            for db_component in db_release.components:
                j += 1

                name = db_component.component.name
                self.log_debug(
                    "  [{0} / {1}] Processing component '{2}'".format(
                        j, len(db_release.components), name))
                try:
                    acls = opsys.get_component_acls(name,
                                                    release=db_release.version)
                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 = OpSysReleaseComponentAssociate(
                            )
                            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()
Exemple #5
0
def maintainer_default():
    if g.user is not None:
        associate = get_associate_by_name(db, g.user.username)
        if associate is not None:
            return associate
    return None
Exemple #6
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()
Exemple #7
0
    def run(self, cmdline, db):
        if len(cmdline.opsys) == 0:
            tasks = []
            for opsys in systems.values():
                releases = get_releases(db, opsys_name=opsys.nice_name)
                tasks += [(opsys, release) for release in releases if
                          release.status != "EOL"]
        elif len(cmdline.opsys) == 1:
            shortname = cmdline.opsys[0]
            if shortname not in systems:
                self.log_error("Operating system '{0}' is not installed"
                               .format(shortname))
                return 1

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

            if len(cmdline.opsys_release) < 1:
                tasks = [(opsys, r) for r in db_opsys.releases]
            else:
                tasks = [(opsys, r) for r in db_opsys.releases
                         if r.version in cmdline.opsys_release]
        else:
            tasks = []
            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

                tasks += [(opsys, rel) for rel in db_opsys.releases]

        new_associates = {}
        i = 0
        for opsys, db_release in tasks:
            i += 1

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

            j = 0
            for db_component in db_release.components:
                j += 1

                name = db_component.component.name
                self.log_debug("  [{0} / {1}] Processing component '{2}'"
                               .format(j, len(db_release.components), name))
                try:
                    acls = opsys.get_component_acls(name,
                                                    release=db_release.version)
                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 = OpSysReleaseComponentAssociate()
                            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()