# --------------------------------------------------------------------------------------------------------- # Author : Ulrich Carmesin # Source : gitea.ucarmesin.de # --------------------------------------------------------------------------------------------------------- import os import basic.constants as B import model.entity import tools.path_const as P import tools.config_tool import tools.file_tool import tools.git_tool import tools.data_const as D import tools.file_type TABLE_NAME = "environment" """ system-name for this entity """ FIELD_ID = "enid" FILE_EXTENSION = D.DFILE_TYPE_YML UNIQUE_FIELDS = [D.FIELD_NAME] """ unique business field as human identifer """ IDENTIFYER_FIELDS = [FIELD_ID] """ unique technical field as technical identifer """ TABLE_NAMES = ["environment", "en_project", "en_component"] DEFAULT_SYNC = model.entity.SYNC_FULL_GIT2DB def select_environments(job, projectList): """ searches and gets environments in which the applications of the project are declared that these are installed filtered by parameter --environment :param job: :return: """ environments = {} path = job.conf[B.TOPIC_PATH][B.ATTR_PATH_ENV] if not os.path.exists(path): raise Exception("Umgebungsverzeichnis existiert nicht "+path) for envdir in os.listdir(path): if not os.path.isdir(os.path.join(path, envdir)): continue if envdir[0:1] == "_": continue try: pathname = tools.config_tool.select_config_path(job, P.KEY_TOOL, "conn", envdir) doc = tools.file_tool.read_file_dict(job, pathname, job.m) for proj in doc[B.SUBJECT_ENVIRONMENT][B.CONF_NODE_GENERAL][B.SUBJECT_PROJECTS]: if proj in projectList: environments[envdir] = doc[B.SUBJECT_ENVIRONMENT][B.CONF_NODE_GENERAL] elif len(projectList) == 1 and projectList[0] == "ALL": environments[envdir] = doc[B.SUBJECT_ENVIRONMENT][B.CONF_NODE_GENERAL] except: continue return environments class Environment(model.entity.Entity): FIELD_ID = "enid" LIST_FIELDS = [FIELD_ID, D.FIELD_NAME, B.SUBJECT_DESCRIPTION, B.SUBJECT_REFERENCE] """ list of object-attributes """ LIST_SUBTABLES = [B.SUBJECT_COMPS, B.SUBJECT_PROJECTS] LIST_NODES = [B.NODE_ATTRIBUTES] PREFIX_SUBTABLE = "en" name = "" description = "" reference = "" attributes = "" project = "" component = "" def read_unique_names(self, job, project, application, gran, args, ttype: str=""): """ reads the entity-names from file-storage :param job: :param opt. project: select-criteria if used and defined :param opt. application: select-criteria if used and defined :param opt. gran: granularity values testcase / testsuite / testplan :param opt. args additional args :return: list of entity-names """ path = os.path.join(job.conf[B.TOPIC_PATH][B.ATTR_PATH_ENV]) outList = self.getDirlist(job, path, "") return outList def read_entity(self, job, name): """ reads the entity from the file-system :param job: :param name: :return: """ config = self.getConfig(job, P.KEY_ENV, name, tools.config_tool.get_plain_filename(job, name), ttype=B.SUBJECT_ENVIRONMENT) return self.setAttributes(job, config, name, self.LIST_FIELDS, self.LIST_NODES, self.LIST_SUBTABLES) @staticmethod def rebuild_data(job, data: dict) -> dict: """ gets the subtable-tag from filecsv and sets the subtables in order to workable entity-elements :param job: :param data: :return: """ data = tools.file_type.popSubjectsNode(job, data) data = tools.file_type.popNameNode(job, data) return data def check_data(self, job, data: dict) -> dict: """ it checks the data for the specific form :param job: :param tdata: :param ttype: :return: """ checkNodes = {} checkNodes[tools.file_type.MUST_NODES] = [B.SUBJECT_COMPS] checkNodes[tools.file_type.MUSTNT_NODES] = [B.DATA_NODE_DATA, B.DATA_NODE_HEADER, B.DATA_NODE_FIELDS, B.DATA_NODE_KEYS] checkNodes[tools.file_type.OPT_NODES] = [B.SUBJECT_PROJECTS] return tools.file_type.check_nodes(job, data, checkNodes)