Ejemplo n.º 1
0
def get_project_dependencies(project_path: str, recurse: bool = False) -> list:
    project_hash_file_path = get_hash_file_path(project_path)
    dep_list = set()

    if os.path.isfile(project_hash_file_path):
        hash_file = qpc_reader.read_file(project_hash_file_path)

        if not hash_file:
            return list(dep_list)

        for block in hash_file:
            if block.key == "dependencies":
                for dep_block in block.items:
                    # maybe get dependencies of that file as well? recursion?
                    dep_list.add(dep_block.key)
                    if recurse:
                        dep_list.update(get_project_dependencies(
                            dep_block.key))
                    if dep_block.values and dep_block.values[0] != "":
                        for path in dep_block.values:
                            if path:
                                dep_list.add(path)
                                if recurse:
                                    dep_list.update(
                                        get_project_dependencies(
                                            dep_block.key))
                break
    return list(dep_list)
Ejemplo n.º 2
0
 def read_file(self, script_path: str) -> QPCBlockBase:
     if script_path in self.read_files:
         return self.read_files[script_path]
     else:
         try:
             script = read_file(script_path)
             self.read_files[script_path] = script
             return script
         except FileNotFoundError:
             pass
Ejemplo n.º 3
0
def get_out_dir(project_hash_file_path):
    if os.path.isfile(project_hash_file_path):
        hash_file = qpc_reader.read_file(project_hash_file_path)

        if not hash_file:
            return ""

        commands_block = hash_file.get_item("commands")

        if commands_block is None:
            print("hold up")
            return ""

        return posix_path(
            os.path.normpath(commands_block.get_item_values("working_dir")[0]))
Ejemplo n.º 4
0
def check_master_file_hash(project_path: str, base_info, generator,
                           hash_list: dict) -> bool:
    project_hash_file_path = get_hash_file_path(project_path)
    project_dir = os.path.split(project_path)[0]
    total_blocks = sorted(("commands", "hashes", "files"))
    blocks_found = []

    if os.path.isfile(project_hash_file_path):
        hash_file = qpc_reader.read_file(project_hash_file_path)

        if not hash_file:
            return False

        for block in hash_file:
            if block.key == "commands":
                blocks_found.append(block.key)
                if not _check_commands(project_dir, block.items, 5):
                    return False

            elif block.key == "hashes":
                blocks_found.append(block.key)
                if not _check_file_hash(project_dir, block.items):
                    return False

            elif block.key == "files":
                blocks_found.append(block.key)
                if not base_info.project_hashes:
                    continue
                if generator.uses_folders():
                    if not _check_files(project_dir, block.items, hash_list,
                                        base_info.projects):
                        return False
                else:
                    if not _check_files(project_dir, block.items, hash_list):
                        return False

            else:
                # how would this happen
                block.warning("Unknown Key in Hash: ")

        if total_blocks == sorted(blocks_found):
            print("Valid: " + project_path + get_hash_file_ext(project_path))
            return True
        return False
    else:
        verbose("Hash File does not exist")
        return False
Ejemplo n.º 5
0
def check_hash(project_path: str, print_allowed: bool = True) -> bool:
    if project_path in CHECKED_HASHES:
        return CHECKED_HASHES[project_path]["result"]

    project_hash_file_path = get_hash_file_path(project_path)
    project_dir = os.path.split(project_path)[0]
    total_blocks = sorted(("commands", "glob_files", "hashes"))
    blocks_found = []
    CHECKED_HASHES[project_path] = {
        "result": True,
        "generators": [],
        "rebuild_all": False
    }
    result = True

    if os.path.isfile(project_hash_file_path):
        hash_file = qpc_reader.read_file(project_hash_file_path)

        if not hash_file:
            CHECKED_HASHES[project_path]["result"] = False
            CHECKED_HASHES[project_path]["rebuild_all"] = True
            return False

        for block in hash_file:
            if not result:
                CHECKED_HASHES[project_path]["result"] = False
                return False

            if block.key == "commands":
                blocks_found.append(block.key)
                result = _check_commands(project_dir, block.items, 4)
                CHECKED_HASHES[project_path]["rebuild_all"] = not result

            elif block.key == "hashes":
                blocks_found.append(block.key)
                result = _project_check_file_hash(project_dir, block.items,
                                                  project_path)

            elif block.key == "dependencies":
                pass

            elif block.key == "glob_files":
                blocks_found.append(block.key)
                result = _check_glob_files(project_dir, block.items)
                CHECKED_HASHES[project_path]["rebuild_all"] = not result

            elif print_allowed:
                # how would this happen
                block.warning("Unknown Key in Hash: ")

        if total_blocks == sorted(blocks_found):
            if print_allowed:
                print("Valid: " + project_path +
                      get_hash_file_ext(project_path))
            CHECKED_HASHES[project_path]["result"] = True
            return True
        CHECKED_HASHES[project_path]["result"] = False
        return False
    else:
        if print_allowed:
            verbose("Hash File does not exist")
        CHECKED_HASHES[project_path]["result"] = False
        CHECKED_HASHES[project_path]["rebuild_all"] = True
        return False
Ejemplo n.º 6
0
    def _parse_base_info_recurse(self,
                                 info: BaseInfoPlatform,
                                 base_file: QPCBlockBase,
                                 include_dir: str = "") -> None:
        for project_block in base_file:

            if not project_block.solve_condition(info.macros):
                continue

            elif project_block.key == "macro":
                info.add_macro(project_block)

            elif project_block.key == "configurations":
                configs = project_block.get_item_list_condition(info.macros)
                [
                    info.configurations.append(config) for config in configs
                    if config not in info.configurations
                ]

            # obsolete
            elif project_block.key == "dependency_paths":
                project_block.warning(
                    "dependency_paths is obsolete, now uses project paths directly"
                )
                continue

            elif not project_block.values:
                continue

            elif project_block.key == "project":
                self._base_project_define(project_block, info, include_dir)

            elif project_block.key == "group":
                self._base_group_define(project_block, info)

            elif project_block.key == "include":
                # "Ah shit, here we go again."
                file_path = os.path.normpath(
                    replace_macros(project_block.values[0], info.macros))
                new_include_dir = include_dir

                if len(project_block.values) >= 2:
                    new_include_dir += "/" + project_block.values[
                        1] if include_dir else project_block.values[1]
                    new_include_dir = replace_macros(new_include_dir,
                                                     info.macros)
                    current_dir = os.getcwd()
                    if os.path.isdir(new_include_dir):
                        os.chdir(new_include_dir)

                verbose("Reading: " + file_path)

                try:
                    include_file = read_file(file_path)

                    verbose("Parsing... ")

                    self._parse_base_info_recurse(info, include_file,
                                                  new_include_dir)
                except FileNotFoundError:
                    project_block.warning("File Does Not Exist: ")

                if len(project_block.values) >= 2:
                    os.chdir(current_dir)

            elif not args.hide_warnings:
                project_block.warning("Unknown Key: ")