def dump_rose_log(rundir, node): """Dump a config node to a timestamped file in the ``log`` sub-directory. Args: rundir (pathlib.Path): Installed location of a flow. node (Rose Config node): Node to be dumped to file. Returns: String filepath of the dump file relative to the install directory. """ dumper = ConfigDumper() timestamp = DateTimeOperator().process_time_point_str( print_format='%Y%m%dT%H%M%S%z') rel_path = f'log/config/{timestamp}-rose-suite.conf' fpath = rundir / rel_path fpath.parent.mkdir(exist_ok=True, parents=True) dumper.dump(node, str(fpath)) return rel_path
def record_cylc_install_options( rundir=None, opts=None, srcdir=None, ): """Create/modify files recording Cylc install config options. Creates a new config based on CLI options and writes it to the workflow install location as ``rose-suite-cylc-install.conf``. If ``rose-suite-cylc-install.conf`` already exists over-writes changed items, except for ``!opts=`` which is merged and simplified. If ``!opts=`` have been changed these are appended to those that have been written in the installed ``rose-suite.conf``. Args: srcdir (pathlib.Path): Used to check whether the source directory contains a rose config. opts: Cylc option parser object - we want to extract the following values: - opt_conf_keys (list or str): Equivelent of ``rose suite-run --option KEY`` - defines (list of str): Equivelent of ``rose suite-run --define KEY=VAL`` - suite_defines (list of str): Equivelent of ``rose suite-run --define-suite KEY=VAL`` rundir (pathlib.Path): Path to dump the rose-suite-cylc-conf Returns: cli_config - Config Node which has been dumped to ``rose-suite-cylc-install.conf``. rose_suite_conf['opts'] - Opts section of the config node dumped to installed ``rose-suite.conf``. """ # Create a config based on command line options: cli_config = get_cli_opts_node(opts) # Leave now if there is nothing to do: if not cli_config: return False # Construct path objects representing our target files. (Path(rundir) / 'opt').mkdir(exist_ok=True) conf_filepath = Path(rundir) / 'opt/rose-suite-cylc-install.conf' rose_conf_filepath = Path(rundir) / 'rose-suite.conf' dumper = ConfigDumper() loader = ConfigLoader() # If file exists we need to merge with our new config, over-writing with # new items where there are duplicates. if conf_filepath.is_file(): if opts.clear_rose_install_opts: conf_filepath.unlink() else: oldconfig = loader.load(str(conf_filepath)) cli_config = merge_rose_cylc_suite_install_conf( oldconfig, cli_config) cli_config.comments = [' This file records CLI Options.'] dumper.dump(cli_config, str(conf_filepath)) # Merge the opts section of the rose-suite.conf with those set by CLI: if not rose_conf_filepath.is_file(): rose_conf_filepath.touch() rose_suite_conf = loader.load(str(rose_conf_filepath)) rose_suite_conf = add_cylc_install_to_rose_conf_node_opts( rose_suite_conf, cli_config) dumper(rose_suite_conf, rose_conf_filepath) return cli_config, rose_suite_conf