How to use the oasislmf.cli.model.GenerateOasisFilesCmd function in oasislmf

To help you get started, we’ve selected a few oasislmf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github OasisLMF / OasisPlatform / src / model_execution_worker / tasks.py View on Github external
if complex_data_files:
            prepare_complex_model_file_inputs(complex_data_files, media_root, input_data_dir)
            run_args += ['--user-data-dir', input_data_dir]
        if settings.getboolean('worker', 'DISABLE_EXPOSURE_SUMMARY', fallback=False):
            run_args.append('--disable-summarise-exposure')

        # Log MDK generate command 
        args_list = run_args + [''] if (len(run_args) % 2) else run_args
        mdk_args = [x for t in list(zip(*[iter(args_list)] * 2)) if None not in t for x in t]
        logging.info('run_directory: {}'.format(oasis_files_dir))
        logging.info('args_list: {}'.format(str(run_args)))
        logging.info("\nRUNNING: \noasislmf model generate-oasis-files {}".format(
            " ".join([str(arg) for arg in mdk_args])
        ))

        GenerateOasisFilesCmd(argv=run_args).run()

        # Process Generated Files
        lookup_error_fp = next(iter(glob.glob(os.path.join(oasis_files_dir, '*keys-errors*.csv'))), None)
        lookup_success_fp = next(iter(glob.glob(os.path.join(oasis_files_dir, 'gul_summary_map.csv'))), None)
        lookup_validation_fp = next(iter(glob.glob(os.path.join(oasis_files_dir, 'exposure_summary_report.json'))), None)
        summary_levels_fp = next(iter(glob.glob(os.path.join(oasis_files_dir, 'exposure_summary_levels.json'))), None)

        if lookup_error_fp:
            hashed_filename = os.path.join(media_root, '{}.csv'.format(uuid.uuid4().hex))
            shutil.copy(lookup_error_fp, hashed_filename)
            lookup_error_fp = str(Path(hashed_filename).relative_to(media_root))

        if lookup_success_fp:
            hashed_filename = os.path.join(media_root, '{}.csv'.format(uuid.uuid4().hex))
            shutil.copy(lookup_success_fp, hashed_filename)
            lookup_success_fp = str(Path(hashed_filename).relative_to(media_root))