def _log_config(config, logger): """Log the configuration settings. Parameters ---------- logger : logging.Logger The application's logger. """ logger.debug("Configuration settings") app = config["DEFAULT"] aet, port, pdu = app["ae_title"], app["port"], app["max_pdu"] logger.debug(f" AE title: {aet}, Port: {port}, Max. PDU: {pdu}") logger.debug(" Timeouts:") acse, dimse = app["acse_timeout"], app["dimse_timeout"] network = app["network_timeout"] logger.debug(f" ACSE: {acse}, DIMSE: {dimse}, Network: {network}") logger.debug(f" Storage directory: {app['instance_location']}") logger.debug(f" Database location: {app['database_location']}") if config.sections(): logger.debug(" Move destinations: ") else: logger.debug(" Move destinations: none") for ae_title in config.sections(): addr = config[ae_title]["address"] port = config[ae_title]["port"] logger.debug(f" {ae_title}: ({addr}, {port})") logger.debug("")
def _log_config(config, logger): """Log the configuration settings. Parameters ---------- logger : logging.Logger The application's logger. """ logger.debug('Configuration settings') app = config['DEFAULT'] logger.debug( ' AE title: {}, Port: {}, Max. PDU: {}' .format(app['ae_title'], app['port'], app['max_pdu']) ) logger.debug(' Timeouts:') logger.debug( ' ACSE: {}, DIMSE: {}, Network: {}' .format( app['acse_timeout'], app['dimse_timeout'], app['network_timeout'] ) ) logger.debug(' Storage directory: {}'.format(app['instance_location'])) logger.debug(' Database location: {}'.format(app['database_location'])) if config.sections(): logger.debug(' Move destinations: ') else: logger.debug(' Move destinations: none') for ae_title in config.sections(): addr = config[ae_title]['address'] port = config[ae_title]['port'] logger.debug(' {}: ({}, {})'.format(ae_title, addr, port)) logger.debug('')
def main(args=None): """Run the application.""" if args is not None: sys.argv = args args = _setup_argparser() if args.version: print(f"qrscp.py v{__version__}") sys.exit() APP_LOGGER = setup_logging(args, "qrscp") APP_LOGGER.debug(f"qrscp.py v{__version__}") APP_LOGGER.debug("") APP_LOGGER.debug("Using configuration from:") APP_LOGGER.debug(f" {args.config}") APP_LOGGER.debug("") config = ConfigParser() config.read(args.config) if args.ae_title: config["DEFAULT"]["ae_title"] = args.ae_title if args.port: config["DEFAULT"]["port"] = args.port if args.max_pdu: config["DEFAULT"]["max_pdu"] = args.max_pdu if args.acse_timeout: config["DEFAULT"]["acse_timeout"] = args.acse_timeout if args.dimse_timeout: config["DEFAULT"]["dimse_timeout"] = args.dimse_timeout if args.network_timeout: config["DEFAULT"]["network_timeout"] = args.network_timeout if args.bind_address: config["DEFAULT"]["bind_address"] = args.bind_address if args.database_location: config["DEFAULT"]["database_location"] = args.database_location if args.instance_location: config["DEFAULT"]["instance_location"] = args.instance_location # Log configuration settings _log_config(config, APP_LOGGER) app_config = config["DEFAULT"] dests = {} for ae_title in config.sections(): dest = config[ae_title] # Convert to bytes and validate the AE title ae_title = set_ae(ae_title, "ae_title", False, False) dests[ae_title] = (dest["address"], dest.getint("port")) # Use default or specified configuration file current_dir = os.path.abspath(os.path.dirname(__file__)) instance_dir = os.path.join(current_dir, app_config["instance_location"]) db_path = os.path.join(current_dir, app_config["database_location"]) # The path to the database db_path = f"sqlite:///{db_path}" db.create(db_path) # Clean up the database and storage directory if args.clean: response = input( "This will delete all instances from both the storage directory " "and the database. Are you sure you wish to continue? [yes/no]: ") if response != "yes": sys.exit() if clean(db_path, instance_dir, APP_LOGGER): sys.exit() else: sys.exit(1) # Try to create the instance storage directory os.makedirs(instance_dir, exist_ok=True) ae = AE(app_config["ae_title"]) ae.maximum_pdu_size = app_config.getint("max_pdu") ae.acse_timeout = app_config.getfloat("acse_timeout") ae.dimse_timeout = app_config.getfloat("dimse_timeout") ae.network_timeout = app_config.getfloat("network_timeout") ## Add supported presentation contexts # Verification SCP ae.add_supported_context(Verification, ALL_TRANSFER_SYNTAXES) # Storage SCP - support all transfer syntaxes for cx in AllStoragePresentationContexts: ae.add_supported_context(cx.abstract_syntax, ALL_TRANSFER_SYNTAXES, scp_role=True, scu_role=False) # Query/Retrieve SCP ae.add_supported_context(PatientRootQueryRetrieveInformationModelFind) ae.add_supported_context(PatientRootQueryRetrieveInformationModelMove) ae.add_supported_context(PatientRootQueryRetrieveInformationModelGet) ae.add_supported_context(StudyRootQueryRetrieveInformationModelFind) ae.add_supported_context(StudyRootQueryRetrieveInformationModelMove) ae.add_supported_context(StudyRootQueryRetrieveInformationModelGet) # Set our handler bindings handlers = [ (evt.EVT_C_ECHO, handle_echo, [args, APP_LOGGER]), (evt.EVT_C_FIND, handle_find, [db_path, args, APP_LOGGER]), (evt.EVT_C_GET, handle_get, [db_path, args, APP_LOGGER]), (evt.EVT_C_MOVE, handle_move, [dests, db_path, args, APP_LOGGER]), (evt.EVT_C_STORE, handle_store, [instance_dir, db_path, args, APP_LOGGER]), ] # Listen for incoming association requests ae.start_server((app_config["bind_address"], app_config.getint("port")), evt_handlers=handlers)