Beispiel #1
0
    def _get_tasks(self, cmdline, db):
        result = set()

        # no arguments - pull everything for non-EOL releases
        if not cmdline.opsys:
            for osplugin in systems.values():
                db_opsys = get_opsys_by_name(db, osplugin.nice_name)
                if db_opsys is None:
                    raise FafError("Operating system '{0}' is not defined in "
                                   "storage".format(osplugin.nice_name))

                for db_release in db_opsys.releases:
                    if db_release.status != "EOL":
                        result.add((osplugin, db_release))

        # a single opsys - respect opsysrelease
        elif len(cmdline.opsys) == 1:
            if cmdline.opsys[0] not in systems:
                raise FafError("Operating system '{0}' is not supported"
                               .format(cmdline.opsys[0]))

            osplugin = systems[cmdline.opsys[0]]
            db_opsys = get_opsys_by_name(db, osplugin.nice_name)
            if db_opsys is None:
                raise FafError("Operating system '{0}' is not defined in "
                               "storage".format(osplugin.nice_name))

            if len(cmdline.opsys_release) < 1:
                for db_release in db_opsys.releases:
                    result.add((osplugin, db_release))
            else:
                for release in cmdline.opsys_release:
                    db_release = get_osrelease(db, osplugin.nice_name, release)
                    if db_release is None:
                        self.log_warn("Operating system '{0} {1}' is not "
                                      "supported".format(osplugin.nice_name,
                                                         release))
                        continue

                    result.add((osplugin, db_release))

        # multiple opsys - pull all of their releases
        else:
            for opsys_name in cmdline.opsys:
                if not opsys_name in systems:
                    self.log_warn("Operating system '{0}' is not supported"
                                  .format(opsys_name))
                    continue

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

                for db_release in db_opsys.releases:
                    result.add((osplugin, db_release))

        return sorted(result, key=lambda p_r: (p_r[1].opsys.name, p_r[1].version))
Beispiel #2
0
    def _get_tasks(self, cmdline, db):
        result = set()

        # no arguments - pull everything for non-EOL releases
        if not cmdline.opsys:
            for osplugin in systems.values():
                db_opsys = get_opsys_by_name(db, osplugin.nice_name)
                if db_opsys is None:
                    raise FafError("Operating system '{0}' is not defined in "
                                   "storage".format(osplugin.nice_name))

                for db_release in db_opsys.releases:
                    if db_release.status != "EOL":
                        result.add((osplugin, db_release))

        # a single opsys - respect opsysrelease
        elif len(cmdline.opsys) == 1:
            if cmdline.opsys[0] not in systems:
                raise FafError("Operating system '{0}' is not supported"
                               .format(cmdline.opsys[0]))

            osplugin = systems[cmdline.opsys[0]]
            db_opsys = get_opsys_by_name(db, osplugin.nice_name)
            if db_opsys is None:
                raise FafError("Operating system '{0}' is not defined in "
                               "storage".format(osplugin.nice_name))

            if not cmdline.opsys_release:
                for db_release in db_opsys.releases:
                    result.add((osplugin, db_release))
            else:
                for release in cmdline.opsys_release:
                    db_release = get_osrelease(db, osplugin.nice_name, release)
                    if db_release is None:
                        self.log_warn("Operating system '{0} {1}' is not "
                                      "supported".format(osplugin.nice_name,
                                                         release))
                        continue

                    result.add((osplugin, db_release))

        # multiple opsys - pull all of their releases
        else:
            for opsys_name in cmdline.opsys:
                if not opsys_name in systems:
                    self.log_warn("Operating system '{0}' is not supported"
                                  .format(opsys_name))
                    continue

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

                for db_release in db_opsys.releases:
                    result.add((osplugin, db_release))

        return sorted(result, key=lambda p_r: (p_r[1].opsys.name, p_r[1].version))
Beispiel #3
0
    def add_opsys(self,
                  multiple=False,
                  required=False,
                  positional=False,
                  with_rel=False,
                  helpstr=None) -> None:  # pylint: disable=unused-argument
        if required:
            vs = [validators.Required()]
        else:
            vs = [validators.Optional()]

        choice_lst = [(osplugin.name, osplugin.nice_name)
                      for osplugin in systems.values()]
        arg_str = "opsys"

        if positional:
            arg_str = "OPSYS"

            q = db.session.query(OpSys.name)
            choice_lst = [(a[0], a[0]) for a in q]

            if with_rel:
                q = q.join(OpSysRelease).with_entities(OpSys.name,
                                                       OpSysRelease.version)
                choice_lst = [(a[0] + " " + a[1], a[0] + " " + a[1])
                              for a in q]

        Field = SelectField
        if multiple:
            Field = SelectMultipleField
        field = Field("Operating System", vs, choices=choice_lst)
        setattr(self.F, arg_str, field)
        self.F.argparse_fields[arg_str] = {}
Beispiel #4
0
 def add_opsys(self, multiple=False, required=False):
     Field = SelectField
     if multiple:
         Field = SelectMultipleField
     field = Field("Operating System",
                   choices=((osplugin.name, osplugin.nice_name)
                            for osplugin in systems.values()))
     setattr(self.F, "opsys", field)
     self.F.argparse_fields["opsys"] = {}
Beispiel #5
0
 def add_opsys(self, multiple=False, required=False):
     Field = SelectField
     if multiple:
         Field = SelectMultipleField
     field = Field(
         "Operating System",
         choices=((osplugin.name, osplugin.nice_name)
                  for osplugin in systems.values()))
     setattr(self.F, "opsys", field)
     self.F.argparse_fields["opsys"] = {}
Beispiel #6
0
    def add_opsys(self, multiple=False, required=False):
        if required:
            vs = [validators.Required()]
        else:
            vs = [validators.Optional()]

        Field = SelectField
        if multiple:
            Field = SelectMultipleField
        field = Field("Operating System",
                      vs,
                      choices=((osplugin.name, osplugin.nice_name)
                               for osplugin in systems.values()))
        setattr(self.F, "opsys", field)
        self.F.argparse_fields["opsys"] = {}
Beispiel #7
0
    def add_opsys(self, multiple=False, required=False):
        if required:
            vs = [validators.Required()]
        else:
            vs = [validators.Optional()]

        Field = SelectField
        if multiple:
            Field = SelectMultipleField
        field = Field(
            "Operating System",
            vs,
            choices=((osplugin.name, osplugin.nice_name)
                     for osplugin in systems.values()))
        setattr(self.F, "opsys", field)
        self.F.argparse_fields["opsys"] = {}
Beispiel #8
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()
Beispiel #9
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()
Beispiel #10
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()