Пример #1
0
def get_config_directory(
        *, project_name: str,
        project_version: str) -> str:  # pragma: no cover ## Not relevant
    """
    Provides the location of the configuration directory.
    """

    # pylint: disable=too-many-branches

    env_var_helper = EnvironmentVariableHelper()
    directory_helper = DirectoryHelper()

    if env_var_helper.set_name("PYFUNCEBLE_CONFIG_DIR").exists():
        config_directory = env_var_helper.get_value()
    elif env_var_helper.set_name("PYFUNCEBLE_OUTPUT_DIR").exists():
        config_directory = env_var_helper.get_value()
    elif (VersionUtility(project_version).is_cloned()
          or env_var_helper.set_name("TRAVIS_BUILD_DIR").exists()
          or env_var_helper.set_name("CI_PROJECT_DIR").exists()
          and env_var_helper.set_name("GITLAB_CI").exists()):
        config_directory = directory_helper.get_current(with_end_sep=True)
    else:
        if PlatformUtility.is_unix():
            config_dir_path = os.path.expanduser(os.path.join("~", ".config"))

            if directory_helper.set_path(config_dir_path).exists():
                config_directory = config_dir_path
            elif directory_helper.set_path(os.path.expanduser("~")).exists():
                config_directory = directory_helper.join_path(".")
            else:
                config_directory = directory_helper.get_current(
                    with_end_sep=True)
        elif PlatformUtility.is_windows():
            if env_var_helper.set_name("APPDATA").exists():
                config_directory = env_var_helper.get_value()
            else:
                config_directory = directory_helper.get_current(
                    with_end_sep=True)
        else:
            config_directory = directory_helper.get_current(with_end_sep=True)

        if not config_directory.endswith(os.sep):
            config_directory += os.sep
        config_directory += project_name + os.sep

        if not directory_helper.set_path(config_directory).exists():
            directory_helper.create()

    if not config_directory.endswith(os.sep):
        config_directory += os.sep

    return config_directory
Пример #2
0
    def test_is_not_windows(self):
        """
        Tests the method which let us know if the current platform is the
        Windows one for that case that it's the linux one.
        """

        with self.system_platform_mock as platform_patch:
            platform_patch.return_value = "Linux"

            expected = False
            actual = PlatformUtility.is_windows()

            self.assertEqual(expected, actual)
Пример #3
0
    def test_is_windows(self):
        """
        Tests the method which let us know if the current platform is the
        Windows one.
        """

        with self.system_platform_mock as platform_patch:
            platform_patch.return_value = "windows"

            expected = True
            actual = PlatformUtility.is_windows()

            self.assertEqual(expected, actual)
Пример #4
0
    def test_join_path(self) -> None:
        """
        Tests the method which let us join paths.
        """

        given = "/hello/world"

        if PlatformUtility.is_windows():
            expected = "/hello/world\\hello\\world"
        else:
            expected = "/hello/world/hello/world"

        actual = FileHelper(given).join_path("hello", "world")

        self.assertEqual(expected, actual)
Пример #5
0
    def test_get_current_with_sep(
            self, getcwd_path: unittest.mock.MagicMock) -> None:
        """
        Tests the method which let us get the current directory for the case
        that we want to have the directory separator at  the end.
        """

        getcwd_path.return_value = "/hello/world"

        if PlatformUtility.is_windows():
            expected = "/hello/world\\"
        else:
            expected = "/hello/world/"

        actual = self.helper.get_current(with_end_sep=True)

        self.assertEqual(expected, actual)
Пример #6
0
    def get_backup_data(self) -> dict:
        """
        Stores the backup at the current destination.
        """

        data = DictHelper().from_json_file(self.source_file)

        if PlatformUtility.is_windows():
            result = {}

            for directory, files in data.items():
                result[os.path.normpath(directory)] = files

            PyFunceble.facility.Logger.debug("Backup (read) data:\n%r", result)

            return result

        PyFunceble.facility.Logger.debug("Backup (read) data:\n%r", data)
        return data