Ejemplo n.º 1
0
 def test_attach_to_config_and_remove_simple(self):
     document = """
     further_reading: test_echam.some_file
     """
     some_file = """
     stuff: things
     """
     try:
         for f, c in zip(
             [
                 "../test_echam/example_test_echam.yaml",
                 "../test_echam/test_echam.some_file.yaml",
             ],
             [document, some_file],
         ):
             with open(f, "w") as test_file:
                 test_file.write(c)
         config = esm_parser.yaml_file_to_dict(
             "../test_echam/example_test_echam.yaml")
         esm_parser.attach_to_config_and_remove(config, "further_reading")
         expected_answer = {"stuff": "things"}
         self.assertEqual(config, expected_answer)
     finally:
         for f in [
                 "../test_echam/example_test_echam.yaml",
                 "../test_echam/test_echam.some_file.yaml",
         ]:
             os.remove(f)
Ejemplo n.º 2
0
 def __init__(self):
     self.machine_file = esm_parser.determine_computer_from_hostname()
     self.config = esm_parser.yaml_file_to_dict(self.machine_file)
     esm_parser.basic_choose_blocks(self.config, self.config)
     esm_parser.recursive_run_function([], self.config, "atomic",
                                       esm_parser.find_variable,
                                       self.config, [], True)
Ejemplo n.º 3
0
    def test_yaml_file_to_dict(self):
        """Tests extension expansion and loading of YAML documents"""
        document = """
        model: PISM
        nest:
            Domains:
                - nhem
                - shem
                - gris
                - something
            Resolutions:
                - big
                - small
        """

        for valid_extension in esm_parser.YAML_AUTO_EXTENSIONS:
            with open("test" + valid_extension, "w") as test_file:
                test_file.write(document)
            result = esm_parser.yaml_file_to_dict("test")
            try:
                self.assertIsInstance(result, dict)
            finally:
                os.remove("test" + valid_extension)
        with open("test.hjkl", "w") as bad_test_file:
            bad_test_file.write(document)
        try:
            self.assertRaises(Exception, esm_parser.yaml_file_to_dict, "test")
        finally:
            os.remove("test.hjkl")
Ejemplo n.º 4
0
    def __init__(self):

        self.config = esm_parser.yaml_file_to_dict(config_yaml)
        self.emc = self.read_and_update_conf_files()
        self.meta_todos, self.meta_command_order = self.get_meta_command()
        self.display_kinds = self.get_display_kinds()

        if verbose > 1:
            self.output()
def remap_old_new_keys(config):
    try:
        mapping_table_old_to_new = "not a thing yet"
        mapping_table = esm_parser.yaml_file_to_dict(mapping_table_old_to_new)
        for script_key, python_key in six.iteritems(mapping_table):
            for config_key, config_value in six.iteritems(config):
                if config_key == script_key:
                    del config[script_key]
                    config[python_key] = config_calue
    except:
        pass
Ejemplo n.º 6
0
 def add_esm_runscripts_defaults_to_config(self, config):
     if config['general'].get(
             "use_venv") or esm_rcfile.FUNCTION_PATH.startswith("NONE_YET"):
         path_to_file = esm_tools.get_config_filepath(
             "esm_software/esm_runscripts/defaults.yaml")
     else:
         path_to_file = esm_rcfile.FUNCTION_PATH + "/esm_software/esm_runscripts/defaults.yaml"
     default_config = esm_parser.yaml_file_to_dict(path_to_file)
     config["general"]["defaults.yaml"] = default_config
     config = self.distribute_per_model_defaults(config)
     return config
Ejemplo n.º 7
0
    def __init__(self, vcs, general):
        blacklist = [
            re.compile(entry)
            for entry in [".*version", ".*_dir", ".*grid", ".*archfile"]
        ]
        self.config = esm_parser.yaml_file_to_dict(components_yaml)
        self.model_kinds = list(self.config.keys())
        self.meta_todos = general.meta_todos
        self.meta_command_order = general.meta_command_order
        self.display_kinds = general.display_kinds

        self.model_todos = []
        for kind in self.model_kinds:
            for model in self.config[kind].keys():
                version = None
                if "choose_versions" in self.config[kind][model]:
                    for version in self.config[kind][model]["choose_versions"]:
                        for entry in self.config[kind][model]["choose_version"][
                            version
                        ]:
                            if entry.endswith("_command"):
                                todo = entry.replace("_command", "")
                                if todo not in self.model_todos:
                                    self.model_todos.append(todo)
                for entry in self.config[kind][model]:
                    if entry.endswith("_command"):
                        todo = entry.replace("_command", "")
                        if todo not in self.model_todos:
                            self.model_todos.append(todo)

        self.known_todos = self.model_todos + vcs.known_todos + general.meta_todos
        self.all_packages = self.list_all_packages(vcs, general)
        self.update_packages(vcs, general)
        esm_parser.recursive_run_function(
            [],
            self.config,
            "atomic",
            esm_parser.find_variable,
            self.config,
            blacklist,
            True,
        )
        #        self.output()

        if verbose > 1:
            self.output()
Ejemplo n.º 8
0
 def __init__(self):
     self.config = {}
     vcs_files = [f for f in os.listdir(vcs_folder)]
     self.known_repos = []
     for vcs_file in vcs_files:
         if os.path.isfile(vcs_folder + "/" + vcs_file):
             repo_type = vcs_file.replace(".yaml", "")
             self.config.update(
                 {
                     repo_type: esm_parser.yaml_file_to_dict(
                         vcs_folder + "/" + vcs_file
                     )
                 }
             )
             self.known_repos.append(repo_type)
     self.known_todos = []
     for repo in self.known_repos:
         for entry in self.config[repo].keys():
             if entry.endswith("_command"):
                 todo = entry.replace("_command", "")
                 if todo not in self.known_todos:
                     self.known_todos.append(todo)
     if verbose > 1:
         self.output()
Ejemplo n.º 9
0
from esm_parser import yaml_file_to_dict

test = yaml_file_to_dict(
    "/tmp/example_experiments/test/scripts/test_preconfig.yaml")