Example #1
0
    def __init__(self,
                 build_config: FilePath,
                 json_path: FilePath,
                 load_json: bool = True):
        """Loads the file from one of the given JSON paths.

        If `json_path` exists, it is loaded from this file, else `build_config`
        is read.

        Args:
            build_config (FilePath): The path to the original JSON build
                                    configuration  file.
            json_path (FilePath): The path where the parsed build tool configuration
                                    should be saved to. It is not used, because
                                    the `BuildCfg` instances are part of the
                                    project configuration file.
            load_json (bool, optional): Should the configuration be read from the
                                    file `build_config`. Defaults to True.
        """
        super().__init__(config_file_name=BUILD_FILE_NAME, config_name="build")

        self.config_path = build_config
        self.json_path = json_path

        if load_json:
            read_config_path = returnExistingFile(
                [self.json_path, self.config_path])

            self.readJSON(json_path=read_config_path)

            self.initAttribs()
Example #2
0
    def __init__(self,
                 module_config: FilePath,
                 json_path: FilePath,
                 load_json: bool = True):
        """Loads the file from one of the given JSON paths.

        If `json_path` exists, it is loaded from this file, else `module_config`
        is read.

        Args:
            module_config (FilePath): The path to the original JSON module
                            configuration  file.
            json_path (FilePath): The path where the parsed module configuration
                                    should be saved to. It is not used, because
                                    the `ModuleCFG` instances are part of the
                                    project configuration file.
            load_json (bool, optional): Should the configuration be read from the
                                    file `module_config`. Defaults to True.
        """
        super().__init__(config_file_name=MODULE_FILE_NAME,
                         config_name="module")

        self.config_path = module_config
        self.json_path = json_path

        if load_json:
            read_config_path = returnExistingFile(
                [self.json_path, self.config_path])

            self.readJSON(json_path=read_config_path)

            must_have_attrs = {"name": "", "targets": []}
            self.addAttributesIfNotExist(must_have_attrs)
Example #3
0
def test_returnExistingFile() -> None:
    """Test the function `returnExistingFile`."""
    file_path1 = tests.test_project_path
    file_path2 = "/".join([tests.test_project_path,
                           "project_config.json"])  # file
    file_path3 = "/".join([tests.test_project_path, "this_does_not_exist"])

    assert (  # nosec
        files.returnExistingFile(
            file_list=[file_path1, file_path3]) == file_path1)

    assert (  # nosec
        files.returnExistingFile(
            file_list=[file_path2, file_path3]) == file_path2)

    assert (  # nosec
        files.returnExistingFile(
            file_list=[file_path1, file_path2, file_path3]) == file_path1)
Example #4
0
    def __init__(self, project_config: FilePath, json_path: FilePath) -> None:
        """Constructor of class Config.

        Parses the project's JSON configuration and stores it to project_cfg.

        Arguments:
            project_config (FilePath): the path to the project's JSON configuration
                                        file to read.
            json_path (FilePath): The path to the JSON file to write the result.
        """
        super().__init__(config_file_name=PROJECT_FILE_NAME,
                         config_name="project")

        self.project_dep_cfg: project_dependency.ProjectDependency = None
        self.config_path = project_config
        self.json_path = json_path

        read_config_path = returnExistingFile(
            [self.json_path, self.config_path])

        self.readJSON(json_path=read_config_path)

        self.project_dependency_config = os.path.abspath("/".join([
            os.path.dirname(self.config_path),
            os.path.basename(self.project_dependency_config),
        ]))

        self.project_cfg_dir = os.path.abspath(
            os.path.dirname(self.config_path))

        must_have_attrs = {
            "config_path": "",
            "email": "",
            "web_url": "",
            "copyright_info": "",
            "company": "",
            "author": "",
            "version": "",
            "name": "",
        }
        self.addAttributesIfNotExist(must_have_attrs)

        self.setProjectConstants()

        # only if not reading from already written configs.
        if read_config_path == self.config_path:
            self.module_cfgs = []

            self.build_cfgs = []

            self.parseModuleCfgs()

            self.parseBuildCfgs()
        else:
            self.readConfigsJSON()

        self.connectModulesBuildTools()
    def __init__(self, dependency_config: FilePath, json_path: FilePath) -> None:
        """Parses the project dependency JSON configuration file.

        Args:
            dependency_config (FilePath): the configuration file of project
                                            dependencies to load
            json_path (FilePath): The path to the JSON file to write the result.
        """
        super().__init__(
            config_file_name=PROJECT_DEP_FILE_NAME, config_name="project dependencies"
        )

        self.config_path = os.path.normpath(dependency_config)
        self.json_path = json_path

        read_config_path = returnExistingFile([self.json_path, self.config_path])

        self.readJSON(json_path=read_config_path)

        self.addAttributesIfNotExist({"dependencies": []})