Пример #1
0
    def add_entry(self, new_entry: dict, overwrite: bool = False):
        """
        Add a new record config entry to PV Config.

        Args:
            new_entry (dict): The record config.
            overwrite (bool, optional): If True, overwrites the entry that matches the object ID, Defaults to False.
        """
        data = self.get_entries()
        if overwrite:
            overwritten = False
            for index, entry in enumerate(data):
                if entry[self.OBJ] == new_entry[self.OBJ]:
                    data[index] = new_entry
                    overwritten = True
                    break
            if not overwritten:
                manager_logger.error(
                    f'Entry with object ID {new_entry[self.OBJ]} was not overwritten.'
                )
                return
        else:
            data.append(new_entry)

        data = {self.ROOT: data}
        self._json_dump(data)
        manager_logger.info(
            f'Added new PV configuration entry: {new_entry}' if not overwrite
            else f'Updated PV configuration entry: {new_entry}')
Пример #2
0
def is_admin():
    # noinspection PyBroadException
    try:
        return ctypes.windll.shell32.IsUserAnAdmin()
    except Exception as e:
        manager_logger.error(e)
        return False
Пример #3
0
 def update_config_data(self):
     """ Get the PV configuration entries (list of dicts) and store the data in an attribute. """
     try:
         self.pv_config_data = Settings.Service.PVConfig.get_entries()
     except FileNotFoundError as e:
         manager_logger.error(e)
         self.pv_config_data = []
         return
Пример #4
0
 def _get_credentials(service_option):
     if not SERVICE_NAME:
         return
     try:
         return win32serviceutil.GetServiceCustomOption(
             serviceName=SERVICE_NAME, option=service_option)
     except Exception as e:
         manager_logger.error(e)
Пример #5
0
 def _set_credentials(service_option, new_value, err_msg: str):
     if not SERVICE_NAME:
         manager_logger.error(err_msg)
         return
     try:
         win32serviceutil.SetServiceCustomOption(serviceName=SERVICE_NAME,
                                                 option=service_option,
                                                 value=new_value)
     except Exception as e:
         manager_logger.error(e)
Пример #6
0
def excepthook(exc_type, exc_value, exc_tb):
    traceback_ = ''.join(
        traceback.format_exception(exc_type, exc_value, exc_tb))
    err_msg = f'An unhandled exception has occurred:\n {traceback_}'
    manager_logger.error(err_msg)
    err_msg = err_msg.replace('\n', '<br>')
    error_dialog = QErrorMessage()
    error_dialog.setWindowTitle('HLM PV Import - Error')
    error_dialog.resize(600, 300)
    error_dialog.setFont(QFont('Lucida Console', 9))
    error_dialog.showMessage(err_msg)
    error_dialog.exec()
Пример #7
0
 def update_log(self):
     service_log_path = Settings.Service.Logging.log_path
     try:
         last_modified = os.path.getmtime(service_log_path)
     except FileNotFoundError as e:
         manager_logger.error(e)
         self.enable_or_disable_buttons.emit(False)
         self.file_not_found.emit()
         self.last_widget_update = 0
         self.stop()
         return
     # if log file was modified since last log widget update, update widget text
     if last_modified > self.last_widget_update:
         with open(service_log_path) as file:
             text = ''.join(deque(file, self.displayed_lines_no))
             self.log_fetched.emit(text)
             self.last_widget_update = time.time()
Пример #8
0
def test_pv_connection(name: str, timeout: int = 1):
    """
    Tests whether CA can connect to a PV and get its value.

    Args:
        name (str): The PV.
        timeout (int, optional): PV connection timeout in seconds, Defaults to 1.

    Returns:
        (boolean): True if connected, False otherwise.
    """

    try:
        read(pv_name=name, timeout=timeout)
        return True
    except Exception as e:
        manager_logger.error(e)
        return False
Пример #9
0
 def __init__(self, err_msg):
     logger.error(err_msg)
     super(DBConnectionError, self).__init__(err_msg)
Пример #10
0
 def __init__(self, err_msg):
     logger.error(err_msg)
     super(DBObjectNameAlreadyExists, self).__init__(err_msg)