Ejemplo n.º 1
0
    def __init__(self, req_id, uri, diss_info, client_ip):

        self.req_id = req_id
        self.uri = uri
        self.diss_info = diss_info
        self.date_reception = gmtime()
        self.request_file = ""
        self._diff_externalid = None
        self.hostname = self.get_hostname(client_ip)
        #load settings, if it has not been done
        if not SettingsManager.is_loaded():
            SettingsManager.load_settings()
            # initialize LOGGER
            setup_logging()
            # setup repertory structure
            HarnessTree.setup_tree()

        # Setting up database if necessary
        if Database.get_database() is None:
            from webservice.server.application import APP
            Database.initialize_database(APP)
            LOGGER.debug("Database setup")


        LOGGER.debug("Created a Notification object with id %s", req_id)
Ejemplo n.º 2
0
def setup_logging(default_path=DEFAULT_PATH):
    """Setup logging configuration

    """

    path = os.path.abspath(default_path)
    if os.path.exists(path):
        with open(path, 'rt') as file_:
            config = yaml.safe_load(file_.read())
        # use harnaislogdir settings if it has been set.
        log_dir, dir_error_msg = _get_logdir()
        if log_dir is not None:
            if os.path.isdir(log_dir):
                change_log_dir(config, log_dir)
            else:
                raise NotADirectoryError(dir_error_msg)
        elif SettingsManager.is_loaded():
            logging.warning(
                "Logdir filed in settings_harnais.yaml has not been set.\n"
                "Log files repertories will be those defined in the %s file",
                default_path)
        else:
            error_msg = "Attempting to setup logs before the SettingsManager has been loaded"
            logging.error(error_msg)
            raise RuntimeError(error_msg)
        logging.config.dictConfig(config)
    else:
        raise FileNotFoundError("Couldn't resolve logging configuration "
                                "file path {f}".format(f=path))
Ejemplo n.º 3
0
    def setup_tree(cls, update=False):

        if update:
            LOGGER.info("Settings modified, performing a check on the "
                        "repertories tree structure, updating it if necessary")

        if not SettingsManager.is_loaded():
            error_msg = ("Attempting to setup repertories "
                         "tree structure before the SettingsManager "
                         "has been loaded")
            LOGGER.error(error_msg)
            raise RuntimeError(error_msg)

        def setup_repertory(dir_path):

            if not os.path.isdir(dir_path):
                try:
                    os.makedirs(dir_path, exist_ok=True)
                    LOGGER.debug(
                        "Repertory %s created recursively.", dir_path)

                except Exception as msg_error:
                    LOGGER.exception(
                        "Couldn't create repertory %s.",dir_path)
            return dir_path

        if DEBUG:
            tempfile.gettempdir()
            tempfile.tempdir = None
            harnais_dir = os.path.join(tempfile.gettempdir(), "harnais")
        else:
            harnais_dir = SettingsManager.get("harnaisDir")
        # repertory of temporary dissRequest JSON files
        cls._repertories["temp_dissRequest_A"] = setup_repertory(
            join(harnais_dir,
                 REPERTORY_TREE.temp_dissrequest_a)
                                                                )
        cls._repertories["temp_dissRequest_B"] = setup_repertory(
            join(harnais_dir,
                 REPERTORY_TREE.temp_dissrequest_b)
                                                                )
        cls._repertories["temp_dissRequest_C"] = setup_repertory(
            join(harnais_dir,
                 REPERTORY_TREE.temp_dissrequest_c)
                                                                )
        cls._repertories["temp_dissRequest_D"] = setup_repertory(
            join(harnais_dir,
                 REPERTORY_TREE.temp_dissrequest_d)
                                                                )

        cls._repertories["dir_ack"] = dir_ack = SettingsManager.get("harnaisAckDir")

        if not os.path.isdir(cls._repertories["dir_ack"]):
            LOGGER.error("Ack repertory %s does "
                         "not exist", dir_ack)

        # storing the settings file signature
        cls._checksum = SettingsManager.get_checksum()
Ejemplo n.º 4
0
    def get(cls, key):
        if not SettingsManager.is_loaded():
            SettingsManager.load_settings()
            LOGGER.info("Settings loaded")

        #check if settings have been modified
        if SettingsManager.get_checksum() != cls._checksum:
            LOGGER.info("Settings have been modified")
            cls.setup_tree(update=True)
        elif not os.path.isdir(cls._repertories[key]):
            cls.setup_tree(update=False)

        return cls._repertories[key]