def equal_dir_content(dir_a, dir_b): ''' Shallow file check. Solely compares if all filenames in both directories are equivalent. NOTE(vinh): The name equal_dir_content could be interpreted as 'exact' files, do we also check not just for name but for file hash as well? Or is that doing too much? ''' _validate_dir_path(dir_a) _validate_dir_path(dir_b) dir_a_files = set( os.path.relpath(f, dir_a) for f in FileUtils.GetFilesInDir(dir_a)) dir_b_files = set( os.path.relpath(f, dir_b) for f in FileUtils.GetFilesInDir(dir_b)) return dir_a_files == dir_b_files
def compute_dir_hash(selected_dir): ''' Returns a string representing the hash of the contents of the directory. Note: The resulting hash is solely based on the hash of the contents of the directory and not on any file metadata (creation date, modified date, etc..). ''' _validate_dir_path(selected_dir) res = [] for dir_file in FileUtils.GetFilesInDir(selected_dir): rel_path = os.path.relpath(dir_file, selected_dir) # Include relative file path as part of hash string since multiple # files in a directory could compute to the same hash. res.append('%s\t%s' % (rel_path, compute_file_hash(dir_file))) # Sort the computed hashes so that the directory hash is # stable and doesn't rely on the order the system returns files. return ''.join(sorted(res))
def _ComputeTasks(cls, targets, ignore_list=[]): """Computes the tasks to be evaluate given the input targets. Args: targets: list: List of input targets. ignore_list: list: List of strings to ignore. Return: dict{int, set(string)}: Dict from priority to set of tasks to execute at the priority. """ # First create a simple task list of priority string to task. # Once all the tasks have been collected, then sort them to create an actual priority order. tasks = {} ignore_list += ['timeout'] for target in targets: ignore = FileUtils.IgnorePath(target, ignore_list) if ignore: TermColor.Warning( 'Ignored target %s as anything with [%s] is ignored.' % (target, ignore)) continue recurse = False if os.path.basename(target) == '...': target = os.path.dirname(target) if not target: target = FileUtils.GetAbsPathForFile(os.getcwd()) if target.find(PipelineConfig.Instance().pipeline_base_dir( )) != 0: target = PipelineConfig.Instance().pipeline_base_dir() recurse = True abs_target = FileUtils.GetAbsPathForFile(target) if not abs_target: TermColor.Warning('[%s] is not a valid path' % (target)) continue if os.path.isfile(abs_target): cls.__AddFileToTasks(tasks, abs_target) elif os.path.isdir(abs_target): targets += FileUtils.GetFilesInDir(abs_target, recurse, ignore_list) else: TermColor.Warning('[%s] is not supported' % (abs_target)) continue return cls.__MergeTasks(tasks)