Exemple #1
0
    def get_qrs_per_role_and_models(self, db, as_dict=True):
        """
        :param as_dict: Boolean. If False, the result is returned as a list or rule keys
        """
        qrs = dict()
        role_registry = RoleRegistry()
        role_qrs = role_registry.get_role_quality_rules(role_registry.get_active_role())
        if role_qrs == ALL_QUALITY_RULES:
            role_qrs = self.__quality_rules

        if role_qrs:
            db_models = db.get_models()
            model_registry = LADMColModelRegistry()

            for qr in role_qrs:
                # First check if the role QR is registered
                if qr in self.__quality_rules:
                    # Then check if the models required by the QR are in the DB
                    req_models = self.__quality_rules[qr].models()
                    num_models = len(req_models)

                    all_models_found = True
                    if num_models:  # We don't check models if a QR has no required models (e.g., iliValidator)
                        for req_model in req_models:
                            model = model_registry.model(req_model)
                            model_key = model.full_name()
                            if model_key and model_key not in db_models:
                                all_models_found = False
                                self.logger.debug(__name__,
                                                  "Model '{}' not found in the DB. QR '{}' cannot be listed.".format(
                                                      model_key, qr
                                                  ))
                                break

                    if all_models_found:
                        qrs[qr] = self.__quality_rules[qr]

        return qrs if as_dict else list(qrs.keys())
    def __init__(self, db):
        QObject.__init__(self)
        self.logger = Logger()

        ladmcol_models = LADMColModelRegistry()
        self.current_model_version = {
            model_id: None
            for model_id in ladmcol_models.model_keys()
        }
        self.model_version_is_supported = {
            model_id: False
            for model_id in ladmcol_models.model_keys()
        }

        self._db = db

        # Fill versions for each model found
        for current_model_name in self._get_models():
            for model_key, v in self.current_model_version.items():
                if current_model_name.startswith(model_key):
                    parts = current_model_name.split(model_key)
                    if len(parts) > 1:
                        current_version = self.parse_version(parts[1])
                        current_version_valid = is_version_valid(
                            current_version,
                            ladmcol_models.model(
                                model_key).supported_version(),
                            True,  # Exact version required
                            QCoreApplication.translate("ModelParser",
                                                       model_key))
                        self.current_model_version[model_key] = current_version
                        self.model_version_is_supported[
                            model_key] = current_version_valid
                        self.logger.debug(
                            __name__, "Model '{}' found! Valid: {}".format(
                                model_key, current_version_valid))
                        break