def list_modules( configuration_file_path: str = None, out: Union[IO, str] = None, overwrite: bool = False, verbose: bool = False, force_text_output: bool = False, ): """ Writes list of available systems. If configuration_file_path is given and if it defines paths where there are registered systems, they will be listed too. :param configuration_file_path: :param out: the output stream or a path for the output file (None means sys.stdout) :param overwrite: if True and out is a file path, the file will be written even if one already exists :param verbose: if True, shows detailed information for each system if False, shows only identifier and path of each system :param force_text_output: if True, list will be written as text, even if command is used in an interactive IPython shell (Jupyter notebook). Has no effect in other shells or if out parameter is not sys.stdout :raise FastFileExistsError: if overwrite==False and out is a file path and the file exists """ if out is None: out = sys.stdout if configuration_file_path: conf = FASTOADProblemConfigurator(configuration_file_path) conf._set_configuration_modifier(_PROBLEM_CONFIGURATOR) conf.load(configuration_file_path) # As the problem has been configured, BundleLoader now knows additional registered systems if verbose: cell_list = _get_detailed_system_list() else: cell_list = _get_simple_system_list() if isinstance(out, str): if not overwrite and pth.exists(out): raise FastFileExistsError( "File %s not written because it already exists. " "Use overwrite=True to bypass." % out, out, ) make_parent_dir(out) out_file = open(out, "w") else: if ( out == sys.stdout and InteractiveShell.initialized() and not force_text_output and not verbose ): display(HTML(tabulate(cell_list, tablefmt="html"))) return out_file = out out_file.write(tabulate(cell_list, tablefmt="grid")) out_file.write("\n") if isinstance(out, str): out_file.close() _LOGGER.info("System list written in %s", out_file)
def list_systems(configuration_file_path: str = None, out: Union[IO, str] = sys.stdout, overwrite: bool = False): """ Writes list of available systems. If configuration_file_path is given and if it defines paths where there are registered systems, they will be listed too. :param configuration_file_path: :param out: the output stream or a path for the output file :param overwrite: if True and out is a file path, the file will be written even if one already exists :raise FastFileExistsError: if overwrite==False and out is a file path and the file exists """ if configuration_file_path: conf = FASTOADProblemConfigurator(configuration_file_path) conf.load(configuration_file_path) # As the problem has been configured, BundleLoader now knows additional registered systems if isinstance(out, str): if not overwrite and pth.exists(out): raise FastFileExistsError( "File %s not written because it already exists. " "Use overwrite=True to bypass." % out, out, ) make_parent_dir(out) out_file = open(out, "w") else: out_file = out out_file.writelines([ "== AVAILABLE SYSTEM IDENTIFIERS " + "=" * 68 + "\n", "-" * 100 + "\n" ]) for identifier in sorted(OpenMDAOSystemRegistry.get_system_ids()): path = BundleLoader().get_factory_path(identifier) domain = OpenMDAOSystemRegistry.get_system_domain(identifier) description = OpenMDAOSystemRegistry.get_system_description(identifier) if description is None: description = "" out_file.write(" IDENTIFIER: %s\n" % identifier) out_file.write(" PATH: %s\n" % path) out_file.write(" DOMAIN: %s\n" % domain.value) out_file.write(" DESCRIPTION: %s\n" % tw.indent(tw.dedent(description), " ")) out_file.write("-" * 100 + "\n") out_file.write("=" * 100 + "\n") out_file.writelines([ "\n== AVAILABLE PROPULSION WRAPPER IDENTIFIERS " + "=" * 56 + "\n", "-" * 100 + "\n" ]) for identifier in sorted(RegisterPropulsion.get_model_ids()): path = BundleLoader().get_factory_path(identifier) description = RegisterPropulsion.get_service_description(identifier) if description is None: description = "" out_file.write(" IDENTIFIER: %s\n" % identifier) out_file.write(" PATH: %s\n" % path) out_file.write(" DESCRIPTION: %s\n" % tw.indent(tw.dedent(description), " ")) out_file.write("-" * 100 + "\n") out_file.write("=" * 100 + "\n") if isinstance(out, str): out_file.close() _LOGGER.info("System list written in %s", out_file)