def _project_check_file_hash(project_dir: str, hash_list: list, project_path: str) -> bool: result = True for hash_block in hash_list: if os.path.isabs(hash_block.values[0]) or not project_dir: project_file_path = posix_path( os.path.normpath(hash_block.values[0])) else: project_file_path = posix_path( os.path.normpath(project_dir + "/" + hash_block.values[0])) if hash_block.key != make_hash(project_file_path): if not CHECKED_HASHES[project_path][ "rebuild_all"] and hash_block.values[ 0] in QPC_GENERATOR_HASHES: generator_name = os.path.splitext( os.path.basename(hash_block.values[0]))[0] if generator_name in args.generators: CHECKED_HASHES[project_path]["generators"].append( generator_name) else: CHECKED_HASHES[project_path]["rebuild_all"] = True verbose("File Modified: " + hash_block.values[0]) result = False return result
def _check_file_hash(project_dir: str, hash_list: list) -> bool: for hash_block in hash_list: if os.path.isabs(hash_block.values[0]) or not project_dir: project_file_path = posix_path( os.path.normpath(hash_block.values[0])) else: project_file_path = posix_path( os.path.normpath(project_dir + "/" + hash_block.values[0])) if hash_block.key != make_hash(project_file_path): verbose("File Modified: " + hash_block.values[0]) return False return True
def _check_files(project_dir, hash_file_list, file_list, project_def_list: dict = None) -> bool: if len(hash_file_list) != len(file_list): return False for file_block in hash_file_list: hash_path = file_block.get_item_values("hash_path")[0] folder = file_block.get_item_values("folder") folder = folder[0] if folder else "" dependency_hash = file_block.get_item_values("dependency_hash") dependency_hash = dependency_hash[0] if dependency_hash else "" if os.path.isabs(hash_path) or not project_dir: hash_path = posix_path(os.path.normpath(hash_path)) else: hash_path = posix_path( os.path.normpath(project_dir + "/" + hash_path)) if hash_path not in file_list.values(): verbose("New project added: " + file_block.key) return False elif folder and project_def_list: for project_def in project_def_list: if file_block.key == project_def.path: if folder != "/".join(project_def_list[project_def]): return False break # Now check dependencies project_dep_list = get_project_dependencies(file_block.key) if not project_dep_list: if dependency_hash: # and not script_path.values[0] == "": # all dependencies were removed from it, and we think it has some still, rebuild verbose("Outdated dependency list: " + file_block.key) return False continue elif not dependency_hash and project_dep_list: # project has dependencies now, and we think it doesn't, rebuild return False project_dep_list.sort() if dependency_hash != hash_from_string(' '.join(project_dep_list)): verbose(f"Dependencies Changed: \"{file_block.key}\"") return False return True
def _check_commands(project_dir: str, command_list: list, total_commands: int) -> bool: commands_found = 0 for command_block in command_list: if command_block.key == "working_dir": commands_found += 1 directory = args.root_dir if project_dir: directory += "/" + project_dir # something just breaks here i use PosixPath in the if statement directory = posix_path(directory) hash_directory = posix_path(command_block.values[0]) if hash_directory.endswith("/"): hash_directory = hash_directory[:-1] if directory != hash_directory: return False elif command_block.key == "out_dir": pass elif command_block.key == "add": commands_found += 1 if sorted(args.add) != sorted(command_block.values): return False elif command_block.key == "remove": commands_found += 1 if sorted(args.remove) != sorted(command_block.values): return False elif command_block.key == "architectures": commands_found += 1 if sorted(ARCH_NAMES) != sorted(command_block.values): return False elif command_block.key == "macros": commands_found += 1 if sorted(args.macros) != sorted(command_block.values): return False elif command_block.key == "qpc_py_count": commands_found += 1 if len(QPC_BASE_HASHES) != int(command_block.values[0]): return False else: command_block.warning("Unknown Key in Hash: ") return commands_found == total_commands
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]))
def _check_glob_files(project_dir: str, file_list: list) -> bool: for file_block in file_list: file_hash = file_block.key file_glob = file_block.values[0] glob_list = glob.glob(project_dir + "/" + file_glob) for index, path in enumerate(glob_list): glob_list[index] = posix_path(path) glob_list.sort() if file_hash != hash_from_string(' '.join(glob_list)): verbose("Files found are different: " + file_glob) return False return True
def write_project_hash(project_path: str, project: qpc_project.ProjectContainer, generators: list) -> None: base_block = QPCBlockBase(project_path) _write_hash_commands(base_block, project.out_dir) hashes = base_block.add_item("hashes", []) [ hashes.add_item(hash_value, script_path) for script_path, hash_value in QPC_BASE_HASHES.items() ] for generator in generators: if generator.path in QPC_GENERATOR_HASHES: hashes.add_item(QPC_GENERATOR_HASHES[generator.path], generator.path) hash_list = project.get_hashes() if hash_list: [ hashes.add_item(hash_value, script_path) for script_path, hash_value in hash_list.items() ] glob_files_block = base_block.add_item("glob_files", []) for path in project.get_glob_files(): found_files = glob.glob(os.path.split(project_path)[0] + "/" + path) for index, _path in enumerate(found_files): found_files[index] = posix_path(_path) found_files.sort() glob_files_block.add_item(hash_from_string(' '.join(found_files)), path) if project.dependencies: dependencies_block = base_block.add_item("dependencies", []) [ dependencies_block.add_item(script_path, None) for script_path in project.dependencies ] with open(get_hash_file_path(project_path), mode="w", encoding="utf-8") as hash_file: hash_file.write(base_block.to_string(True, True))
def clean_path(string: str, macros: dict) -> str: return posix_path(replace_macros(string, macros))
def _add_dependency_ext(qpc_path: str) -> str: if not qpc_path.endswith(".qpc"): qpc_path = os.path.splitext(qpc_path)[0] + ".qpc" return posix_path(qpc_path)
def get_hash_file_path(project_path) -> str: return posix_path( os.path.normpath(QPC_HASH_DIR + get_hash_file_name(project_path)))