def create_path_dictionary( self, path, work_dict ): """Loop through the directories gathering data into the manifest""" for inode in os.listdir( path ): full_path = make_path( path, inode ) relative_path = self.get_relative_path(full_path) if os.path.isdir( full_path ): self.create_path_dictionary( full_path, work_dict ) elif os.path.isfile( full_path ): if inode.split('.')[-1].lower() in self.md5_extensions: handle = open( full_path, 'rb' ) data = handle.read() work_dict[relative_path] = md5_sum(data) handle.close() else: work_dict[relative_path] = '' return work_dict
def verify_file_md5_tuples(cls, file_md5_tuple_list): "Verify that a list of filepath, md5 pairs match" error_list = [] for file_tuple in file_md5_tuple_list: filepath = file_tuple[0] md5sum = file_tuple[1] lastslash = filepath.rfind( '/' )+1 base = filepath[0:lastslash] if not os.path.isdir(base): err_string = "missing directory" error_list.append((filepath, err_string)) elif not os.path.isfile(filepath): err_string = "missing file" error_list.append((filepath, err_string)) elif md5sum != '': computed = md5_sum(open(filepath, 'rb').read()) if md5sum != computed: err_string = "invalid checksum: Actual: %s Expected %s" \ % (computed, md5sum) error_list.append((filepath, err_string)) return error_list