コード例 #1
0
    def load_config(self, args):
        import os

        from yt.config import YTConfig
        from yt.utilities.configure import CONFIG

        local_config_file = YTConfig.get_local_config_file()
        global_config_file = YTConfig.get_global_config_file()

        local_exists = os.path.exists(local_config_file)
        global_exists = os.path.exists(global_config_file)

        local_arg_exists = hasattr(args, "local")
        global_arg_exists = hasattr(args, "global")

        if getattr(args, "local", False):
            config_file = local_config_file
        elif getattr(args, "global", False):
            config_file = global_config_file
        else:
            config_file: Optional[str] = None
            if local_exists and global_exists:
                s = (
                    "Yt detected a local and a global configuration file, refusing "
                    "to proceed.\n"
                    f"Local config file: {local_config_file}\n"
                    f"Global config file: {global_config_file}")
                # Only print the info about "--global" and "--local" if they exist
                if local_arg_exists and global_arg_exists:
                    s += (
                        "\n"  # missing eol from previous string
                        "Specify which one you want to use using the `--local` or the "
                        "`--global` flags.")
                sys.exit(s)
            elif local_exists:
                config_file = local_config_file
            elif global_exists:
                config_file = global_config_file

            if config_file is None:
                print("WARNING: no configuration file installed.",
                      file=sys.stderr)
            else:
                print(f"INFO: reading configuration file: {config_file}",
                      file=sys.stderr)
        CONFIG.read(config_file)

        self.config_file = config_file
コード例 #2
0
    def load_config(self, args):
        import os

        from yt.config import YTConfig
        from yt.utilities.configure import CONFIG

        local_config_file = YTConfig.get_local_config_file()
        global_config_file = YTConfig.get_global_config_file()

        local_exists = os.path.exists(local_config_file)
        global_exists = os.path.exists(global_config_file)

        local_arg_exists = hasattr(args, "local")
        global_arg_exists = hasattr(args, "global")

        if getattr(args, "local", False):
            config_file = local_config_file
        elif getattr(args, "global", False):
            config_file = global_config_file
        else:
            if local_exists and global_exists:
                s = (
                    "Yt detected a local and a global configuration file, refusing "
                    "to proceed.\n"
                    f"Local config file: {local_config_file}\n"
                    f"Global config file: {global_config_file}"
                )
                # Only print the info about "--global" and "--local" if they exist
                if local_arg_exists and global_arg_exists:
                    s += (
                        "\n"  # missing eol from previous string
                        "Specify which one you want to use using the `--local` or the "
                        "`--global` flags."
                    )
                sys.exit(s)
            elif local_exists:
                config_file = local_config_file
            else:
                config_file = global_config_file
            sys.stderr.write(f"INFO: using configuration file: {config_file}.\n")

        if not os.path.exists(config_file):
            with open(config_file, "w") as f:
                f.write("[yt]\n")

        CONFIG.read(config_file)

        self.config_file = config_file
コード例 #3
0
 def setUp(self):
     super().setUp()
     with open(YTConfig.get_local_config_file(), mode="w") as f:
         f.writelines("[yt]\n")
     with open(YTConfig.get_global_config_file(), mode="w") as f:
         f.writelines("[yt]\n")
コード例 #4
0
import contextlib
import os
import sys
import unittest
import unittest.mock as mock
from io import StringIO

import yt.config
import yt.utilities.command_line
from yt.config import OLD_CONFIG_FILE, YTConfig

GLOBAL_CONFIG_FILE = YTConfig.get_global_config_file()
LOCAL_CONFIG_FILE = YTConfig.get_local_config_file()

_TEST_PLUGIN = "_test_plugin.py"
# NOTE: the normalization of the crazy camel-case will be checked
_DUMMY_CFG_INI = f"""[yt]
logLevel = 49
pluginfilename = {_TEST_PLUGIN}
boolean_stuff = True
chunk_size = 3
"""

_DUMMY_CFG_TOML = f"""[yt]
log_level = 49
plugin_filename = "{_TEST_PLUGIN}"
boolean_stuff = true
chunk_size = 3
"""