def add_object(name: str, type_id: int, display_group_id: int = None, comment: str = None): """ Create a new object with the given name, type and comment. Args: name (str): The name of the object. type_id (int): The type ID of the object. display_group_id (int): The ID of the display group this object is part of. comment (str): Object comment. Returns: (int): ID of the added object. Raises: DBObjectNameAlreadyExists: If an object with the given name already exists in the database. """ if get_object_id(object_name=name) is not None: raise DBObjectNameAlreadyExists( f'Could not create object - ' f'Object with name "{name}" already exists in the database.') record_id = GamObject.insert(ob_name=name, ob_objecttype=type_id, ob_displaygroup=display_group_id, ob_comment=comment).execute() logger.info( f'Created object no. {record_id} ("{name}") of type {type_id}.') return record_id
def db_connect(): try: database.connect(reuse_if_open=True) logger.info('Database connection successful.') except Exception as e: raise DBConnectionError( f'Could not establish database connection: {e}')
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}')
def on_finished(self, result): if result == QDialog.Accepted: path = self.service_path.text() Settings.Manager.service_path = path manager_logger.info('Service directory path changed.') service_settings_path = Settings.Manager.service_path Settings.init_service_settings(service_settings_path) # Init/Update Service settings with path self.service_updated.emit()
def main(): # Pyinstaller fix freeze_support() sys.excepthook = excepthook manager_logger.info("Starting application.") service_manager = App() rec = service_manager.app.exec_() manager_logger.info("Exit application.") sys.exit(rec)
def add_relation(or_object_id: int, or_object_id_assigned: int): """ Creates a relation between two objects. Note: Dates must be in '%Y-%m-%d %H:%M:%S' format. Args: or_object_id (int): The object ID (the object itself). or_object_id_assigned (int): The assigned object ID (e.g. the SLD/ILM Module etc.). """ record_id = GamObjectrelation.insert( or_primary=0, or_object=or_object_id, or_object_id_assigned=or_object_id_assigned, or_date_assignment=datetime.now().strftime('%Y-%m-%d %H:%M:%S'), or_date_removal=None, or_outflow=None, or_bookingrequest=None).execute() logger.info( f'Added relation {record_id} for objects {or_object_id} - {or_object_id_assigned}.' )
def delete_entry(self, object_id: int): data = self.get_entries() deleted = False for index, entry in enumerate(data): if entry[self.OBJ] == object_id: data.remove(entry) deleted = True break if not deleted: manager_logger.warning( f'Entry with object ID {object_id} should have been deleted but was not.' ) data = {self.ROOT: data} self._json_dump(data) if deleted: manager_logger.info( f'Deleted PV configuration entry for object ID: {object_id}.')
def run(self): self._running = True manager_logger.info( f'Checking connection of measurement PVs: {self.pv_names}') connected = [] failed = [] self.display_progress_bar.emit(True) for index, pv_name in enumerate(self.pv_names): if pv_name: pv_connected = test_pv_connection(name=pv_name, timeout=2) if not self._running: manager_logger.info('Stopped PV connection check.') break self.mea_status_update.emit(index, pv_connected) if pv_connected: connected.append(pv_name) else: failed.append(pv_name) self.progress_bar_update.emit(index + 1) if self._running: manager_logger.info( f'PV connection check finished. Connected: {connected}. Failed: {failed}' ) self.results = {'connected': connected, 'failed': failed}
def refresh_db_connection(self): manager_logger.info("Refreshing database connection...") Settings.Service.connect_to_db() self.update_db_connection_status()